dominate 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dominate/scope.rb +14 -5
- data/lib/dominate/version.rb +1 -1
- data/test/dominate_test.rb +7 -0
- data/test/dummy/flat.slim +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c1400088bbf6912de35de8603f32b9ced944c1e
|
4
|
+
data.tar.gz: 567983d23410a20dc5345ea7e2604634c4773b2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 534cf36a5da54a097a0a024d3768aeb016f143af2ad3f9e9b31191e853f2f24f8a2a9e73fa26ac1d6b3bc90176e00e7e009119dd05dd0be735c97483fafff527
|
7
|
+
data.tar.gz: 5072be8a698f922d1f8bf8839874acfd31f44426b8a171fb503ff11980cb33850c1fad5cac9a457c37c45dcfb8664b2d17abee6e848f7cfc61c3b1948f32c29b
|
data/lib/dominate/scope.rb
CHANGED
@@ -47,7 +47,7 @@ module Dominate
|
|
47
47
|
|
48
48
|
def apply_list doc, data_list, &block
|
49
49
|
# child placement
|
50
|
-
placement = '
|
50
|
+
placement = 'add_child'
|
51
51
|
# clean the html, removing spaces and returns
|
52
52
|
doc.inner_html = doc.inner_html.strip
|
53
53
|
# grab the first element before we remove the rest
|
@@ -55,7 +55,7 @@ module Dominate
|
|
55
55
|
# remove all the children
|
56
56
|
doc.children.each_with_index do |node, index|
|
57
57
|
if "#{node}"['data-scope']
|
58
|
-
placement = (index == 0 ? '
|
58
|
+
placement = (index == 0 ? 'add_child' : 'before')
|
59
59
|
else
|
60
60
|
node.remove
|
61
61
|
end
|
@@ -66,21 +66,30 @@ module Dominate
|
|
66
66
|
# dup the element
|
67
67
|
elem = first_elem.dup
|
68
68
|
|
69
|
-
data = data.to_deep_ostruct
|
69
|
+
data = data.to_deep_ostruct if data.is_a? Hash
|
70
70
|
|
71
71
|
# lets look for data-prop elements
|
72
72
|
elem.traverse do |x|
|
73
73
|
if x.attributes.keys.include? 'data-prop'
|
74
74
|
prop_val = x.attr('data-prop').to_s
|
75
75
|
|
76
|
-
|
76
|
+
if prop_val.length > 0
|
77
|
+
value = value_for data.instance_eval(prop_val), data, elem
|
78
|
+
else
|
79
|
+
value = value_for data, data, elem
|
80
|
+
end
|
77
81
|
x.inner_html = value
|
78
82
|
end
|
79
83
|
end
|
80
84
|
|
81
85
|
block.call elem, data if block
|
86
|
+
|
82
87
|
# add the element back to the doc
|
83
|
-
|
88
|
+
if placement == 'add_child'
|
89
|
+
doc.add_child elem
|
90
|
+
elsif placement == 'before'
|
91
|
+
doc.children.before elem
|
92
|
+
end
|
84
93
|
end
|
85
94
|
|
86
95
|
doc
|
data/lib/dominate/version.rb
CHANGED
data/test/dominate_test.rb
CHANGED
@@ -93,4 +93,11 @@ scope 'dominate' do
|
|
93
93
|
dom = Dominate::HTML.file 'index'
|
94
94
|
assert dom.html['data-scope']
|
95
95
|
end
|
96
|
+
|
97
|
+
test 'flat' do
|
98
|
+
dom = Dominate::HTML.file 'flat'
|
99
|
+
dom.scope(:flat).apply ['moo', 'cow']
|
100
|
+
assert dom.html['Moo']
|
101
|
+
assert dom.html['Cow']
|
102
|
+
end
|
96
103
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dominate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
@@ -143,6 +143,7 @@ files:
|
|
143
143
|
- lib/dominate/version.rb
|
144
144
|
- test/dominate_test.rb
|
145
145
|
- test/dummy/app.slim
|
146
|
+
- test/dummy/flat.slim
|
146
147
|
- test/dummy/footer.slim
|
147
148
|
- test/dummy/header.html
|
148
149
|
- test/dummy/index.html
|
@@ -174,6 +175,7 @@ summary: Templating Engine.
|
|
174
175
|
test_files:
|
175
176
|
- test/dominate_test.rb
|
176
177
|
- test/dummy/app.slim
|
178
|
+
- test/dummy/flat.slim
|
177
179
|
- test/dummy/footer.slim
|
178
180
|
- test/dummy/header.html
|
179
181
|
- test/dummy/index.html
|