class String def json_escape ERB::Util.json_escape self end def html_escape # ERB::Util.html_escape self Rack::Utils.escape_html 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