twitter_bootstrap_form_for 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,6 +1,9 @@
1
1
  Twitter Bootstrap Form For Changes
2
2
  ==================================
3
3
 
4
+ ## 1.0.4 (2011-11-20) ##
5
+ - support for inline fields (closes [\#2])
6
+
4
7
  ## 1.0.3 (2011-11-11) ##
5
8
  - ruby 1.8 compatibility for hidden fields (closes [\#20])
6
9
  - produce correct labels for radio buttons (closes [\#16])
@@ -36,4 +39,5 @@ Twitter Bootstrap Form For Changes
36
39
  [\#14]: https://github.com/stouset/twitter_bootstrap_form_for/issues/14
37
40
  [\#7]: https://github.com/stouset/twitter_bootstrap_form_for/issues/7
38
41
  [\#5]: https://github.com/stouset/twitter_bootstrap_form_for/issues/5
42
+ [\#2]: https://github.com/stouset/twitter_bootstrap_form_for/issues/2
39
43
  [\#1]: https://github.com/stouset/twitter_bootstrap_form_for/issues/1
data/README.markdown CHANGED
@@ -38,6 +38,15 @@ Just Rails. But you were going to use that anyway, weren't you?
38
38
  / input fields with custom add-ons
39
39
  = user.text_field :twitter_id, 'Twitter', :class => 'medium', :add_on => :prepend do
40
40
  %span.add-on @
41
+
42
+ / select fields now have the second parameter as a label
43
+ = user.date_select :born_on, 'Born on', {}, :class => 'small'
44
+
45
+ / inline inputs are not automatically labeled
46
+ = user.inline 'Interests' do |inline|
47
+ #{inline.text_field :interest_1, :class => 'small'},
48
+ #{inline.text_field :interest_2, :class => 'small'}, and
49
+ #{inline.text_field :interest_3, :class => 'small'}
41
50
 
42
51
  / group of radio buttons
43
52
  = user.toggles 'Email Preferences' do
@@ -66,7 +75,7 @@ the functionality anticipated by Twitter Bootstrap.
66
75
 
67
76
  ## Known Bugs ##
68
77
 
69
- - inline fields are not yet supported ([issue #2])
78
+ - inline fields don't receive error markup ([issue #28])
70
79
 
71
80
  [Twitter Bootstrap]: http://twitter.github.com/bootstrap/
72
- [issue #2]: https://github.com/stouset/twitter_bootstrap_form_for/issues/2
81
+ [issue #28]: https://github.com/stouset/twitter_bootstrap_form_for/issues/28
@@ -27,16 +27,10 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
27
27
  # +legend+ text.
28
28
  #
29
29
  def inputs(legend = nil, options = {}, &block)
30
- # stash the old field_error_proc, then override it temporarily
31
- original_field_error_proc = template.field_error_proc
32
- template.field_error_proc = lambda {|html_tag, instance| html_tag }
33
-
34
30
  template.content_tag(:fieldset, options) do
35
31
  template.concat template.content_tag(:legend, legend) unless legend.nil?
36
32
  block.call
37
33
  end
38
- ensure
39
- template.field_error_proc = original_field_error_proc
40
34
  end
41
35
 
42
36
  #
@@ -45,7 +39,7 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
45
39
  # inside of here, and will not look correct unless they are.
46
40
  #
47
41
  def toggles(label = nil, &block)
48
- template.content_tag(:div, :class => "clearfix") do
42
+ template.content_tag(:div, :class => 'clearfix') do
49
43
  template.concat template.content_tag(:label, label)
50
44
  template.concat template.content_tag(:div, :class => "input") {
51
45
  template.content_tag(:ul, :class => "inputs-list") { block.call }
@@ -70,6 +64,26 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
70
64
  super value, options
71
65
  end
72
66
 
67
+ #
68
+ # Creates bootstrap wrapping before yielding a plain old rails builder
69
+ # to the supplied block.
70
+ #
71
+ def inline(label = nil, &block)
72
+ template.content_tag(:div, :class => 'clearfix') do
73
+ template.concat template.content_tag(:label, label) if label.present?
74
+ template.concat template.content_tag(:div, :class => 'input') {
75
+ template.content_tag(:div, :class => 'inline-inputs') do
76
+ self.fields_for(
77
+ self.object_name,
78
+ self.object,
79
+ self.options.merge(:builder => ActionView::Helpers::FormBuilder),
80
+ &block
81
+ )
82
+ end
83
+ }
84
+ end
85
+ end
86
+
73
87
  INPUTS.each do |input|
74
88
  define_method input do |attribute, *args, &block|
75
89
  options = args.extract_options!
@@ -155,7 +169,7 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
155
169
  # This merges any +classes+ passed in.
156
170
  #
157
171
  def _wrapper_classes(attribute, *classes)
158
- classes.tap do |klasses|
172
+ classes.compact.tap do |klasses|
159
173
  klasses.push 'error' if self.errors_on?(attribute)
160
174
  end.join(' ')
161
175
  end
@@ -9,8 +9,22 @@ module TwitterBootstrapFormFor::FormHelpers
9
9
  options[:builder] = TwitterBootstrapFormFor::FormBuilder
10
10
 
11
11
  # call the original method with our overridden options
12
- send method, record, *(args << options), &block
12
+ _override_field_error_proc do
13
+ send method, record, *(args << options), &block
14
+ end
13
15
  end
14
16
  end
15
17
  end
18
+
19
+ private
20
+
21
+ BLANK_FIELD_ERROR_PROC = lambda {|input, _| input }
22
+
23
+ def _override_field_error_proc
24
+ original_field_error_proc = self.field_error_proc
25
+ self.field_error_proc = BLANK_FIELD_ERROR_PROC
26
+ yield
27
+ ensure
28
+ self.field_error_proc = original_field_error_proc
29
+ end
16
30
  end
@@ -1,3 +1,3 @@
1
1
  module TwitterBootstrapFormFor
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_bootstrap_form_for
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-11 00:00:00.000000000 Z
12
+ date: 2011-11-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: railties
16
- requirement: &70157112743780 !ruby/object:Gem::Requirement
16
+ requirement: &70325744527840 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70157112743780
24
+ version_requirements: *70325744527840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: actionpack
27
- requirement: &70157112743200 !ruby/object:Gem::Requirement
27
+ requirement: &70325744526200 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '3'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70157112743200
35
+ version_requirements: *70325744526200
36
36
  description: A custom Rails FormBuilder that assumes the use of Twitter Bootstrap
37
37
  email:
38
38
  - stephen@touset.org