lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.5.0 vs lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.6.1
- old
+ new
@@ -167,19 +167,20 @@
distance_of_time_in_words(from_time, Time.now, include_seconds)
end
# Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino
# js_escape_html("<h1>Hey</h1>")
- def js_escape_html(html_content)
+ def escape_javascript(html_content)
return '' unless html_content
javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n' }
javascript_mapping.merge("\r" => '\n', '"' => '\\"', "'" => "\\'")
escaped_string = html_content.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { javascript_mapping[$1] }
- "\"#{escaped_string}\""
+ escaped_string
end
- alias escape_javascript js_escape_html
- alias escape_for_javascript js_escape_html
+ def js_escape_html(html_content)
+ "\"#{escape_javascript(html_content)}\""
+ end
end
end
end