ProMotion-XLForm 0.0.4 → 0.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16f266fe44d16f2b3dbba9d3a854e57b61096782
4
- data.tar.gz: b392bad7840ec083954aeb5938c7f508cd7a3252
3
+ metadata.gz: 02a3b9031223eeed2b269133801248640428cda1
4
+ data.tar.gz: c1122c6fb0bfc8b6b2ea35724f427fb9be5eb3d5
5
5
  SHA512:
6
- metadata.gz: 2e2cec121337790d06be52097d7cc6df47b6a9c5afdbb204d559d17b38a6a0d0cfc52ff9d751e88c5ac7d80ce5330cee3aaab0c7f8c37ca37f69c4a3a3c5b588
7
- data.tar.gz: 7c7135483141be1e1f1285568c0095301b7208e0fa7c15d8b607836f1f79a29b8972b59693d1505b8a417abbe6d5464fe3cfa298d115b78a28f2386df9a3775a
6
+ metadata.gz: 6a89a59030b0d934598ed8570e1e1ce98da593527fa8ab24c608100f99acf53c34018ee26af9ba0e652a55fc7d4dd59c8dd858c712d35b95eb6222e5b0da0faf
7
+ data.tar.gz: c2ad9973c172fc545d8a74d95b2a2a4d190dc497540812ae90946812c8c842d6025221b66a85060c662f17f713a0c4fd44a2f1793fca66a52b5f7db4446cd886
data/README.md CHANGED
@@ -248,6 +248,46 @@ You can add validators to cells.
248
248
 
249
249
  Finally, you can provide a PM::Validator with a `valid?(cell)` method.
250
250
 
251
+ ### Make a row or section invisible depending on other rows values
252
+ [You can show/hide cells](https://github.com/xmartlabs/XLForm#make-a-row-or-section-invisible-depending-on-other-rows-values) depending on a cell value with a predicate
253
+
254
+ ```ruby
255
+ {
256
+ title: 'Hide and seek',
257
+ cells: [
258
+ {
259
+ title: 'Switch me',
260
+ type: :switch,
261
+ name: :hide_and_seek,
262
+ value: true
263
+ },
264
+ {
265
+ title: 'Appear when switch is on',
266
+ name: :show_me,
267
+ type: :info,
268
+ visible: {
269
+ # the cell name wich will "trigger" the visibility
270
+ name: :hide_and_seek,
271
+
272
+ # the operand. Valid operands are :equal, :not_equal, :contains, :not_contains
273
+ is: :equal,
274
+
275
+ # the value which trigger the visibility
276
+ value: true }
277
+ },
278
+ {
279
+ title: 'Appear when switch is off',
280
+ name: :hide_me,
281
+ type: :info,
282
+
283
+ # you can also write it this way
284
+ visible: ':hide_and_seek == false'
285
+ # also valid ':some_text contains "a text"'
286
+ # ':some_text not contains "a text"'
287
+ }
288
+ ]
289
+ }
290
+ ```
251
291
 
252
292
 
253
293
  ## Todo
@@ -128,6 +128,66 @@ module ProMotion
128
128
 
129
129
  cell.disabled = !cell_data[:enabled] if cell_data[:enabled]
130
130
 
131
+ # row visible
132
+ if cell_data[:visible]
133
+ predicate = cell_data[:visible]
134
+ if predicate.is_a?(Hash)
135
+ tag = predicate[:name]
136
+ operand = case predicate[:is]
137
+ when :equal
138
+ '=='
139
+ when :not_equal
140
+ '!='
141
+ when :contains
142
+ 'contains'
143
+ when :not_contains
144
+ 'not contains'
145
+ else
146
+ predicate[:is]
147
+ end
148
+ value = predicate[:value]
149
+ else
150
+ match = /(:?[a-zA-Z_]+)\s+(==|!=|contains|not contains)\s+(.*)/.match(predicate)
151
+ if match and match.length == 4
152
+ # todo better than ignore ?
153
+ tag = match[1]
154
+ operand = match[2]
155
+ value = match[3]
156
+ if value =~ /"(.*)"/
157
+ value = value[1, value.length - 2]
158
+ end
159
+ end
160
+ end
161
+
162
+ if tag and operand
163
+ if tag.is_a?(Symbol)
164
+ tag = tag.to_s
165
+ elsif tag.start_with?(':')
166
+ tag[0] = ''
167
+ end
168
+ value = case value
169
+ when 'true', :true, true
170
+ 0
171
+ when 'false', :false, false
172
+ 1
173
+ when String
174
+ "\"#{value}\""
175
+ else
176
+ value
177
+ end
178
+
179
+ if operand == 'contains'
180
+ cell.hidden = "$#{tag} contains[c] #{value}"
181
+ elsif operand == 'not contains'
182
+ cell.hidden = "not($#{tag} contains[c] #{value})"
183
+ else
184
+ cell.hidden = "$#{tag} #{operand} #{value}"
185
+ end
186
+ else
187
+ mp "#{cell_data[:visible]} can not be parsed", force_color: :red
188
+ end
189
+ end
190
+
131
191
  # validators
132
192
  if cell_data[:validators]
133
193
  validators = cell_data[:validators]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ProMotion-XLForm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Michotte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-26 00:00:00.000000000 Z
11
+ date: 2015-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ProMotion