trenni-formatters 0.4.1 → 0.4.2

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: a57557f077c2dbb156b3a99f74ce6c8aa516a373
4
- data.tar.gz: f5a01135f2c7c2349a97a46c58be7fc09b9375ec
3
+ metadata.gz: dc3cefa3c833f41f4a54287eb8b4e49b38a386f2
4
+ data.tar.gz: 4c87174bfcb5aa9892beb03918bc4bcc0fabfaa2
5
5
  SHA512:
6
- metadata.gz: 08018e55d97cc99a2a751d51834988f3f3980a255855c6f4e55682dfa881d03b380c10a07f08ea510b4251ff36ce4493e57ee3d6720526c9a2fef176a87a769e
7
- data.tar.gz: e1a1ca5a88f82461bbeeba4163957e68d963871ab76434fb9bf0cad2668ab386556c6625910bde79cdac060ce461eed35c868095d383706c5b876c7e7cf0cde1
6
+ metadata.gz: 3c9a7c3eb4efc74fe0c99bbaf69e15c89caad2b17f9837981a8e4c8554e4447dd4885db509ab09dfed02179ff134c7baae45b9a3321b5415e61cebd9f890e6e6
7
+ data.tar.gz: dc8837a2db6db5a06a8b484b765549eafc304dfe191e65972693dd0e88f802151e5dbb3f113658ab7c06bd63a0bc99177f9e96db121fb0fc67f82f705f068546
@@ -49,12 +49,6 @@ module Trenni
49
49
  def for(klass, &block)
50
50
  @formatters[klass] = block
51
51
  end
52
-
53
- protected
54
-
55
- def merged_options(options = {})
56
- @options.merge(options)
57
- end
58
52
  end
59
53
  end
60
54
  end
@@ -45,18 +45,20 @@ module Trenni
45
45
  Strings::to_html(title)
46
46
  end
47
47
 
48
- # The value of the field.
49
- def value_for(options)
50
- value = options[:value]
51
-
52
- if options[:object]
53
- value ||= options[:object].send(field_for(options))
54
- end
48
+ def object_value_for(options)
49
+ options[:object].send(field_for(options)) if options[:object]
50
+ end
55
51
 
52
+ def raw_value_for(options)
53
+ value = options.fetch(:value) { object_value_for(options) }
54
+
56
55
  # Allow to specify a default value if the value given, usually from an object, is nil.
57
- value ||= options[:default]
56
+ value || options[:default]
57
+ end
58
58
 
59
- self.format(value, options)
59
+ # The value of the field.
60
+ def value_for(options)
61
+ self.format(raw_value_for(options), options)
60
62
  end
61
63
 
62
64
  def pattern_for(options)
@@ -117,12 +119,12 @@ module Trenni
117
119
  :type => options[:type] || 'checkbox',
118
120
  :id => options[:id],
119
121
  :class => options[:class],
120
- :checked => options[:object].send(name),
121
122
  :name => name_for(options),
123
+ :value => 'true',
124
+ :checked => raw_value_for(options),
122
125
  :required => options[:required],
123
126
  :disabled => options[:disabled],
124
127
  :readonly => options[:readonly],
125
- :value => 'true',
126
128
  }
127
129
  end
128
130
 
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Trenni
22
22
  module Formatters
23
- VERSION = "0.4.1"
23
+ VERSION = "0.4.2"
24
24
  end
25
25
  end
@@ -49,7 +49,7 @@ module Trenni::Formatters::FormFormatterSpec
49
49
  end
50
50
 
51
51
  describe "<input>" do
52
- let(:formatter) {FormFormatter.new(:object => double(:bar => 10))}
52
+ let(:formatter) {FormFormatter.new(:object => double(bar: 10, bob: true, dole: false))}
53
53
 
54
54
  it "should support support min, max and step" do
55
55
  attributes = formatter.input_attributes_for(:min => 10, :max => 20, :step => 2)
@@ -75,5 +75,21 @@ module Trenni::Formatters::FormFormatterSpec
75
75
  expect(attributes[:readonly]).to be true
76
76
  expect(attributes[:disabled]).to be true
77
77
  end
78
+
79
+ it "should generate checked checkbox" do
80
+ attributes = formatter.checkbox_attributes_for(:value => true)
81
+ expect(attributes[:checked]).to be true
82
+
83
+ output_tag = formatter.checkbox(:field => :bob)
84
+ expect(output_tag).to be == %Q{<dd>\n\t<input type="hidden" name="bob" value="false"/>\t<input type="checkbox" name="bob" value="true" checked/>\tBob\n</dd>}
85
+ end
86
+
87
+ it "should generate unchecked checkbox" do
88
+ attributes = formatter.checkbox_attributes_for(:value => false)
89
+ expect(attributes[:checked]).to be nil
90
+
91
+ output_tag = formatter.checkbox(:field => :dole)
92
+ expect(output_tag).to be == %Q{<dd>\n\t<input type="hidden" name="dole" value="false"/>\t<input type="checkbox" name="dole" value="true"/>\tDole\n</dd>}
93
+ end
78
94
  end
79
95
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trenni-formatters
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-16 00:00:00.000000000 Z
11
+ date: 2014-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trenni