bureaucrat 0.0.2 → 0.0.3

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.
@@ -353,7 +353,7 @@ module Fields
353
353
 
354
354
  def clean(value)
355
355
  case value
356
- when true, 'true', '1' then true
356
+ when true, 'true', '1', 'on' then true
357
357
  when false, 'false', '0' then false
358
358
  else nil
359
359
  end
@@ -393,13 +393,17 @@ module Fields
393
393
  end
394
394
 
395
395
  def valid_value?(value)
396
- @choices.any? do |k, v|
397
- if v.is_a?(Array) # This is an optgroup, so look inside the group for options
398
- v.any? {|k2, v2| value == k2.to_s}
396
+ @choices.each do |k, v|
397
+ if v.is_a?(Array)
398
+ # This is an optgroup, so look inside the group for options
399
+ v.each do |k2, v2|
400
+ return true if value == k2.to_s
401
+ end
399
402
  else
400
- value == k.to_s
403
+ return true if value == k.to_s
401
404
  end
402
405
  end
406
+ false
403
407
  end
404
408
  end
405
409
 
@@ -116,8 +116,8 @@ module Bureaucrat; module Forms
116
116
 
117
117
  def initialize(data=nil, options={})
118
118
  @is_bound = !data.nil?
119
- @data = data ? data.dup : {}
120
- @data.each {|k, v| @data[k.to_sym] ||= v}
119
+ @data = {}
120
+ data.each {|k, v| @data[k.to_sym] = @data[k] = v} if data
121
121
  @files = options.fetch(:files, {})
122
122
  @auto_id = options.fetch(:auto_id, 'id_%s')
123
123
  @prefix = options[:prefix]
@@ -133,7 +133,7 @@ module Widgets
133
133
  end
134
134
 
135
135
  def value_from_datahash(data, files, name)
136
- return data[name]
136
+ data[name]
137
137
  end
138
138
 
139
139
  def self.id_for_label(id_)
@@ -250,17 +250,17 @@ module Widgets
250
250
  end
251
251
 
252
252
  class Textarea < Widget
253
- def initialize(attrs=nil)
254
- # The 'rows' and 'cols' attributes are required for HTML correctness.
255
- @attrs = {:cols => '40', :rows => '10'}
256
- @attrs.merge!(attrs) if attrs
257
- end
253
+ def initialize(attrs=nil)
254
+ # The 'rows' and 'cols' attributes are required for HTML correctness.
255
+ @attrs = {:cols => '40', :rows => '10'}
256
+ @attrs.merge!(attrs) if attrs
257
+ end
258
258
 
259
- def render(name, value, attrs=nil)
260
- value ||= ''
261
- final_attrs = build_attrs(attrs, :name => name)
262
- mark_safe("<textarea#{flatatt(final_attrs)}>#{conditional_escape(value.to_s)}</textarea>")
263
- end
259
+ def render(name, value, attrs=nil)
260
+ value ||= ''
261
+ final_attrs = build_attrs(attrs, :name => name)
262
+ mark_safe("<textarea#{flatatt(final_attrs)}>#{conditional_escape(value.to_s)}</textarea>")
263
+ end
264
264
  end
265
265
 
266
266
  # DateInput
@@ -275,7 +275,7 @@ module Widgets
275
275
 
276
276
  def render(name, value, attrs=nil)
277
277
  final_attrs = build_attrs(attrs, :type => 'checkbox', :name => name.to_s)
278
- result = self.check_test(value) rescue false
278
+ result = @check_test.call(value) rescue false
279
279
  final_attrs[:checked] = 'checked' if result
280
280
  final_attrs[:value] = value.to_s unless
281
281
  ['', true, false, nil].include?(value)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bureaucrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Deferrari