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 +35 -29
- data/examples/screenshot.png +0 -0
- data/lib/twitter_bootstrap_form_for/form_builder.rb +38 -36
- data/lib/twitter_bootstrap_form_for/railtie.rb +0 -1
- data/lib/twitter_bootstrap_form_for/version.rb +1 -1
- data/twitter_bootstrap_form_for.gemspec +0 -4
- metadata +6 -21
- data/app/views/twitter_bootstrap_form_for/_actions.html.haml +0 -2
- data/app/views/twitter_bootstrap_form_for/_input.html.haml +0 -6
- data/app/views/twitter_bootstrap_form_for/_inputs.html.haml +0 -5
- data/app/views/twitter_bootstrap_form_for/_toggle.html.haml +0 -4
- data/app/views/twitter_bootstrap_form_for/_toggles.html.haml +0 -6
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
|
-
|
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
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
45
|
-
|
46
|
-
%span.add-on @
|
40
|
+
/ a field with a custom label
|
41
|
+
= user.password_field :password_confirmation, 'Confirm Password'
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
54
|
-
|
55
|
-
|
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
|
-
#
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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.
|
47
|
-
:
|
48
|
-
:
|
49
|
-
|
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.
|
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
|
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
|
-
|
79
|
-
|
80
|
-
:
|
81
|
-
|
82
|
-
:attribute => attribute
|
83
|
-
|
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
|
-
|
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.
|
97
|
-
:
|
98
|
-
|
99
|
-
|
100
|
-
:
|
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
|
-
|
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
|
@@ -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.
|
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-
|
12
|
+
date: 2011-10-04 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
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: *
|
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
|
-
-
|
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.
|
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
|