| Class | HTML5::TreeBuilders::Hpricot::Node |
| In: |
lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb
|
| Parent: | Base::Node |
| hpricot | [RW] |
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb, line 16
16: def initialize(name)
17: super(name)
18: @hpricot = self.class.hpricot_class.new name
19: end
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb, line 21
21: def appendChild(node)
22: if node.kind_of?(TextNode) and childNodes.any? and childNodes.last.kind_of?(TextNode)
23: childNodes.last.hpricot.content = childNodes.last.hpricot.content + node.hpricot.content
24: else
25: childNodes << node
26: hpricot.children << node.hpricot
27: end
28: if (oldparent = node.hpricot.parent) != nil
29: oldparent.children.delete_at(oldparent.children.index(node.hpricot))
30: end
31: node.hpricot.parent = hpricot
32: node.parent = self
33: end
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb, line 60
60: def hasContent
61: childNodes.any?
62: end
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb, line 50
50: def insertBefore(node, refNode)
51: index = childNodes.index(refNode)
52: if node.kind_of?(TextNode) and index > 0 and childNodes[index-1].kind_of?(TextNode)
53: childNodes[index-1].hpricot.content = childNodes[index-1].hpricot.to_s + node.hpricot.to_s
54: else
55: refNode.hpricot.parent.insert_before(node.hpricot,refNode.hpricot)
56: childNodes.insert(index, node)
57: end
58: end
# File lib/feed_tools/vendor/html5/lib/html5/treebuilders/hpricot.rb, line 42
42: def insertText(data, before=nil)
43: if before
44: insertBefore(TextNode.new(data), before)
45: else
46: appendChild(TextNode.new(data))
47: end
48: end