Class: Gumbo::Node
- Inherits:
-
Object
- Object
- Gumbo::Node
- Defined in:
- ext/ruby_gumbo_ext.c,
lib/gumbo/node.rb
Instance Attribute Summary collapse
- #parent ⇒ Object readonly
- #parse_flags ⇒ Object readonly
- #type ⇒ Object readonly
Instance Method Summary collapse
-
#dump_tree(output = $stdout) ⇒ Object
Recursively dump an indented representation of a HTML tree to
output.
Instance Attribute Details
#parent ⇒ Object (readonly)
#parse_flags ⇒ Object (readonly)
#type ⇒ Object (readonly)
Instance Method Details
#dump_tree(output = $stdout) ⇒ Object
Recursively dump an indented representation of a HTML tree to output. Text nodes are not printed.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/gumbo/node.rb', line 20 def dump_tree(output = $stdout) process_node = lambda do |node, indent| return unless node.type == :document || node.type == :element output.write (" " * indent) if node.type == :element tag = (node.tag == :unknown) ? node.original_tag_name : node.tag.to_s attributes = node.attributes.map(&:name) output.write "<" + tag.upcase() output.write(" " + attributes.join(" ")) unless attributes.empty? output.puts ">" indent += 2 end for child in node.children process_node.call(child, indent) end end process_node.call(self, 0) end |