Class: HTML5::TreeWalkers::SimpleTree::TreeWalker

Inherits:
Base
  • Object
show all
Includes:
HTML5::TreeBuilders::SimpleTree
Defined in:
lib/feed_tools/vendor/html5/lib/html5/treewalkers/simpletree.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_ary

Methods included from TokenConstructor

#_, #comment, #doctype, #empty_tag, #end_tag, #error, #normalize_attrs, #start_tag, #text, #unknown

Constructor Details

This class inherits a constructor from HTML5::TreeWalkers::Base

Instance Method Details

#eachObject



40
41
42
43
44
# File 'lib/feed_tools/vendor/html5/lib/html5/treewalkers/simpletree.rb', line 40

def each
  for child in @tree.childNodes
    walk(child) {|node| yield node}
  end
end

#walk(node) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/feed_tools/vendor/html5/lib/html5/treewalkers/simpletree.rb', line 9

def walk(node)
  case node
  when Document, DocumentFragment
    return

  when DocumentType
    yield doctype(node.name, node.public_id, node.system_id)

  when TextNode
    text(node.value) {|token| yield token}

  when Element
    if VOID_ELEMENTS.include?(node.name)
      yield empty_tag(node.name, node.attributes, node.hasContent())
    else
      yield start_tag(node.name, node.attributes)
      for child in node.childNodes
        walk(child) {|token| yield token}
      end
      yield end_tag(node.name)
    end

  when CommentNode
    yield comment(node.value)

  else
    puts '?'
    yield unknown(node.class)
  end
end