Class: Hexp::Unparser

Inherits:
Object
  • Object
show all
Includes:
Adamantium
Defined in:
lib/hexp-rails.rb,
lib/hexp/unparser.rb

Overview

Honor ActiveSupport::SafeBuffer’s “html_safe” flag

Constant Summary collapse

APOS =
?'.freeze
QUOT =
?".freeze
LT =
'<'.freeze
GT =
'>'.freeze
SPACE =
' '.freeze
EQ =
'='.freeze
AMP =
'&'.freeze
FSLASH =
'/'.freeze
E_AMP =
'&amp;'.freeze
E_APOS =
'&#x27;'.freeze
E_QUOT =
'&quot;'.freeze
E_LT =
'&lt;'.freeze
E_GT =
'&gt;'.freeze
ESCAPE_ATTR_APOS =
{AMP => E_AMP, APOS => E_APOS}
ESCAPE_ATTR_QUOT =
{AMP => E_AMP, QUOT => E_QUOT}
ESCAPE_TEXT =
{AMP => E_AMP, APOS => E_APOS, QUOT => E_QUOT, LT => E_LT, GT => E_GT}
ESCAPE_ATTR_APOS_REGEX =
Regexp.new("[#{ESCAPE_ATTR_APOS.keys.join}]")
ESCAPE_ATTR_QUOT_REGEX =
Regexp.new("[#{ESCAPE_ATTR_QUOT.keys.join}]")
ESCAPE_TEXT_REGEX =
Regexp.new("[#{ESCAPE_TEXT.keys.join}]")
DEFAULT_OPTIONS =
{
  encoding: Encoding.default_external,
  no_escape: [:script],
  void: [ :area, :base, :br, :col, :command, :embed, :hr, :img, :input,
          :keygen, :link, :meta, :param, :source, :track, :wbr ]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Unparser

Returns a new instance of Unparser.



37
38
39
# File 'lib/hexp/unparser.rb', line 37

def initialize(options)
  @options = DEFAULT_OPTIONS.merge(options)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



35
36
37
# File 'lib/hexp/unparser.rb', line 35

def options
  @options
end

Instance Method Details

#call(node) ⇒ Object



41
42
43
44
45
# File 'lib/hexp/unparser.rb', line 41

def call(node)
  buffer = String.new.force_encoding(options[:encoding])
  add_node(buffer, node)
  buffer.freeze
end

#orig_escape_textObject



26
# File 'lib/hexp-rails.rb', line 26

alias orig_escape_text escape_text