Class: HTML5::TreeBuilders::REXML::Node

Inherits:
Base::Node
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/html5/treebuilders/rexml.rb

Direct Known Subclasses

CommentNode, Document, DocumentType, Element, TextNode

Instance Attribute Summary collapse

Attributes inherited from Base::Node

#_flags, #childNodes, #parent

Instance Method Summary collapse

Methods inherited from Base::Node

#cloneNode, #reparentChildren

Constructor Details

#initialize(name) ⇒ Node

Returns a new instance of Node.



14
15
16
17
# File 'lib/html5/treebuilders/rexml.rb', line 14

def initialize name
  super name
  @rxobj = self.class.rxclass.new name
end

Instance Attribute Details

#rxobjObject

Returns the value of attribute rxobj.



12
13
14
# File 'lib/html5/treebuilders/rexml.rb', line 12

def rxobj
  @rxobj
end

Instance Method Details

#appendChild(node) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/html5/treebuilders/rexml.rb', line 19

def appendChild node
  if node.kind_of?(TextNode) && childNodes.length > 0 && childNodes.last.kind_of?(TextNode)
    childNodes.last.rxobj.value = childNodes.last.rxobj.to_s + node.rxobj.to_s
    childNodes.last.rxobj.raw = true
  else
    childNodes.push node
    rxobj.add node.rxobj
  end
  node.parent = self
end

#hasContentObject



55
56
57
# File 'lib/html5/treebuilders/rexml.rb', line 55

def hasContent
  (childNodes.length > 0)
end

#insertBefore(node, refNode) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/html5/treebuilders/rexml.rb', line 44

def insertBefore node, refNode
  index = childNodes.index(refNode)
  if node.kind_of?(TextNode) and index > 0 && childNodes[index-1].kind_of?(TextNode)
    childNodes[index-1].rxobj.value = childNodes[index-1].rxobj.to_s + node.rxobj.to_s
    childNodes[index-1].rxobj.raw = true
  else
    childNodes.insert index, node
    refNode.rxobj.parent.insert_before(refNode.rxobj,node.rxobj)
  end
end

#insertText(data, before = nil) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/html5/treebuilders/rexml.rb', line 36

def insertText data, before=nil
  if before
    insertBefore TextNode.new(data), before
  else
    appendChild TextNode.new(data)
  end
end

#removeChild(node) ⇒ Object



30
31
32
33
34
# File 'lib/html5/treebuilders/rexml.rb', line 30

def removeChild node
   childNodes.delete node
   rxobj.delete node.rxobj
   node.parent = nil
end