datagnan 1.0.2 → 1.0.3

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 +39 -35
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4abc2c60f6c8ae2c9080a8304ab25feec4aa8eb1
4
- data.tar.gz: 69b188a1ff8ef210349a10d3f96d0c1ee15091dc
3
+ metadata.gz: f425736e18d39486f8e1fc680fd8450bde7a4d1a
4
+ data.tar.gz: 46b8bdba14ff01e2dd64cedf69828fe7acb8458a
5
5
  SHA512:
6
- metadata.gz: dad826a6a3a5f9571de819e2b2f0558ca745e25f0da031099a393e633aff5111aedb41961cdf8ff91ee1c187749c757de93cdcec9d2eadf502336ac8e17389e8
7
- data.tar.gz: 05ca6420a97a40d88dba20c5c5e8d8d41e404e1577268c332aabf71da242f28479d28ddaac6359760630f44c4357b82358cd6d5c84f649354d7836408abdd6c8
6
+ metadata.gz: 96bd8819def16e59acc2223cdb23bdea2bf16cd9089238f1ddd3b9d6142fd06082e56fe526acab30f0a9f470d2bacdcdfeedf4b0c8f87e2a5dd813edb23167c1
7
+ data.tar.gz: 01eaa06ae0cd544c99123af7757e93e0ddea66dab4b7f97ed119e60e23fbf2d4ba5c5fe35c96b3fa4004852d923642cafeab19971495e81eafc960ec481a9765
@@ -75,22 +75,44 @@ class Datagnan
75
75
 
76
76
  private
77
77
 
78
+ ## find value in vars and scope
79
+ def find_value(path, vars)
80
+ ## recursive access to property
81
+ ## debug
82
+ # puts "-- Datagnan.find_value ( path = #{path} )"
83
+ # puts "-- Datagnan.find_value ( vars = #{vars} )"
84
+ var = vars
85
+ path.split('.').each do |key|
86
+ ## var exist
87
+ # puts "-- Datagnan.find_value split ( key = #{key} )"
88
+ # puts "-- Datagnan.find_value split ( @scope.respond_to?(key) = #{@scope.respond_to?(key)} )"
89
+ # puts "-- Datagnan.find_value split ( @scope.send(key) = #{@scope.send(key)} )" if @scope.respond_to?(key)
90
+ var = ( var.is_a?(Hash) ?
91
+ ( var[key].nil? ?
92
+ ( @scope.respond_to?(key) ?
93
+ @scope.send(key) :
94
+ nil
95
+ ) :
96
+ var[key]
97
+ ) :
98
+ ( var.respond_to?(key) ?
99
+ var.send(key) :
100
+ nil
101
+ )
102
+ )
103
+ end
104
+ # puts "-- Datagnan.find_value ( var = #{var} )"
105
+ var
106
+ end
107
+
78
108
  ## node content
79
109
  def data_var(vars, root)
80
110
  ## debug
81
111
  # puts "-- Datagnan.data_var ( vars = #{vars} )"
82
112
  # puts "-- Datagnan.data_var ( root.to_xml = #{root.to_xml} )"
83
113
  root.css('*[data-var]').each do |node|
84
- ## recursive access to property
85
- ## debug
86
- # puts "-- Datagnan.data_var each ( vars = #{vars} )"
87
- # puts "-- Datagnan.data_var each ( node.to_xml = #{node.to_xml} )"
88
- var = vars
89
- node.get('data-var').split('.').each do |key|
90
- ## var exist
91
- var = ( var.is_a?(Hash) ? var[key] : (var.respond_to?(key) ? var.send(key) : nil ) )
92
- end
93
- # puts "-- Datagnan.data_var each ( var = #{var} )"
114
+
115
+ var = find_value(node.get('data-var'), vars)
94
116
 
95
117
  unless var.nil?
96
118
  node.children = Oga.parse_html(var.to_s).children
@@ -118,12 +140,8 @@ private
118
140
  val = key_val.size.odd? ? key_val[0] : key_val[1]
119
141
  ## debug
120
142
  # puts "-- Datagnan.data_attrs each attr ( key = #{key}, val = #{val} )"
121
- var = vars
122
- val.split('.').each do |val_part|
123
- ## var exist
124
- var = ( var.is_a?(Hash) ? var[val_part] : (var.respond_to?(val_part) ? var.send(val_part) : nil ) )
125
- end
126
- # puts "-- Datagnan.data_attrs each ( var = #{var} )"
143
+ var = find_value(val, vars)
144
+
127
145
  unless var.nil?
128
146
  node.attributes.insert(
129
147
  node.attributes.index(node.attribute('data-attrs')),
@@ -144,15 +162,9 @@ private
144
162
  # puts "-- Datagnan.data_each ( root = #{root.to_xml} )"
145
163
  # puts "-- Datagnan.data_each ( root.css('[data-each]') = #{root.css('[data-each]').inspect} )"
146
164
  root.css('*[data-each]').each do |node|
147
- # puts "-- Datagnan.data_each each"
148
- # --------
149
- var = vars
150
- node.get('data-each').split('.').each do |key|
151
- ## var exist
152
- var = ( var.is_a?(Hash) ? var[key] : (var.respond_to?(key) ? var.send(key) : nil ) )
153
- end
154
- # puts "-- Datagnan.data_each each ( var = #{var} )"
155
- # puts "-- Datagnan.data_each each ( node = #{node.to_xml} )"
165
+
166
+ var = find_value(node.get('data-each'), vars)
167
+
156
168
  unless var.nil?
157
169
  # --------
158
170
  node.unset('data-each')
@@ -186,16 +198,8 @@ private
186
198
  # puts "Datagnan.data_when ( vars = #{vars} )"
187
199
  # puts "Datagnan.data_when ( root = #{root} )"
188
200
  root.css('*[data-when]').each do |node|
189
- ## recursive access to property
190
- ## debug
191
- # puts "-- Datagnan.data_when each ( vars = #{vars} )"
192
- # puts "-- Datagnan.data_when each ( node = #{node} )"
193
- var = vars
194
- node.get('data-when').split('.').each do |key|
195
- ## var exist
196
- var = ( var.is_a?(Hash) ? var[key] : (var.respond_to?(key) ? var.send(key) : nil ) )
197
- end
198
- # puts "-- Datagnan.data_when each ( var = #{var} )"
201
+
202
+ var = find_value(node.get('data-when'), vars)
199
203
 
200
204
  unless var.nil?
201
205
  var ? node.unset('data-when') : node.remove
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: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Popov
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-27 00:00:00.000000000 Z
12
+ date: 2015-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oga