Module: Philiprehberger::HtmlBuilder::Escape

Defined in:
lib/philiprehberger/html_builder/escape.rb

Overview

HTML entity escaping utilities

Constant Summary collapse

ENTITIES =
{
  '&' => '&',
  '<' => '&lt;',
  '>' => '&gt;',
  '"' => '&quot;',
  "'" => '&#39;'
}.freeze
ENTITY_PATTERN =
Regexp.union(ENTITIES.keys).freeze

Class Method Summary collapse

Class Method Details

.html(value) ⇒ String

Escape HTML special characters in a string

Parameters:

  • value (String)

    the string to escape

Returns:

  • (String)

    the escaped string



21
22
23
# File 'lib/philiprehberger/html_builder/escape.rb', line 21

def self.html(value)
  value.to_s.gsub(ENTITY_PATTERN, ENTITIES)
end