lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.1.3 vs lib/padrino-helpers/format_helpers.rb in padrino-helpers-0.1.4
- old
+ new
@@ -53,22 +53,21 @@
when 525600..1051199 then 'about 1 year'
else "over #{(distance_in_minutes / 525600).round} years"
end
end
- # Used in xxxx.js.erb files to escape html so that it can be passed to javascript from sinatra
- # escape_javascript("<h1>Hey</h1>")
- def escape_javascript(html_content)
+ # 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)
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}\""
end
- alias js_escape escape_javascript
- alias js_escape_html escape_javascript
- alias escape_for_javascript escape_javascript
+ alias escape_javascript js_escape_html
+ alias escape_for_javascript js_escape_html
end
end
end