Sha256: 8b11a387822516e5a31816c3d41c906b766e59c60e380ede2973d1e8a94ac468

Contents?: true

Size: 827 Bytes

Versions: 12

Compression:

Stored size: 827 Bytes

Contents

class String
  def json_escape
    ERB::Util.json_escape self
  end
  
  HTML_ESCAPE_MAP = { '&' => '&amp;',  '>' => '&gt;',   '<' => '&lt;', '"' => '&quot;' }
  def html_escape
    # ERB and Rack both are replacing '/' character, and it's wrong because it destroys links (like '/default/my_item')
    # ERB::Util.html_escape self
    # Rack::Utils.escape_html self
    
    gsub(/[&"><]/){|special| HTML_ESCAPE_MAP[special]}
  end
  
  def url_escape    
    CGI.escape self
  end
  
  JS_ESCAPE_MAP = {
    '\\'    => '\\\\',
    '</'    => '<\/',
    "\r\n"  => '\n',
    "\n"    => '\n',
    "\r"    => '\n',
    '"'     => '\\"',
    "'"     => "\\'" 
  }  
  def js_escape
    gsub(/(\\|<\/|\r\n|[\n\r"'])/){JS_ESCAPE_MAP[$1]}
  end
  
  # String marks, like :format, :safe 
  def marks; @marks ||= OpenObject.new end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rad_core-0.0.25 lib/rad/_support/string.rb
rad_core-0.0.24 lib/rad/_support/string.rb
rad_core-0.0.23 lib/rad/_support/string.rb
rad_core-0.0.22 lib/rad/_support/string.rb
rad_core-0.0.21 lib/rad/_support/string.rb
rad_core-0.0.20 lib/rad/_support/string.rb
rad_core-0.0.19 lib/rad/_support/string.rb
rad_core-0.0.18 lib/rad/_support/string.rb
rad_core-0.0.17 lib/rad/_support/string.rb
rad_core-0.0.16 lib/rad/_support/string.rb
rad_core-0.0.15 lib/rad/_support/string.rb
rad_core-0.0.14 lib/rad/_support/string.rb