Class: HTML5::TreeBuilders::Hpricot::Element

Inherits:
Node show all
Defined in:
lib/html5/treebuilders/hpricot.rb

Direct Known Subclasses

DocumentFragment

Defined Under Namespace

Classes: AttributeProxy

Instance Attribute Summary

Attributes inherited from Node

#hpricot

Attributes inherited from Base::Node

#_flags, #childNodes, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#appendChild, #hasContent, #insertBefore, #insertText, #removeChild

Methods inherited from Base::Node

#appendChild, #hasContent, #insertBefore, #insertText, #removeChild, #reparentChildren

Constructor Details

#initialize(name) ⇒ Element

Returns a new instance of Element.



71
72
73
74
75
# File 'lib/html5/treebuilders/hpricot.rb', line 71

def initialize(name)
  super(name)

  @hpricot = ::Hpricot::Elem.new(::Hpricot::STag.new(name))
end

Class Method Details

.hpricot_classObject



67
68
69
# File 'lib/html5/treebuilders/hpricot.rb', line 67

def self.hpricot_class
  ::Hpricot::Elem
end

Instance Method Details

#attributesObject



113
114
115
# File 'lib/html5/treebuilders/hpricot.rb', line 113

def attributes
  AttributeProxy.new(@hpricot)
end

#attributes=(attrs) ⇒ Object



117
118
119
# File 'lib/html5/treebuilders/hpricot.rb', line 117

def attributes=(attrs)
  attrs.each { |name, value| @hpricot[name] = value }
end

#cloneNodeObject



81
82
83
84
85
86
# File 'lib/html5/treebuilders/hpricot.rb', line 81

def cloneNode
  attributes.inject(self.class.new(name)) do |node, (name, value)|
    node.hpricot[name] = value
    node
  end
end

#nameObject



77
78
79
# File 'lib/html5/treebuilders/hpricot.rb', line 77

def name
  @hpricot.stag.name
end

#printTree(indent = 0) ⇒ Object



121
122
123
124
125
126
127
128
129
# File 'lib/html5/treebuilders/hpricot.rb', line 121

def printTree(indent=0)
  tree = "\n|#{' ' * indent}<#{name}>"
  indent += 2
  attributes.each do |name, value|
    next if name == 'xmlns'
    tree += "\n|#{' ' * indent}#{name}=\"#{value}\""
  end
  childNodes.inject(tree) { |tree, child| tree + child.printTree(indent) }
end