Module: Erubis::XmlHelper
- Defined in:
- lib/erubis/helper.rb
Overview
helper for xml
Constant Summary collapse
- ESCAPE_TABLE =
{ '&' => '&', '<' => '<', '>' => '>', '"' => '"', "'" => ''', }
Class Method Summary collapse
- .escape_xml(value) ⇒ Object (also: h, html_escape)
- .escape_xml2(value) ⇒ Object
- .url_encode(str) ⇒ Object (also: u)
Class Method Details
.escape_xml(value) ⇒ Object Also known as: h, html_escape
25 26 27 28 |
# File 'lib/erubis/helper.rb', line 25 def escape_xml(value) value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/ #value.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] } end |
.escape_xml2(value) ⇒ Object
30 31 32 |
# File 'lib/erubis/helper.rb', line 30 def escape_xml2(value) return value.to_s.gsub(/\&/,'&').gsub(/</,'<').gsub(/>/,'>').gsub(/"/,'"') end |
.url_encode(str) ⇒ Object Also known as: u
37 38 39 40 41 |
# File 'lib/erubis/helper.rb', line 37 def url_encode(str) return str.gsub(/[^-_.a-zA-Z0-9]+/) { |s| s.unpack('C*').collect { |i| "%%%02X" % i }.join } end |