Class: Hpricot::TreeBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/hpricot/tree_builder.rb

Overview

Turns a Scanner token stream into a Hpricot::Doc tree.

XML mode is a straight push/pop of a stack. HTML mode additionally applies implicit closing driven by ElementContent (see #close_implied), matching ext/hpricot_scan/hpricot_scan.rl:316-400.

Instance Method Summary collapse

Constructor Details

#initialize(tokens, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false, void_elements: nil) ⇒ TreeBuilder

Returns a new instance of TreeBuilder.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/hpricot/tree_builder.rb', line 12

def initialize(tokens, xml: false, fixup_tags: false, xhtml_strict: false, html_void: false,
               void_elements: nil)
  @tokens = tokens
  @xml = xml
  # Which tag names are void in XML mode, or nil for none (ordinary XML).
  # :void_elements names the set outright; :html_void is shorthand for
  # HTML's own list. An explicit set wins, so a caller can narrow the list
  # without restating it as a negation.
  @void_tags = void_elements || (html_void ? VOID_TAGS : nil)
  @fixup_tags = fixup_tags
  @xhtml_strict = xhtml_strict
end

Instance Method Details

#document ⇒ Object



25
26
27
# File 'lib/hpricot/tree_builder.rb', line 25

def document
  @document ||= build
end