datagnan 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datagnan.rb +31 -0
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 907b0658f4dffc41593fd94d1cf17ffb3f99026d
4
- data.tar.gz: 3711e0c9bd3254afdd202322f8f62b64a1fffcfb
3
+ metadata.gz: 0f42662d14b652fc9a1a7893a01f899b0110bfad
4
+ data.tar.gz: 90b00872e0458397ea67b4c3bde7160dc449a08b
5
5
  SHA512:
6
- metadata.gz: 161992397a49b10deb721163654410eac37f99b949a55988aa52e7d4c4ea9c04e1579bc612234bf56710a4970cd21ea4d51a2d11d0934bec533d0fc1c3f2749c
7
- data.tar.gz: 63d0e57eb1c5a1e6284644de76f8760233b1c533dec272e61c254d0b819782a33a980908cb2e4d74afd0074806ecde3c6f0cce6a809a719fb12927cef4794480
6
+ metadata.gz: 8aaced078aecc27dad66a30074e2fad86e4a7445a6962e98b0eca6c54f6690f6e568ad7c14e964f6fe6471848377cb848e7d276d7142d009cbb72fa98980c26d
7
+ data.tar.gz: cf76b2ab34cc0d65c894e9328205fa5df747862513d898a006d15475f0048b2d24bd37a1caf5962b70e294497b8b0558f97b2948afe91ce76596927ceb3e12b8
@@ -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 = {})
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: datagnan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov