formtastic 0.9.10 → 1.0.0.beta
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.
- data/lib/formtastic.rb +16 -5
- data/lib/formtastic/util.rb +2 -1
- data/spec/inputs/check_boxes_input_spec.rb +21 -2
- data/spec/inputs/radio_input_spec.rb +32 -1
- data/spec/inputs/string_input_spec.rb +34 -18
- metadata +11 -8
data/lib/formtastic.rb
CHANGED
@@ -536,7 +536,7 @@ module Formtastic #:nodoc:
|
|
536
536
|
#
|
537
537
|
def strip_formtastic_options(options) #:nodoc:
|
538
538
|
options.except(:value_method, :label_method, :collection, :required, :label,
|
539
|
-
:as, :hint, :input_html, :label_html, :value_as_class)
|
539
|
+
:as, :hint, :input_html, :label_html, :value_as_class, :find_options)
|
540
540
|
end
|
541
541
|
|
542
542
|
# Determins if the attribute (eg :title) should be considered required or not.
|
@@ -885,8 +885,13 @@ module Formtastic #:nodoc:
|
|
885
885
|
li_options = value_as_class ? { :class => [method.to_s.singularize, value.to_s.downcase].join('_') } : {}
|
886
886
|
template.content_tag(:li, Formtastic::Util.html_safe(li_content), li_options)
|
887
887
|
end
|
888
|
-
|
889
|
-
|
888
|
+
|
889
|
+
template.content_tag(:fieldset,
|
890
|
+
template.content_tag(:legend,
|
891
|
+
template.label_tag(nil, localized_string(method, method, :label) || humanized_attribute_name(method), :for => nil), :class => :label
|
892
|
+
) <<
|
893
|
+
template.content_tag(:ol, list_item_content)
|
894
|
+
)
|
890
895
|
end
|
891
896
|
alias :boolean_radio_input :radio_input
|
892
897
|
|
@@ -1152,7 +1157,12 @@ module Formtastic #:nodoc:
|
|
1152
1157
|
template.content_tag(:li, Formtastic::Util.html_safe(li_content), li_options)
|
1153
1158
|
end
|
1154
1159
|
|
1155
|
-
|
1160
|
+
template.content_tag(:fieldset,
|
1161
|
+
template.content_tag(:legend,
|
1162
|
+
template.label_tag(nil, localized_string(method, method, :label) || humanized_attribute_name(method), :for => nil), :class => :label
|
1163
|
+
) <<
|
1164
|
+
template.content_tag(:ol, list_item_content)
|
1165
|
+
)
|
1156
1166
|
end
|
1157
1167
|
|
1158
1168
|
# Outputs a country select input, wrapping around a regular country_select helper.
|
@@ -1531,7 +1541,8 @@ module Formtastic #:nodoc:
|
|
1531
1541
|
elsif type == :numeric || column.nil? || column.limit.nil?
|
1532
1542
|
{ :size => @@default_text_field_size }
|
1533
1543
|
else
|
1534
|
-
{ :maxlength => column.limit,
|
1544
|
+
{ :maxlength => column.limit,
|
1545
|
+
:size => @@default_text_field_size && [column.limit, @@default_text_field_size].min }
|
1535
1546
|
end
|
1536
1547
|
end
|
1537
1548
|
|
data/lib/formtastic/util.rb
CHANGED
@@ -13,7 +13,8 @@ module Formtastic
|
|
13
13
|
def html_safe(text)
|
14
14
|
return text if text.nil?
|
15
15
|
return text.html_safe if defined?(ActiveSupport::SafeBuffer)
|
16
|
-
return text.html_safe!
|
16
|
+
return text.html_safe! if text.respond_to?(:html_safe!)
|
17
|
+
text
|
17
18
|
end
|
18
19
|
|
19
20
|
def rails_safe_buffer_class
|
@@ -231,10 +231,29 @@ describe 'check_boxes input' do
|
|
231
231
|
end
|
232
232
|
|
233
233
|
end
|
234
|
+
|
235
|
+
describe "with i18n of the legend label" do
|
236
|
+
|
237
|
+
before do
|
238
|
+
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
239
|
+
|
240
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
241
|
+
semantic_form_for(@new_post) do |builder|
|
242
|
+
concat(builder.input(:authors, :as => :check_boxes))
|
243
|
+
end
|
244
|
+
end
|
234
245
|
|
246
|
+
after do
|
247
|
+
::I18n.backend.reload!
|
248
|
+
end
|
249
|
+
|
250
|
+
it "should do foo" do
|
251
|
+
output_buffer.should have_tag("legend.label label", /Translated/)
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
235
256
|
end
|
236
|
-
|
237
|
-
|
238
257
|
|
239
258
|
end
|
240
259
|
|
@@ -29,7 +29,7 @@ describe 'radio input' do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should not link the label within the legend to any input' do
|
32
|
-
output_buffer.should_not have_tag('form li fieldset legend label[@for
|
32
|
+
output_buffer.should_not have_tag('form li fieldset legend label[@for]')
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should generate an ordered list with a list item for each choice' do
|
@@ -76,6 +76,16 @@ describe 'radio input' do
|
|
76
76
|
|
77
77
|
output_buffer.should have_tag("form li fieldset ol li label input[@checked='checked']")
|
78
78
|
end
|
79
|
+
|
80
|
+
it "should not contain invalid HTML attributes" do
|
81
|
+
|
82
|
+
semantic_form_for(@new_post) do |builder|
|
83
|
+
concat(builder.input(:author, :as => :radio))
|
84
|
+
end
|
85
|
+
|
86
|
+
output_buffer.should_not have_tag("form li fieldset ol li input[@find_options]")
|
87
|
+
end
|
88
|
+
|
79
89
|
end
|
80
90
|
|
81
91
|
describe 'and no object is given' do
|
@@ -151,5 +161,26 @@ describe 'radio input' do
|
|
151
161
|
end
|
152
162
|
|
153
163
|
end
|
164
|
+
|
165
|
+
describe "with i18n of the legend label" do
|
166
|
+
|
167
|
+
before do
|
168
|
+
::I18n.backend.store_translations :en, :formtastic => { :labels => { :post => { :authors => "Translated!" }}}
|
169
|
+
|
170
|
+
@new_post.stub!(:author_ids).and_return(nil)
|
171
|
+
semantic_form_for(@new_post) do |builder|
|
172
|
+
concat(builder.input(:authors, :as => :radio))
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
after do
|
177
|
+
::I18n.backend.reload!
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should do foo" do
|
181
|
+
output_buffer.should have_tag("legend.label label", /Translated/)
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
154
185
|
|
155
186
|
end
|
@@ -8,26 +8,30 @@ describe 'string input' do
|
|
8
8
|
before do
|
9
9
|
@output_buffer = ''
|
10
10
|
mock_everything
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "when object is provided" do
|
14
|
+
before do
|
15
|
+
semantic_form_for(@new_post) do |builder|
|
16
|
+
concat(builder.input(:title, :as => :string))
|
17
|
+
end
|
14
18
|
end
|
19
|
+
|
20
|
+
it_should_have_input_wrapper_with_class(:string)
|
21
|
+
it_should_have_input_wrapper_with_id("post_title_input")
|
22
|
+
it_should_have_label_with_text(/Title/)
|
23
|
+
it_should_have_label_for("post_title")
|
24
|
+
it_should_have_input_with_id("post_title")
|
25
|
+
it_should_have_input_with_type(:text)
|
26
|
+
it_should_have_input_with_name("post[title]")
|
27
|
+
it_should_have_maxlength_matching_column_limit
|
28
|
+
it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
|
29
|
+
it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
|
30
|
+
it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
|
31
|
+
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
32
|
+
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
33
|
+
it_should_apply_error_logic_for_input_type(:string)
|
15
34
|
end
|
16
|
-
|
17
|
-
it_should_have_input_wrapper_with_class(:string)
|
18
|
-
it_should_have_input_wrapper_with_id("post_title_input")
|
19
|
-
it_should_have_label_with_text(/Title/)
|
20
|
-
it_should_have_label_for("post_title")
|
21
|
-
it_should_have_input_with_id("post_title")
|
22
|
-
it_should_have_input_with_type(:text)
|
23
|
-
it_should_have_input_with_name("post[title]")
|
24
|
-
it_should_have_maxlength_matching_column_limit
|
25
|
-
it_should_use_default_text_field_size_for_columns_longer_than_default_text_field_size(:string)
|
26
|
-
it_should_use_column_size_for_columns_shorter_than_default_text_field_size(:string)
|
27
|
-
it_should_use_default_text_field_size_when_method_has_no_database_column(:string)
|
28
|
-
it_should_apply_custom_input_attributes_when_input_html_provided(:string)
|
29
|
-
it_should_apply_custom_for_to_label_when_input_html_id_provided(:string)
|
30
|
-
it_should_apply_error_logic_for_input_type(:string)
|
31
35
|
|
32
36
|
describe "when no object is provided" do
|
33
37
|
before do
|
@@ -43,5 +47,17 @@ describe 'string input' do
|
|
43
47
|
it_should_have_input_with_name("project[title]")
|
44
48
|
end
|
45
49
|
|
50
|
+
describe "when size is nil" do
|
51
|
+
before do
|
52
|
+
semantic_form_for(:project, :url => 'http://test.host/') do |builder|
|
53
|
+
concat(builder.input(:title, :as => :string, :input_html => {:size => nil}))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should have no size attribute" do
|
58
|
+
output_buffer.should_not have_tag("input[@size]")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
46
62
|
end
|
47
63
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: true
|
5
5
|
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
6
8
|
- 0
|
7
|
-
-
|
8
|
-
|
9
|
-
version: 0.9.10
|
9
|
+
- beta
|
10
|
+
version: 1.0.0.beta
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Justin French
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-07 00:00:00 +10:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -151,11 +152,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: "0"
|
152
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
154
|
requirements:
|
154
|
-
- - "
|
155
|
+
- - ">"
|
155
156
|
- !ruby/object:Gem::Version
|
156
157
|
segments:
|
157
|
-
-
|
158
|
-
|
158
|
+
- 1
|
159
|
+
- 3
|
160
|
+
- 1
|
161
|
+
version: 1.3.1
|
159
162
|
requirements: []
|
160
163
|
|
161
164
|
rubyforge_project:
|