Class: String
- Defined in:
- lib/crystal/spec/xhtml.rb,
lib/crystal/support/string.rb
Direct Known Subclasses
Constant Summary collapse
- JS_ESCAPE_MAP =
{ '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
Instance Method Summary collapse
- #html_escape ⇒ Object
- #js_escape ⇒ Object
- #json_escape ⇒ Object
-
#marks ⇒ Object
String marks, like :format, :safe.
- #to_xhtml(css = nil) ⇒ Object
Instance Method Details
#html_escape ⇒ Object
6 7 8 9 |
# File 'lib/crystal/support/string.rb', line 6 def html_escape # ERB::Util.html_escape self Rack::Utils.escape_html self end |
#js_escape ⇒ Object
20 21 22 |
# File 'lib/crystal/support/string.rb', line 20 def js_escape gsub(/(\\|<\/|\r\n|[\n\r"'])/){JS_ESCAPE_MAP[$1]} end |
#json_escape ⇒ Object
2 3 4 |
# File 'lib/crystal/support/string.rb', line 2 def json_escape ERB::Util.json_escape self end |
#marks ⇒ Object
String marks, like :format, :safe
25 |
# File 'lib/crystal/support/string.rb', line 25 def marks; @marks ||= OpenObject.new end |
#to_xhtml(css = nil) ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/crystal/spec/xhtml.rb', line 2 def to_xhtml css = nil node = Nokogiri::HTML(self) unless css node else nodes = node.css(css) raise "Elements for '#{css}' CSS query not found!" if nodes.size < 1 raise "Found more than one elment for '#{css}' CSS query!" if nodes.size > 1 nodes.first end end |