twitter_bootstrap_form_for 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -1,7 +1,7 @@
1
1
  Twitter Bootstrap Form For
2
2
  ==========================
3
3
 
4
- twitter_bootstrap_form_for is a Rails FormBuilder DSL that, like Formtastic,
4
+ `twitter_bootstrap_form_for` is a Rails FormBuilder DSL that, like Formtastic,
5
5
  makes it easier to create semantically awesome, readily-stylable, and
6
6
  wonderfully accessible HTML forms in your Rails applications. It abides by
7
7
  the markup expectations of [Twitter Bootstrap], make your forms look great right
@@ -14,9 +14,7 @@ Formtastic does), it only lightly wraps the existing Rails form tag helpers.
14
14
  Dependencies
15
15
  ============
16
16
 
17
- Besides Rails, Twitter Bootstrap depends on Haml. You don't have to use it
18
- yourself, but it made the views for this gem far, far cleaner and more
19
- readable.
17
+ Just Rails. But you were going to use that anyway, weren't you?
20
18
 
21
19
  I may consider adding a dependency on `less-rails-bootstrap` in the future, to
22
20
  tie this plugin to specific releases of Twitter Bootstrap.
@@ -24,38 +22,46 @@ tie this plugin to specific releases of Twitter Bootstrap.
24
22
  Syntax
25
23
  ======
26
24
 
27
- = twitter_bootstrap_form_for @user do |user|
28
-
29
- / wraps a section in a fieldset with the provided legend text
30
- = user.inputs 'Sign up' do
25
+ ```haml
26
+ = twitter_bootstrap_form_for @user do |user|
31
27
 
32
- / generates an email field with descriptive help text and standard
33
- / HTML attributes
34
- = user.email_field :email, :placeholder => 'me@example.com' do
35
- %span.help-block No account? #{link_to('Sign up!', '#')}
28
+ / wraps a section in a fieldset with the provided legend text
29
+ = user.inputs 'Sign up' do
36
30
 
37
- / generates a password field in a similar manner
38
- = user.password_field :password do
39
- %span.help-block= link_to('Forgot your password?', '#')
40
-
41
- / a field with a custom label
42
- = user.password_field :password_confirmation, 'Confirm Password'
31
+ / generates a standard email field
32
+ = user.email_field :email, :placeholder => 'me@example.com'
33
+
34
+ / generates a password field with a descriptive aside
35
+ = user.password_field :password do
36
+ %span.help-block
37
+ Must be no larger than 6 characters<br/>
38
+ Must contain only the letters 'x' or 'p'
43
39
 
44
- / input fields with custom add-ons
45
- = user.text_field :twitter_id, 'Twitter', :class => 'medium', :add_on => :prepend do
46
- %span.add-on @
40
+ / a field with a custom label
41
+ = user.password_field :password_confirmation, 'Confirm Password'
47
42
 
48
- / lists of checkboxes / radio buttons
49
- = user.toggles 'Agreements' do
50
- = user.check_box :agree, 'I agree to the Terms and Conditions'
51
- = user.check_box :spam, 'I agree to receive all sorts of spam'
43
+ / input fields with custom add-ons
44
+ = user.text_field :twitter_id, 'Twitter', :class => 'medium', :add_on => :prepend do
45
+ %span.add-on @
46
+
47
+ / lists of checkboxes / radio buttons
48
+ = user.toggles 'Agreements' do
49
+ = user.check_box :agree, 'I agree to the abusive Terms and Conditions'
50
+ = user.check_box :spam, 'I agree to receive all sorts of spam'
51
+ = user.check_box :spammer, 'I agree to let the site spam others through my Twitter account'
52
52
 
53
- = user.actions do
54
- = user.submit 'Sign up'
55
- = button_tag 'Cancel', :type => 'reset', :class => 'btn'
53
+ / wraps buttons in a distinctive style
54
+ = user.actions do
55
+ = user.submit 'Sign up'
56
+ = button_tag 'Cancel', :type => 'reset', :class => 'btn'
57
+ ```
58
+
59
+ That code produces the following output, with no custom stylesheets.
60
+
61
+ ![](https://github.com/stouset/twitter_bootstrap_form_for/raw/master/examples/screenshot.png)
56
62
 
57
63
  That's it. All of the Rails field helpers you know and love work just like
58
64
  their normal FormBuilder counterparts, but with minor extensions to expose
59
65
  the functionality anticipated by Twitter Bootstrap.
60
66
 
61
- [Twitter Bootstrap]: http://twitter.github.com/bootstrap/
67
+ [Twitter Bootstrap]: http://twitter.github.com/bootstrap/
Binary file
@@ -27,14 +27,18 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
27
27
  # +legend+ text.
28
28
  #
29
29
  def inputs(legend = nil, &block)
30
- # TODO: don't wrap error fields in field_with_error divs
31
- # ActionView::Base.field_error_proc = ->(html_tag, instance) { html_tag }
32
-
33
- template.render(
34
- :layout => 'twitter_bootstrap_form_for/inputs',
35
- :locals => { :legend => legend },
36
- &block
37
- )
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 = ->(html_tag, instance) { html_tag }
33
+
34
+ # TODO: fix field with errors for good
35
+ template.field_error_proc = ->(html_tag, instance) { html_tag }
36
+ template.content_tag(:fieldset) do
37
+ template.concat template.content_tag(:legend, legend) unless legend.nil?
38
+ block.call
39
+ end
40
+ ensure
41
+ template.field_error_proc = original_field_error_proc
38
42
  end
39
43
 
40
44
  #
@@ -43,22 +47,19 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
43
47
  # inside of here, and will not look correct unless they are.
44
48
  #
45
49
  def toggles(label = nil, &block)
46
- template.render(
47
- :layout => 'twitter_bootstrap_form_for/toggles',
48
- :locals => { :label => label },
49
- &block
50
- )
50
+ template.content_tag(:div, :class => "clearfix") do
51
+ template.concat template.content_tag(:label, label)
52
+ template.concat template.content_tag(:div, :class => "input") {
53
+ template.content_tag(:ul, :class => "inputs-list") { block.call }
54
+ }
55
+ end
51
56
  end
52
57
 
53
58
  #
54
59
  # Wraps action buttons into their own styled container.
55
60
  #
56
61
  def actions(&block)
57
- template.render(
58
- :layout => 'twitter_bootstrap_form_for/actions',
59
- :locals => { },
60
- &block
61
- )
62
+ template.content_tag(:div, :class => 'actions', &block)
62
63
  end
63
64
 
64
65
  #
@@ -73,34 +74,35 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
73
74
 
74
75
  INPUTS.each do |input|
75
76
  define_method input do |attribute, *args, &block|
76
- options = args.extract_options!
77
+ options = args.extract_options!
78
+ label = args.first.nil? ? '' : args.shift
79
+ classes = [ 'input' ]
80
+ classes << ('input-' + options.delete(:add_on).to_s) if options[:add_on]
77
81
 
78
- template.render(
79
- :layout => 'twitter_bootstrap_form_for/input',
80
- :locals => {
81
- :form => self,
82
- :attribute => attribute,
83
- # only skip label if it's explicitly false
84
- :label => args.first.nil? ? '' : args.shift,
85
- :add_on => (options[:add_on] && 'input-' << options.delete(:add_on).to_s),
86
- :block => block
82
+ self.div_wrapper(attribute, :class => 'clearfix') do
83
+ template.concat self.label(attribute, label) if label
84
+ template.concat template.content_tag(:div, :class => classes.join(' ')) {
85
+ template.concat super(attribute, *(args << options))
86
+ template.concat template.content_tag(:span, self.errors_for(attribute), :class => 'help-inline') if self.errors_on?(attribute)
87
+ block.call if block.present?
87
88
  }
88
- ) { super attribute, *(args << options) }
89
+ end
89
90
  end
90
91
  end
91
92
 
92
93
  TOGGLES.each do |toggle|
93
94
  define_method toggle do |attribute, *args, &block|
94
95
  options = args.extract_options!
96
+ label = args.first.nil? ? '' : args.shift
97
+ target = self.object_name.to_s + '_' + attribute.to_s
95
98
 
96
- template.render(
97
- :layout => 'twitter_bootstrap_form_for/toggle',
98
- :locals => {
99
- :form => self,
100
- :attribute => attribute,
101
- :label => args.first.nil? ? '' : args.shift,
99
+ template.content_tag(:li) do
100
+ template.concat template.content_tag(:label, :for => target) {
101
+ template.concat super(attribute, *(args << options))
102
+ template.concat ' ' # give the input and span some room
103
+ template.concat template.content_tag(:span, label)
102
104
  }
103
- ) { super attribute, *(args << options) }
105
+ end
104
106
  end
105
107
  end
106
108
 
@@ -5,6 +5,5 @@ class TwitterBootstrapFormFor::Railtie < Rails::Railtie
5
5
  initializer 'twitter_bootstrap_form_for.initialize',
6
6
  :after => :after_initialize do
7
7
  ActionView::Base.send :include, TwitterBootstrapFormFor::FormHelpers
8
- ActionController::Base.append_view_path Pathname.new(__FILE__).join('../../../app/views')
9
8
  end
10
9
  end
@@ -1,3 +1,3 @@
1
1
  module TwitterBootstrapFormFor
2
- VERSION = '1.0.0.rc1'
2
+ VERSION = '1.0.0.rc2'
3
3
  end
@@ -10,15 +10,11 @@ Gem::Specification.new do |s|
10
10
  s.summary = 'Rails form builder optimized for Twitter Bootstrap'
11
11
  s.description = 'A custom Rails FormBuilder that assumes the use of Twitter Bootstrap'
12
12
 
13
- # s.required_rubygems_version = '>= 1.8.0'
14
- # s.rubyforge_project = 'twitter_bootstrap_form_for'
15
-
16
13
  s.files = `git ls-files`.split("\n")
17
14
  s.executables = `git ls-files`.split("\n").map {|f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
18
15
  s.require_path = 'lib'
19
16
 
20
17
  s.add_dependency 'rails', '~> 3'
21
- s.add_dependency 'haml', '~> 3'
22
18
  # TODO: uncomment the next line
23
19
  # s.add_dependency 'twitter-bootstrap', '~> 1.3'
24
20
  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.0.rc1
4
+ version: 1.0.0.rc2
5
5
  prerelease: 6
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-09-30 00:00:00.000000000Z
12
+ date: 2011-10-04 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70272000133280 !ruby/object:Gem::Requirement
16
+ requirement: &70107045286300 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,18 +21,7 @@ dependencies:
21
21
  version: '3'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70272000133280
25
- - !ruby/object:Gem::Dependency
26
- name: haml
27
- requirement: &70272000132780 !ruby/object:Gem::Requirement
28
- none: false
29
- requirements:
30
- - - ~>
31
- - !ruby/object:Gem::Version
32
- version: '3'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70272000132780
24
+ version_requirements: *70107045286300
36
25
  description: A custom Rails FormBuilder that assumes the use of Twitter Bootstrap
37
26
  email:
38
27
  - stephen@touset.org
@@ -44,11 +33,7 @@ files:
44
33
  - .rvmrc
45
34
  - Gemfile
46
35
  - README.markdown
47
- - app/views/twitter_bootstrap_form_for/_actions.html.haml
48
- - app/views/twitter_bootstrap_form_for/_input.html.haml
49
- - app/views/twitter_bootstrap_form_for/_inputs.html.haml
50
- - app/views/twitter_bootstrap_form_for/_toggle.html.haml
51
- - app/views/twitter_bootstrap_form_for/_toggles.html.haml
36
+ - examples/screenshot.png
52
37
  - lib/twitter_bootstrap_form_for.rb
53
38
  - lib/twitter_bootstrap_form_for/form_builder.rb
54
39
  - lib/twitter_bootstrap_form_for/form_helpers.rb
@@ -75,7 +60,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
60
  version: 1.3.1
76
61
  requirements: []
77
62
  rubyforge_project:
78
- rubygems_version: 1.8.8
63
+ rubygems_version: 1.8.10
79
64
  signing_key:
80
65
  specification_version: 3
81
66
  summary: Rails form builder optimized for Twitter Bootstrap
@@ -1,2 +0,0 @@
1
- .actions
2
- = yield
@@ -1,6 +0,0 @@
1
- = form.div_wrapper attribute, :class => 'clearfix' do
2
- = form.label attribute, label if label
3
- .input{:class => add_on}
4
- = yield
5
- %span.help-inline= form.errors_for(attribute) if form.errors_on?(attribute)
6
- = capture &block if block.present?
@@ -1,5 +0,0 @@
1
- %fieldset
2
- - if legend.present?
3
- %legend= legend
4
-
5
- = yield
@@ -1,4 +0,0 @@
1
- %li
2
- %label
3
- = yield
4
- %span= label
@@ -1,6 +0,0 @@
1
- .clearfix
2
- %label= label
3
-
4
- .input
5
- %ul.inputs-list
6
- = yield