datagnan 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/datagnan.rb +31 -0
- 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: 0f42662d14b652fc9a1a7893a01f899b0110bfad
|
4
|
+
data.tar.gz: 90b00872e0458397ea67b4c3bde7160dc449a08b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8aaced078aecc27dad66a30074e2fad86e4a7445a6962e98b0eca6c54f6690f6e568ad7c14e964f6fe6471848377cb848e7d276d7142d009cbb72fa98980c26d
|
7
|
+
data.tar.gz: cf76b2ab34cc0d65c894e9328205fa5df747862513d898a006d15475f0048b2d24bd37a1caf5962b70e294497b8b0558f97b2948afe91ce76596927ceb3e12b8
|
data/lib/datagnan.rb
CHANGED
@@ -53,6 +53,11 @@ class Datagnan
|
|
53
53
|
## replace data-each
|
54
54
|
data_each(vars, root)
|
55
55
|
## debug
|
56
|
+
# puts "-- Datagnan.write ( vars = #{vars} )"
|
57
|
+
# puts "-- Datagnan.write ( root = #{root} )"
|
58
|
+
## replace data-when
|
59
|
+
data_when(vars, root)
|
60
|
+
## debug
|
56
61
|
# puts "Datagnan.write after each ( vars = #{vars} )"
|
57
62
|
# puts "Datagnan.write after each ( root = #{root} )"
|
58
63
|
## replace data-var
|
@@ -141,6 +146,32 @@ private
|
|
141
146
|
end
|
142
147
|
end
|
143
148
|
|
149
|
+
## display if true
|
150
|
+
def data_when(vars, root)
|
151
|
+
## debug
|
152
|
+
# puts "Datagnan.data_when ( vars = #{vars} )"
|
153
|
+
# puts "Datagnan.data_when ( root = #{root} )"
|
154
|
+
root.css('*[data-when]').each do |node|
|
155
|
+
## recursive access to property
|
156
|
+
## debug
|
157
|
+
# puts "-- Datagnan.data_when each ( vars = #{vars} )"
|
158
|
+
# puts "-- Datagnan.data_when each ( node = #{node} )"
|
159
|
+
var = vars
|
160
|
+
node['data-when'].split('.').each do |key|
|
161
|
+
## var exist
|
162
|
+
var = ( var.is_a?(Hash) ? var[key] : (var.respond_to?(key) ? var.send(key) : nil ) )
|
163
|
+
end
|
164
|
+
# puts "-- Datagnan.data_when each ( var = #{var} )"
|
165
|
+
|
166
|
+
unless var.nil?
|
167
|
+
var ? node.remove_attribute('data-when') : node.remove
|
168
|
+
end
|
169
|
+
## TODO: if var not exist remember it (maybe return to model)
|
170
|
+
end
|
171
|
+
## debug
|
172
|
+
# puts "Datagnan.data_when end ( root = #{root} )"
|
173
|
+
end
|
174
|
+
|
144
175
|
end
|
145
176
|
|
146
177
|
def datagnan(template_file, options = {}, locals = {})
|