Sha256: 348d909dc98d9028b5259f5727224a91f4f456bffd619394afea6f8656c6d2c5

Contents?: true

Size: 937 Bytes

Versions: 3

Compression:

Stored size: 937 Bytes

Contents

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

module Innate

  # Shortcuts to some CGI methods

  module Helper
    module CGI
      # shortcut for Rack::Utils.escape
      def url_encode(*args)
        Rack::Utils.escape(*args.map{|a| a.to_s })
      end

      # shortcut for Rack::Utils.unescape
      def url_decode(*args)
        Rack::Utils.unescape(*args.map{|a| a.to_s })
      end

      # shortcut for Rack::Utils.escape_html
      def html_escape(string)
        Rack::Utils.escape_html(string)
      end

      # shortcut for CGI.unescapeHTML
      def html_unescape(string)
        ::CGI.unescapeHTML(string.to_s)
      end

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

      # one-letter versions help in case like #{h foo.inspect}
      # ERb/ERuby/Rails compatible
      alias u url_encode
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
manveru-innate-2009.02.06 lib/innate/helper/cgi.rb
manveru-innate-2009.02.21 lib/innate/helper/cgi.rb
manveru-innate-2009.02.25 lib/innate/helper/cgi.rb