roda-component 0.1.22 → 0.1.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2762210c34d25092f116906d5f179868ec7a015a
4
- data.tar.gz: 90bfc66cfc6a1144f5c6deeeedfa19461efb7a6a
3
+ metadata.gz: 92853f7a4482978ca64e2dbb1dc688c6b113f8ba
4
+ data.tar.gz: 15690b78f86016b7569bda1d94e2ea25e9478542
5
5
  SHA512:
6
- metadata.gz: 438a6485163a5065b03ebf8e4438f362b4b73abfeda6652db9ddfbca3cdf2c2072ab0d58adf2762edcc4cd252fc1af3816307dc673fa61425c0cac0f6234b0ed
7
- data.tar.gz: 7fc115845baaa1abfbd43458722b0160d885cb552e7153f290be24872a5c3a22ada9fc2428d9a7e9e767bac244371c41f34ab74ee9701763741554330691e58e
6
+ metadata.gz: 7d85d941ac1792fa14556b70585e423fe4662b891b2e4f0251360e85321a10f59b86f3731d5c9ea9c31a533c04011061dc0338b03390d9fec5ab722f6e0001a5
7
+ data.tar.gz: 20b3badf17176a236538f8386a37c01643f65e7ccd0e79de55a6eceefeae27d74c9f54609388bef37f783fd56bb09d429733399e1925e303c2883f5f92c0c5f4
@@ -1,5 +1,6 @@
1
1
  require 'opal'
2
2
  require 'opal-jquery'
3
+ require 'ostruct'
3
4
 
4
5
  unless RUBY_ENGINE == 'opal'
5
6
  require 'tilt'
@@ -126,7 +127,9 @@ class Roda
126
127
  Element.find('meta[name=_csrf]').attr 'content', csrf
127
128
  ###########################
128
129
 
129
- blk.call Native(response.body), response
130
+ res = JSON.from_object(`response`)
131
+
132
+ blk.call res[:body], res
130
133
  end
131
134
 
132
135
  # Element['body'].on event_id do |event, local, data|
@@ -401,6 +404,22 @@ class Roda
401
404
  value
402
405
  end
403
406
 
407
+ # Recursively process the request params and convert
408
+ # hashes to support indifferent access, leaving
409
+ # other values alone.
410
+ def indifferent_params(params)
411
+ case params
412
+ when Hash
413
+ hash = Hash.new{|h, k| h[k.to_s] if Symbol === k}
414
+ params.each{|k, v| hash[k] = indifferent_params(v)}
415
+ hash
416
+ when Array
417
+ params.map{|x| indifferent_params(x)}
418
+ else
419
+ params
420
+ end
421
+ end
422
+
404
423
  private
405
424
 
406
425
  def server?
@@ -176,7 +176,7 @@ class Roda
176
176
 
177
177
  error = error.first
178
178
 
179
- if error.is_a? Hash
179
+ if error.is_a?(Hash)
180
180
  d_options = options.dup
181
181
  d_options[:keys] = d_keys
182
182
  d_options[:override_errors] = d_errors[key].first
@@ -187,7 +187,16 @@ class Roda
187
187
  i != 0 ? "[#{field}]" : field
188
188
  end.join
189
189
 
190
- field_error_dom = DOM.new(`#{options[:tmpl].dom}[0].outerHTML` || '<span class="field-error"><span>')
190
+ if tmpl = options[:tmpl]
191
+ if client?
192
+ field_error_dom = DOM.new(`#{tmpl.dom}[0].outerHTML`)
193
+ else
194
+ field_error_dom = DOM.new(tmpl.dom.to_html)
195
+ end
196
+ else
197
+ field_error_dom = DOM.new('<span class="field-error"><span>')
198
+ end
199
+
191
200
  field_error_dom.html _error_name(key, error)
192
201
 
193
202
  field = dom.find("[name='#{name}']")
@@ -268,7 +277,7 @@ class Roda
268
277
  end
269
278
 
270
279
  def _error_name key, error
271
- case error.to_sym
280
+ case error.to_s.to_sym
272
281
  when :not_email
273
282
  'Email Isn\'t Valid.'
274
283
  when :not_present
@@ -283,6 +292,16 @@ class Roda
283
292
  def empty?
284
293
  _attributes.empty?
285
294
  end
295
+
296
+ def server? &block
297
+ RUBY_ENGINE == 'ruby'
298
+ end
299
+ alias :server :server?
300
+
301
+ def client?
302
+ RUBY_ENGINE == 'opal'
303
+ end
304
+ alias :client :client?
286
305
  end
287
306
  end
288
307
  end
@@ -1,5 +1,5 @@
1
1
  class Roda
2
2
  class Component
3
- VERSION = "0.1.22"
3
+ VERSION = "0.1.23"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roda-component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.22
4
+ version: 0.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj