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
24 25 26 27 |
# File 'lib/erubis/helper.rb', line 24 def escape_xml(value) value.to_s.gsub(/[&<>"]/) { |s| ESCAPE_TABLE[s] } # or /[&<>"']/ #value.to_s.gsub(/[&<>"]/) { ESCAPE_TABLE[$&] } end |
.escape_xml2(value) ⇒ Object
29 30 31 |
# File 'lib/erubis/helper.rb', line 29 def escape_xml2(value) return value.to_s.gsub(/\&/,'&').gsub(/</,'<').gsub(/>/,'>').gsub(/"/,'"') end |
.url_encode(str) ⇒ Object Also known as: u
36 37 38 39 40 |
# File 'lib/erubis/helper.rb', line 36 def url_encode(str) return str.gsub(/[^-_.a-zA-Z0-9]+/) { |s| s.unpack('C*').collect { |i| "%%%02X" % i }.join } end |