formtastic 1.0.0.rc → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -53,8 +53,8 @@ begin
53
53
 
54
54
  # Runtime dependencies: When installing Formtastic these will be checked if they are installed.
55
55
  # Will be offered to install these if they are not already installed.
56
- s.add_dependency 'activesupport', '>= 2.3.0'
57
- s.add_dependency 'actionpack', '>= 2.3.0'
56
+ s.add_dependency 'activesupport', '>= 2.3.0', '< 3.0.0'
57
+ s.add_dependency 'actionpack', '>= 2.3.0', '< 3.0.0'
58
58
  s.add_dependency 'i18n', '< 0.4'
59
59
 
60
60
  # Development dependencies. Not installed by default.
data/lib/formtastic.rb CHANGED
@@ -617,15 +617,14 @@ module Formtastic #:nodoc:
617
617
  end
618
618
 
619
619
  # Outputs a hidden field inside the wrapper, which should be hidden with CSS.
620
- # Additionals options can be given and will be sent straight to hidden input
621
- # element.
620
+ # Additionals options can be given using :input_hml. Should :input_html not be
621
+ # specified every option except for formtastic options will be sent straight
622
+ # to hidden input element.
622
623
  #
623
624
  def hidden_input(method, options)
624
625
  options ||= {}
625
- if options[:input_html].present?
626
- options[:value] = options[:input_html][:value] if options[:input_html][:value].present?
627
- end
628
- self.hidden_field(method, strip_formtastic_options(options))
626
+ html_options = options.delete(:input_html) || strip_formtastic_options(options)
627
+ self.hidden_field(method, html_options)
629
628
  end
630
629
 
631
630
  # Outputs a label and a select box containing options from the parent
@@ -888,10 +887,7 @@ module Formtastic #:nodoc:
888
887
  end
889
888
 
890
889
  template.content_tag(:fieldset,
891
- template.content_tag(:legend,
892
- template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
893
- ) <<
894
- template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
890
+ legend_tag(method, options) << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
895
891
  )
896
892
  end
897
893
  alias :boolean_radio_input :radio_input
@@ -1159,12 +1155,9 @@ module Formtastic #:nodoc:
1159
1155
  template.content_tag(:li, Formtastic::Util.html_safe(li_content), li_options)
1160
1156
  end
1161
1157
 
1162
- template.content_tag(:fieldset,
1163
- template.content_tag(:legend,
1164
- template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
1165
- ) <<
1166
- template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
1167
- )
1158
+ fieldset_content = legend_tag(method, options)
1159
+ fieldset_content << template.content_tag(:ol, Formtastic::Util.html_safe(list_item_content.join))
1160
+ template.content_tag(:fieldset, fieldset_content)
1168
1161
  end
1169
1162
 
1170
1163
  # Outputs a country select input, wrapping around a regular country_select helper.
@@ -1346,6 +1339,13 @@ module Formtastic #:nodoc:
1346
1339
  )
1347
1340
  end
1348
1341
 
1342
+ # Generates the legend for radiobuttons and checkboxes
1343
+ def legend_tag(method, options = {})
1344
+ (options[:label] == false) ? Formtastic::Util.html_safe("") : template.content_tag(:legend,
1345
+ template.label_tag(nil, localized_string(method, options[:label], :label) || humanized_attribute_name(method), :for => nil), :class => :label
1346
+ )
1347
+ end
1348
+
1349
1349
  # For methods that have a database column, take a best guess as to what the input method
1350
1350
  # should be. In most cases, it will just return the column type (eg :string), but for special
1351
1351
  # cases it will simplify (like the case of :integer, :float & :decimal to :numeric), or do
@@ -277,6 +277,20 @@ describe 'check_boxes input' do
277
277
  output_buffer.should have_tag("legend.label label", /The authors/)
278
278
  end
279
279
  end
280
+
281
+ describe "when :label option is false" do
282
+ before do
283
+ @output_buffer = ''
284
+ @new_post.stub!(:author_ids).and_return(nil)
285
+ semantic_form_for(@new_post) do |builder|
286
+ concat(builder.input(:authors, :as => :check_boxes, :label => false, :morton => true))
287
+ end
288
+ end
289
+
290
+ it "should not output the legend" do
291
+ output_buffer.should_not have_tag("legend.label")
292
+ end
293
+ end
280
294
  end
281
295
  end
282
296
 
@@ -13,6 +13,8 @@ describe 'hidden input' do
13
13
  concat(builder.input(:secret, :as => :hidden))
14
14
  concat(builder.input(:author_id, :as => :hidden, :value => 99))
15
15
  concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
16
+ concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
17
+ concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"}))
16
18
  end
17
19
  end
18
20
 
@@ -34,6 +36,14 @@ describe 'hidden input' do
34
36
  it "should pass any explicitly specified value - using :input_html options" do
35
37
  output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
36
38
  end
39
+
40
+ it "should pass any option specified using :input_html" do
41
+ output_buffer.should have_tag("form li input#new_post_reviewer[@type=\"hidden\"][@class=\"new_post_reviewer\"]")
42
+ end
43
+
44
+ it "should prefer :input_html over directly supplied options" do
45
+ output_buffer.should have_tag("form li input#post_author[@type=\"hidden\"][@value=\"formtastic_value\"]")
46
+ end
37
47
 
38
48
  it "should not render inline errors" do
39
49
  @errors = mock('errors')
@@ -207,4 +207,18 @@ describe 'radio input' do
207
207
  output_buffer.should have_tag("legend.label label", /The authors/)
208
208
  end
209
209
  end
210
+
211
+ describe "when :label option is false" do
212
+ before do
213
+ @output_buffer = ''
214
+ @new_post.stub!(:author_ids).and_return(nil)
215
+ semantic_form_for(@new_post) do |builder|
216
+ concat(builder.input(:authors, :as => :radio, :label => false))
217
+ end
218
+ end
219
+
220
+ it "should not output the legend" do
221
+ output_buffer.should_not have_tag("legend.label")
222
+ end
223
+ end
210
224
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - rc
10
- version: 1.0.0.rc
9
+ - rc2
10
+ version: 1.0.0.rc2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Justin French
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-08-01 00:00:00 +10:00
18
+ date: 2010-08-09 00:00:00 +10:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -30,6 +30,13 @@ dependencies:
30
30
  - 3
31
31
  - 0
32
32
  version: 2.3.0
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ segments:
36
+ - 3
37
+ - 0
38
+ - 0
39
+ version: 3.0.0
33
40
  type: :runtime
34
41
  version_requirements: *id001
35
42
  - !ruby/object:Gem::Dependency
@@ -44,6 +51,13 @@ dependencies:
44
51
  - 3
45
52
  - 0
46
53
  version: 2.3.0
54
+ - - <
55
+ - !ruby/object:Gem::Version
56
+ segments:
57
+ - 3
58
+ - 0
59
+ - 0
60
+ version: 3.0.0
47
61
  type: :runtime
48
62
  version_requirements: *id002
49
63
  - !ruby/object:Gem::Dependency