Module: Temple::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/deprecation_collector/web/utils.rb

Constant Summary collapse

ESCAPE_HTML =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Used by escape_html

{
  "&" => "&",
  '"' => """,
  "'" => "'",
  "<" => "&lt;",
  ">" => "&gt;"
}.freeze
ESCAPE_HTML_PATTERN =
Regexp.union(*ESCAPE_HTML.keys)

Instance Method Summary collapse

Instance Method Details

#escape_html(html) ⇒ String

Returns an escaped copy of ‘html`.

Parameters:

  • html (String)

    The string to escape

Returns:

  • (String)

    The escaped string



30
31
32
# File 'lib/deprecation_collector/web/utils.rb', line 30

def escape_html(html)
  CGI.escapeHTML(html.to_s)
end

#escape_html_safe(html) ⇒ String

Returns an escaped copy of ‘html`. Strings which are declared as html_safe are not escaped.

Parameters:

  • html (String)

    The string to escape

Returns:

  • (String)

    The escaped string



20
21
22
23
# File 'lib/deprecation_collector/web/utils.rb', line 20

def escape_html_safe(html)
  s = html.to_s
  s.html_safe? || html.html_safe? ? s : escape_html(s)
end