Class: HTML5::TreeBuilders::Base::Node
- Inherits:
-
Object
- Object
- HTML5::TreeBuilders::Base::Node
- Defined in:
- lib/html5/treebuilders/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#_flags ⇒ Object
A list of miscellaneous flags that can be set on the node.
-
#childNodes ⇒ Object
a list of child nodes of the current node.
-
#parent ⇒ Object
The parent of the current node (or nil for the document node).
Instance Method Summary collapse
-
#appendChild(node) ⇒ Object
Insert node as a child of the current node.
-
#cloneNode ⇒ Object
Return a shallow copy of the current node i.e.
-
#hasContent ⇒ Object
Return true if the node has children or text, false otherwise.
-
#initialize(name) ⇒ Node
constructor
A new instance of Node.
-
#insertBefore(node, refNode) ⇒ Object
Insert node as a child of the current node, before refNode in the list of child nodes.
-
#insertText(data, insertBefore = nil) ⇒ Object
Insert data as text in the current node, positioned before the start of node insertBefore or to the end of the node’s text.
-
#removeChild(node) ⇒ Object
Remove node from the children of the current node.
-
#reparentChildren(newParent) ⇒ Object
Move all the children of the current node to newParent.
Constructor Details
#initialize(name) ⇒ Node
Returns a new instance of Node.
26 27 28 29 30 |
# File 'lib/html5/treebuilders/base.rb', line 26 def initialize(name) @parent = nil @childNodes = [] @_flags = [] end |
Instance Attribute Details
#_flags ⇒ Object
A list of miscellaneous flags that can be set on the node
24 25 26 |
# File 'lib/html5/treebuilders/base.rb', line 24 def _flags @_flags end |
#childNodes ⇒ Object
a list of child nodes of the current node. This must include all elements but not necessarily other node types
21 22 23 |
# File 'lib/html5/treebuilders/base.rb', line 21 def childNodes @childNodes end |
#parent ⇒ Object
The parent of the current node (or nil for the document node)
17 18 19 |
# File 'lib/html5/treebuilders/base.rb', line 17 def parent @parent end |
Instance Method Details
#appendChild(node) ⇒ Object
Insert node as a child of the current node
33 34 35 |
# File 'lib/html5/treebuilders/base.rb', line 33 def appendChild(node) raise NotImplementedError end |
#cloneNode ⇒ Object
Return a shallow copy of the current node i.e. a node with the same name and attributes but with no parent or child nodes
66 67 68 |
# File 'lib/html5/treebuilders/base.rb', line 66 def cloneNode raise NotImplementedError end |
#hasContent ⇒ Object
Return true if the node has children or text, false otherwise
71 72 73 |
# File 'lib/html5/treebuilders/base.rb', line 71 def hasContent raise NotImplementedError end |
#insertBefore(node, refNode) ⇒ Object
Insert node as a child of the current node, before refNode in the list of child nodes. Raises ValueError if refNode is not a child of the current node
46 47 48 |
# File 'lib/html5/treebuilders/base.rb', line 46 def insertBefore(node, refNode) raise NotImplementedError end |
#insertText(data, insertBefore = nil) ⇒ Object
Insert data as text in the current node, positioned before the start of node insertBefore or to the end of the node’s text.
39 40 41 |
# File 'lib/html5/treebuilders/base.rb', line 39 def insertText(data, insertBefore=nil) raise NotImplementedError end |
#removeChild(node) ⇒ Object
Remove node from the children of the current node
51 52 53 |
# File 'lib/html5/treebuilders/base.rb', line 51 def removeChild(node) raise NotImplementedError end |
#reparentChildren(newParent) ⇒ Object
Move all the children of the current node to newParent. This is needed so that trees that don’t store text as nodes move the text in the correct way
58 59 60 61 62 |
# File 'lib/html5/treebuilders/base.rb', line 58 def reparentChildren(newParent) #XXX - should this method be made more general? @childNodes.each { |child| newParent.appendChild(child) } @childNodes = [] end |