Sha256: f6d5113421df0b863fe9cfeeb52815bd54a3f82f224d412c445d1a52785c0a03

Contents?: true

Size: 1.37 KB

Versions: 13

Compression:

Stored size: 1.37 KB

Contents

# Title:: CGI Extensions
# Authors:: Trans
# Copying:: (c)2005 Trans
# License:: Ruby Licens

require 'cgi'

# = CGI Extensions

class CGI

  # Create an hidden input field through which an object can can be marshalled.
  # This makes it very easy to pass from data betwenn requests.
  def marshal_to_cgi(name, iobj)
    data = CGI.escape(Marshal.dump(iobj))
    return %Q{<input type="hidden" name="__#{name}__" value="#{data}"/>\n}
  end

  # Create an hidden input field through which an object can can be marshalled.
  # This makes it very easy to pass from data between requests.
  def marshal_from_cgi(name)
    if self.params.has_key?("__#{name}__")
      return Marshal.load(CGI.unescape(self["__#{name}__"][0]))
    end
  end

  # RENAME!!!!

  # Are these two good enough to replace CGI.escape?

  # Return an html "safe" version of the string,
  # where every &, < and > are replaced with appropriate entities.
  def esc(str)
    str.gsub(/&/,'&amp;').gsub(/</,'&lt;').gsub(/>/,'&gt;')
  end

  # Calls #esc, and then further replaces carriage returns and quote characters with entities.
  def escformat(str)
    esc(str).gsub(/[\r\n]+/,'&#13;&#10;').gsub(%r|"|,'&quot;').gsub(%r|'|,'&#39;')
  end

  class << self
    alias :escape_html :escapeHTML
    alias :unescape_html :unescapeHTML
    alias :escape_element :escapeElement
    alias :unescape_element :unescapeElement
  end

end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
facets-2.8.4 lib/more/facets/cgi.rb
facets-2.8.3 lib/more/facets/cgi.rb
facets-2.8.2 lib/more/facets/cgi.rb
facets-2.8.1 lib/more/facets/cgi.rb
facets-2.8.0 lib/more/facets/cgi.rb
facets-2.7.0 lib/more/facets/cgi.rb
facets-2.6.0 lib/lore/facets/cgi.rb
facets-2.4.4 lib/lore/facets/cgi.rb
facets-2.5.0 lib/lore/facets/cgi.rb
facets-2.5.1 lib/lore/facets/cgi.rb
facets-2.4.5 lib/lore/facets/cgi.rb
facets-2.5.2 lib/lore/facets/cgi.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/lore/facets/cgi.rb