Class: CGI
Instance Method Summary collapse
-
#esc(str) ⇒ Object
Return an html “safe” version of the string, where every &, < and > are replaced with appropriate entities.
-
#escformat(str) ⇒ Object
Calls #esc, and then further replaces carriage returns and quote characters with entities.
-
#marshal_from_cgi(name) ⇒ Object
Create an hidden input field through which an object can can be marshalled.
-
#marshal_to_cgi(name, iobj) ⇒ Object
Create an hidden input field through which an object can can be marshalled.
Instance Method Details
#esc(str) ⇒ Object
Return an html “safe” version of the string, where every &, < and > are replaced with appropriate entities.
26 27 28 |
# File 'lib/standard/facets/cgi.rb', line 26 def esc(str) str.gsub(/&/,'&').gsub(/</,'<').gsub(/>/,'>') end |
#escformat(str) ⇒ Object
Calls #esc, and then further replaces carriage returns and quote characters with entities.
31 32 33 |
# File 'lib/standard/facets/cgi.rb', line 31 def escformat(str) esc(str).gsub(/[\r\n]+/,' ').gsub(%r|"|,'"').gsub(%r|'|,''') end |
#marshal_from_cgi(name) ⇒ Object
Create an hidden input field through which an object can can be marshalled. This makes it very easy to pass from data between requests.
14 15 16 17 18 |
# File 'lib/standard/facets/cgi.rb', line 14 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) ⇒ Object
Create an hidden input field through which an object can can be marshalled. This makes it very easy to pass from data betwenn requests.
7 8 9 10 |
# File 'lib/standard/facets/cgi.rb', line 7 def marshal_to_cgi(name, iobj) data = CGI.escape(Marshal.dump(iobj)) return %Q{<input type="hidden" name="__#{name}__" value="#{data}"/>\n} end |