re_duxml 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/re_duxml.rb +5 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4d2ccb9fa84a9e969220ff9ab2cbe9a945cb9f07
|
4
|
+
data.tar.gz: 9f9c52ad59e65c6d888e18c35cdbdf900c962aa5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61dfd7e3bc30423fbc216947232d60d7da2247a74d18c26f984450d00c92e627c79fc250fba7e3b70695f70e59545c37521c575e7015e12eef62407f01a342df
|
7
|
+
data.tar.gz: 6e6c50737da85d318f516f2f10d6daa905b0ddae7ddbb60ea1e11d312a9f2b95b49920e3fc80f70cbf760424b6224b8985652994d56e83ad5eed123ca4381711
|
data/lib/re_duxml.rb
CHANGED
@@ -11,6 +11,7 @@ module ReDuxml
|
|
11
11
|
# @param doc_or_node [Doc, String] XML to load; can be Doc, String path or String XML; also XML Element when recursing
|
12
12
|
# @return [Doc] instantiated XML with parameters resolved with given values
|
13
13
|
def resolve(doc_or_node, parent_params={})
|
14
|
+
@e ||= Evaluator.new
|
14
15
|
if doc_or_node.is_a?(Element)
|
15
16
|
resolved_node = doc_or_node.stub
|
16
17
|
resolved_node.attributes.each do |attr, val|
|
@@ -18,11 +19,11 @@ module ReDuxml
|
|
18
19
|
end
|
19
20
|
this_params = get_params(doc_or_node, parent_params)
|
20
21
|
new_children = doc_or_node.nodes.collect do |child|
|
21
|
-
if child.respond_to?(:nodes)
|
22
|
+
if child.respond_to?(:nodes) # if this node is an XML element...
|
22
23
|
new_child = child.clone
|
23
24
|
new_child[:if] = resolve_str(new_child[:if], this_params) if new_child[:if]
|
24
|
-
if new_child.if?
|
25
|
-
new_child[:if] = nil
|
25
|
+
if new_child.if? # if this node should exist
|
26
|
+
new_child[:if] = nil if new_child[:if] == 'true'
|
26
27
|
child_params = get_params(new_child, this_params)
|
27
28
|
new_instances = new_child.activate
|
28
29
|
i = -1
|
@@ -31,13 +32,12 @@ module ReDuxml
|
|
31
32
|
resolve(inst, child_params.merge({'iterator' => i.to_s}))
|
32
33
|
end
|
33
34
|
end
|
34
|
-
else
|
35
|
+
else # this is a text node
|
35
36
|
resolve_str(child, this_params)
|
36
37
|
end
|
37
38
|
end.flatten.compact
|
38
39
|
resolved_node << new_children
|
39
40
|
else
|
40
|
-
@e ||= Evaluator.new
|
41
41
|
@src_doc = get_doc doc_or_node
|
42
42
|
@doc = Doc.new << resolve(src_doc.root, parent_params)
|
43
43
|
end
|