2007-07-05 00:36:59 +02:00
|
|
|
require 'html5/treewalkers/base'
|
2007-06-05 23:34:49 +02:00
|
|
|
require 'rexml/document'
|
|
|
|
|
2007-07-05 00:36:59 +02:00
|
|
|
module HTML5
|
2007-06-05 23:34:49 +02:00
|
|
|
module TreeWalkers
|
|
|
|
module REXML
|
2007-07-05 00:36:59 +02:00
|
|
|
class TreeWalker < HTML5::TreeWalkers::NonRecursiveTreeWalker
|
2007-06-05 23:34:49 +02:00
|
|
|
|
|
|
|
def node_details(node)
|
|
|
|
case node
|
|
|
|
when ::REXML::Document
|
|
|
|
[:DOCUMENT]
|
|
|
|
when ::REXML::Element
|
|
|
|
if !node.name
|
|
|
|
[:DOCUMENT_FRAGMENT]
|
|
|
|
else
|
|
|
|
[:ELEMENT, node.name,
|
|
|
|
node.attributes.map {|name,value| [name,value]},
|
|
|
|
node.has_elements? || node.has_text?]
|
|
|
|
end
|
|
|
|
when ::REXML::Text
|
|
|
|
[:TEXT, node.value]
|
|
|
|
when ::REXML::Comment
|
|
|
|
[:COMMENT, node.string]
|
|
|
|
when ::REXML::DocType
|
2007-08-30 19:19:10 +02:00
|
|
|
[:DOCTYPE, node.name, node.public, node.system]
|
2007-06-05 23:34:49 +02:00
|
|
|
when ::REXML::XMLDecl
|
|
|
|
[nil]
|
|
|
|
else
|
|
|
|
[:UNKNOWN, node.class.inspect]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def first_child(node)
|
|
|
|
node.children.first
|
|
|
|
end
|
|
|
|
|
|
|
|
def next_sibling(node)
|
|
|
|
node.next_sibling
|
|
|
|
end
|
|
|
|
|
|
|
|
def parent(node)
|
|
|
|
node.parent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|