class Gumbo::Node
Attributes
parent[R]
parse_flags[R]
type[R]
Public Instance Methods
dump_tree(output = $stdout)
click to toggle source
Recursively dump an indented representation of a HTML tree to output
. Text nodes are not printed.
# 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