Sha256: 8a139c45d553e32792f9750c8f9be8bbb82f349a8fc8859617182b1ec989962f

Contents?: true

Size: 1.27 KB

Versions: 29

Compression:

Stored size: 1.27 KB

Contents

autoload(:CGI, 'cgi') # in case you want to use html_unescape

module Innate

  # Shortcuts to some CGI methods

  module Helper
    module CGI
      module_function

      # Shortcut for Rack::Utils.escape
      #
      # @param [#to_s] input
      # @return [String] URI-encoded representation of +input+
      def url_encode(input)
        Rack::Utils.escape(input.to_s)
      end
      alias u url_encode

      # Shortcut for Rack::Utils.unescape
      #
      # @param [#to_s] input
      # @return [String] URI-decoded representation of +input+
      def url_decode(input)
        Rack::Utils.unescape(input.to_s)
      end

      # Shortcut for Rack::Utils.escape_html
      #
      # @param [#to_s] input
      # @return [String]
      def html_escape(input)
        Rack::Utils.escape_html(input.to_s)
      end

      # Shortcut for CGI.unescapeHTML
      #
      # @param [#to_s] input
      # @return [String]
      def html_unescape(input)
        ::CGI.unescapeHTML(input.to_s)
      end

      # safely escape all HTML and code
      def html_and_code_escape(input)
        Rack::Utils.escape_html(input.to_s).gsub(/#([{@$]@?)/, '#\1')
      end
      alias h html_and_code_escape

      # aliases are ignored by module_function...
      module_function :u, :h
    end
  end
end

Version data entries

29 entries across 29 versions & 3 rubygems

Version Path
innate-2023.01.06 lib/innate/helper/cgi.rb
innate-2015.10.28 lib/innate/helper/cgi.rb
manveru-innate-2009.04 lib/innate/helper/cgi.rb
manveru-innate-2009.05 lib/innate/helper/cgi.rb
manveru-innate-2009.06.12 lib/innate/helper/cgi.rb
manveru-innate-2009.06 lib/innate/helper/cgi.rb
manveru-innate-2009.07 lib/innate/helper/cgi.rb
rjspotter-innate-2009.06.29 lib/innate/helper/cgi.rb
rjspotter-innate-2009.06.30 lib/innate/helper/cgi.rb
rjspotter-innate-2009.06.31 lib/innate/helper/cgi.rb
innate-2013.02.21 lib/innate/helper/cgi.rb
innate-2013.02 lib/innate/helper/cgi.rb
innate-2012.12 lib/innate/helper/cgi.rb
innate-2012.03 lib/innate/helper/cgi.rb
innate-2011.12 lib/innate/helper/cgi.rb
innate-2011.10 lib/innate/helper/cgi.rb
innate-2011.04 lib/innate/helper/cgi.rb
innate-2011.01 lib/innate/helper/cgi.rb
innate-2010.07 lib/innate/helper/cgi.rb
innate-2010.06.18 lib/innate/helper/cgi.rb