Class: CGI

Class | CGI
In: | lib/more/facets/cgi.rb
Parent: | Object

# CGI Extensions

### Methods

esc escformat marshal_from_cgi marshal_to_cgi

### External Aliases

escapeHTML | -> | escape_html
unescapeHTML | -> | unescape_html
escapeElement | -> | escape_element
unescapeElement | -> | unescape_element

### Public Instance methods

esc(str)

Return an html "safe" version of the string, where every &, < and > are replaced with appropriate entities.

[Source]

    # File lib/more/facets/cgi.rb, line 33
      def esc(str)
        str.gsub(/&/,'&amp;').gsub(/</,'&lt;').gsub(/>/,'&gt;')
      end

escformat(str)

Calls esc, and then further replaces carriage returns and quote characters with entities.

[Source]

    # File lib/more/facets/cgi.rb, line 38
      def escformat(str)
        esc(str).gsub(/[\r\n]+/,'&#13;&#10;').gsub(%r|"|,'&quot;').gsub(%r|'|,'&#39;')
      end

marshal_from_cgi(name)

Create an hidden input field through which an object can can be marshalled. This makes it very easy to pass from data between requests.

[Source]

    # File lib/more/facets/cgi.rb, line 21
      def marshal_from_cgi(name)
        if self.params.has_key?("__#{name}__")
          return Marshal.load(CGI.unescape(self["__#{name}__"][0]))
        end
      end

marshal_to_cgi(name, iobj)

Create an hidden input field through which an object can can be marshalled. This makes it very easy to pass from data betwenn requests.

[Source]

    # File lib/more/facets/cgi.rb, line 14
      def marshal_to_cgi(name, iobj)
        data = CGI.escape(Marshal.dump(iobj))
        return %Q{<input type="hidden" name="__#{name}__" value="#{data}"/>\n}
      end

[Validate]