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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc3cefa3c833f41f4a54287eb8b4e49b38a386f2
|
4
|
+
data.tar.gz: 4c87174bfcb5aa9892beb03918bc4bcc0fabfaa2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c9a7c3eb4efc74fe0c99bbaf69e15c89caad2b17f9837981a8e4c8554e4447dd4885db509ab09dfed02179ff134c7baae45b9a3321b5415e61cebd9f890e6e6
|
7
|
+
data.tar.gz: dc8837a2db6db5a06a8b484b765549eafc304dfe191e65972693dd0e88f802151e5dbb3f113658ab7c06bd63a0bc99177f9e96db121fb0fc67f82f705f068546
|
@@ -45,18 +45,20 @@ module Trenni
|
|
45
45
|
Strings::to_html(title)
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
56
|
+
value || options[:default]
|
57
|
+
end
|
58
58
|
|
59
|
-
|
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
|
|
@@ -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(:
|
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.
|
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-
|
11
|
+
date: 2014-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trenni
|