Class: HTML5::TreeWalkers::NonRecursiveTreeWalker
- Inherits:
-
Base
- Object
- Base
- HTML5::TreeWalkers::NonRecursiveTreeWalker
show all
- Defined in:
- lib/html5/treewalkers/base.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #to_ary
#_, #comment, #doctype, #empty_tag, #end_tag, #error, #normalize_attrs, #start_tag, #text, #unknown
Instance Method Details
#each ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
# File 'lib/html5/treewalkers/base.rb', line 98
def each
current_node = @tree
while current_node != nil
details = node_details(current_node)
has_children = false
case details.shift
when :DOCTYPE
yield doctype(*details)
when :TEXT
text(*details) {|token| yield token}
when :ELEMENT
name, attributes, has_children = details
if VOID_ELEMENTS.include?(name)
yield empty_tag(name, attributes.to_a, has_children)
has_children = false
else
yield start_tag(name, attributes.to_a)
end
when :COMMENT
yield (details[0])
when :DOCUMENT, :DOCUMENT_FRAGMENT
has_children = true
when nil
else
yield unknown(details[0])
end
first_child = has_children ? first_child(current_node) : nil
if first_child != nil
current_node = first_child
else
while current_node != nil
details = node_details(current_node)
if details.shift == :ELEMENT
name, attributes, has_children = details
yield end_tag(name) if !VOID_ELEMENTS.include?(name)
end
if @tree == current_node
current_node = nil
else
next_sibling = next_sibling(current_node)
if next_sibling != nil
current_node = next_sibling
break
end
current_node = parent(current_node)
end
end
end
end
end
|
#first_child(node) ⇒ Object
86
87
88
|
# File 'lib/html5/treewalkers/base.rb', line 86
def first_child(node)
raise NotImplementedError
end
|
#next_sibling(node) ⇒ Object
90
91
92
|
# File 'lib/html5/treewalkers/base.rb', line 90
def next_sibling(node)
raise NotImplementedError
end
|
#node_details(node) ⇒ Object
82
83
84
|
# File 'lib/html5/treewalkers/base.rb', line 82
def node_details(node)
raise NotImplementedError
end
|
#parent(node) ⇒ Object
94
95
96
|
# File 'lib/html5/treewalkers/base.rb', line 94
def parent(node)
raise NotImplementedError
end
|