Class: Volt::DomSection
Constant Summary
CommentSearchers::NO_XPATH
Instance Method Summary
collapse
#build_from_html, #find_by_comment, #find_by_comment_without_xml
Methods inherited from BaseSection
#set_content_to_template
Constructor Details
#initialize(binding_name) ⇒ DomSection
Returns a new instance of DomSection.
8
9
10
11
|
# File 'lib/volt/page/targets/dom_section.rb', line 8
def initialize(binding_name)
@start_node = ("$#{binding_name}")
@end_node = ("$/#{binding_name}")
end
|
Instance Method Details
#container_node ⇒ Object
Returns the nearest DOM node that contains all of the section.
73
74
75
76
|
# File 'lib/volt/page/targets/dom_section.rb', line 73
def container_node
range = self.range
`range.commonAncestorContainer`
end
|
#html=(value) ⇒ Object
20
21
22
23
24
|
# File 'lib/volt/page/targets/dom_section.rb', line 20
def html=(value)
new_nodes = build_from_html(value)
self.nodes = `new_nodes.childNodes`
end
|
#insert_anchor_before(binding_name, insert_after_binding) ⇒ Object
48
49
50
51
52
53
|
# File 'lib/volt/page/targets/dom_section.rb', line 48
def insert_anchor_before(binding_name, insert_after_binding)
node = ("$#{insert_after_binding}")
binding_str = "<!-- $#{binding_name} --><!-- $/#{binding_name} -->"
`$(#{node}).before(#{binding_str})`
end
|
#insert_anchor_before_end(binding_name) ⇒ Object
43
44
45
46
|
# File 'lib/volt/page/targets/dom_section.rb', line 43
def insert_anchor_before_end(binding_name)
binding_str = "<!-- $#{binding_name} --><!-- $/#{binding_name} -->"
`$(#{@end_node}).before(#{binding_str})`
end
|
111
112
113
|
# File 'lib/volt/page/targets/dom_section.rb', line 111
def inspect
"<#{self.class}>"
end
|
#nodes=(nodes) ⇒ Object
Takes in an array of dom nodes and replaces the current content with the new nodes
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/volt/page/targets/dom_section.rb', line 57
def nodes=(nodes)
range = self.range
`
range.deleteContents();
for (var i=nodes.length-1; i >= 0; i--) {
var node = nodes[i];
node.parentNode.removeChild(node);
range.insertNode(node);
}
`
end
|
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/volt/page/targets/dom_section.rb', line 96
def range
return @range if @range
range = nil
`
range = document.createRange();
range.setStartAfter(this.start_node);
range.setEndBefore(this.end_node);
`
@range = range
range
end
|
26
27
28
29
30
31
32
|
# File 'lib/volt/page/targets/dom_section.rb', line 26
def remove
range = self.range
`
range.deleteContents();
`
end
|
#remove_anchors ⇒ Object
34
35
36
37
38
39
40
41
|
# File 'lib/volt/page/targets/dom_section.rb', line 34
def remove_anchors
`
this.start_node.parentNode.removeChild(this.start_node);
this.end_node.parentNode.removeChild(this.end_node);
`
@start_node = nil
@end_node = nil
end
|
#set_template(dom_template) ⇒ Object
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/volt/page/targets/dom_section.rb', line 78
def set_template(dom_template)
dom_nodes, bindings = dom_template.make_new
children = nil
`
children = dom_nodes.childNodes;
`
self.nodes = children
`
dom_nodes = null;
`
bindings
end
|
#text=(value) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/volt/page/targets/dom_section.rb', line 13
def text=(value)
`
this.$range().deleteContents();
this.$range().insertNode(document.createTextNode(#{value}));
`
end
|