Class: HTMLTree::Document

Inherits:
Object show all
Includes:
TreeElement
Defined in:
lib/web/htmltools/element.rb,
lib/web/htmltools/xpath.rb

Overview

This is a Element that represents the whole document (and makes a scope for the DTD declaration)

Instance Method Summary collapse

Methods included from TreeElement

#add_child, #can_have_children?, #children, #content, #dump, #get_elements, #has_children?, #parent, #parent=, #remove_child, #rexml_match, #root

Constructor Details

#initializeDocument

Returns a new instance of Document.



115
116
117
# File 'lib/web/htmltools/element.rb', line 115

def initialize
  initialize_tree_element(nil, [])
end

Instance Method Details

#as_rexml_document(context = {}) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/web/htmltools/xpath.rb', line 62

def as_rexml_document(context = {})
  node = REXML::Document.new(nil, context)
  # add DocType
  # add <HTML> node
  node.add( html_node.as_rexml_document(node, context) )
  node
end

#each(&block) ⇒ Object



123
124
125
# File 'lib/web/htmltools/element.rb', line 123

def each(&block)
  children.each { |ch| ch.each(&block) }
end

#html_nodeObject

Return my child <html> node, if any.



136
137
138
# File 'lib/web/htmltools/element.rb', line 136

def html_node
  children.detect { |ea| ea.tag == 'html' }
end

#tagObject



131
132
133
# File 'lib/web/htmltools/element.rb', line 131

def tag
  ''
end

#to_sObject



119
120
121
# File 'lib/web/htmltools/element.rb', line 119

def to_s
  ''
end

#write(io) ⇒ Object



127
128
129
# File 'lib/web/htmltools/element.rb', line 127

def write(io)
  children.each { |t| t.write(io) }
end