twitter_bootstrap_form_for 1.0.1 → 1.0.2
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/CHANGELOG.markdown +7 -1
- data/README.markdown +13 -11
- data/examples/screenshot.png +0 -0
- data/lib/twitter_bootstrap_form_for.rb +3 -2
- data/lib/twitter_bootstrap_form_for/form_builder.rb +52 -40
- data/lib/twitter_bootstrap_form_for/form_helpers.rb +1 -1
- data/lib/twitter_bootstrap_form_for/railtie.rb +1 -1
- data/lib/twitter_bootstrap_form_for/version.rb +1 -1
- data/twitter_bootstrap_form_for.gemspec +3 -4
- metadata +65 -28
- data/.gitignore +0 -3
data/CHANGELOG.markdown
CHANGED
@@ -1,8 +1,14 @@
|
|
1
1
|
Twitter Bootstrap Form For Changes
|
2
2
|
==================================
|
3
3
|
|
4
|
+
## 1.0.2 (2011-10-31) ##
|
5
|
+
- dependencies reduced to just `railties` and `actionpack`
|
6
|
+
- 1.8.7 compatibility fixes
|
7
|
+
- added compatibility with non-ActiveModel objects
|
8
|
+
- demonstrated use of radio buttons in the README
|
9
|
+
|
4
10
|
## 1.0.1 (2011-10-06) ##
|
5
|
-
- hidden_field tags are no accidentally marked-up (issue #5)
|
11
|
+
- hidden_field tags are no longer accidentally marked-up (issue #5)
|
6
12
|
|
7
13
|
## 1.0.0 (2011-10-04) ##
|
8
14
|
- added a changelog
|
data/README.markdown
CHANGED
@@ -15,39 +15,41 @@ Formtastic does), it only lightly wraps the existing Rails form tag helpers.
|
|
15
15
|
|
16
16
|
Just Rails. But you were going to use that anyway, weren't you?
|
17
17
|
|
18
|
-
I may consider adding a dependency on `less-rails-bootstrap` in the future, to
|
19
|
-
tie this plugin to specific releases of Twitter Bootstrap.
|
20
|
-
|
21
18
|
## Syntax ##
|
22
19
|
|
23
20
|
```haml
|
24
21
|
= twitter_bootstrap_form_for @user do |user|
|
25
|
-
|
22
|
+
|
26
23
|
/ wraps a section in a fieldset with the provided legend text
|
27
24
|
= user.inputs 'Sign up' do
|
28
|
-
|
25
|
+
|
29
26
|
/ generates a standard email field
|
30
27
|
= user.email_field :email, :placeholder => 'me@example.com'
|
31
|
-
|
28
|
+
|
32
29
|
/ generates a password field with a descriptive aside
|
33
30
|
= user.password_field :password do
|
34
31
|
%span.help-block
|
35
32
|
Must be no larger than 6 characters<br/>
|
36
33
|
Must contain only the letters 'x' or 'p'
|
37
|
-
|
34
|
+
|
38
35
|
/ a field with a custom label
|
39
36
|
= user.password_field :password_confirmation, 'Confirm Password'
|
40
|
-
|
37
|
+
|
41
38
|
/ input fields with custom add-ons
|
42
39
|
= user.text_field :twitter_id, 'Twitter', :class => 'medium', :add_on => :prepend do
|
43
40
|
%span.add-on @
|
44
|
-
|
45
|
-
/
|
41
|
+
|
42
|
+
/ group of radio buttons
|
43
|
+
= user.toggles 'Email Preferences' do
|
44
|
+
= user.radio_button :email, 'HTML Email', :html, :checked => true
|
45
|
+
= user.radio_button :email, 'Plain Text', :plain
|
46
|
+
|
47
|
+
/ group of checkboxes
|
46
48
|
= user.toggles 'Agreements' do
|
47
49
|
= user.check_box :agree, 'I agree to the abusive Terms and Conditions'
|
48
50
|
= user.check_box :spam, 'I agree to receive all sorts of spam'
|
49
51
|
= user.check_box :spammer, 'I agree to let the site spam others through my Twitter account'
|
50
|
-
|
52
|
+
|
51
53
|
/ wraps buttons in a distinctive style
|
52
54
|
= user.actions do
|
53
55
|
= user.submit 'Sign up'
|
data/examples/screenshot.png
CHANGED
Binary file
|
@@ -1,9 +1,10 @@
|
|
1
|
+
require 'action_view'
|
2
|
+
|
1
3
|
module TwitterBootstrapFormFor
|
2
|
-
require 'twitter_bootstrap_form_for/version'
|
3
|
-
|
4
4
|
autoload :FormBuilder, 'twitter_bootstrap_form_for/form_builder'
|
5
5
|
autoload :FormHelpers, 'twitter_bootstrap_form_for/form_helpers'
|
6
6
|
autoload :Railtie, 'twitter_bootstrap_form_for/railtie'
|
7
|
+
autoload :VERSION, 'twitter_bootstrap_form_for/version'
|
7
8
|
end
|
8
9
|
|
9
10
|
TwitterBootstrapFormFor::Railtie # trigger loading the Railtie
|
@@ -1,28 +1,29 @@
|
|
1
1
|
require 'twitter_bootstrap_form_for'
|
2
|
+
require 'action_view/helpers'
|
2
3
|
|
3
4
|
class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
4
5
|
# TODO: support inline inputs
|
5
|
-
|
6
|
+
|
6
7
|
include TwitterBootstrapFormFor::FormHelpers
|
7
|
-
|
8
|
+
|
8
9
|
attr_reader :template
|
9
10
|
attr_reader :object
|
10
11
|
attr_reader :object_name
|
11
|
-
|
12
|
+
|
12
13
|
INPUTS = [
|
13
14
|
:select,
|
14
|
-
*ActionView::Helpers::FormBuilder.instance_methods.grep(%r{
|
15
|
-
|
16
|
-
|
15
|
+
*ActionView::Helpers::FormBuilder.instance_methods.grep(%r{
|
16
|
+
_(area|field|select)$ # all area, field, and select methods
|
17
|
+
}mx)
|
17
18
|
]
|
18
|
-
|
19
|
+
|
19
20
|
INPUTS.delete(:hidden_field)
|
20
|
-
|
21
|
+
|
21
22
|
TOGGLES = [
|
22
23
|
:check_box,
|
23
24
|
:radio_button,
|
24
25
|
]
|
25
|
-
|
26
|
+
|
26
27
|
#
|
27
28
|
# Wraps the contents of the block passed in a fieldset with optional
|
28
29
|
# +legend+ text.
|
@@ -30,10 +31,8 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
30
31
|
def inputs(legend = nil, &block)
|
31
32
|
# stash the old field_error_proc, then override it temporarily
|
32
33
|
original_field_error_proc = template.field_error_proc
|
33
|
-
template.field_error_proc =
|
34
|
-
|
35
|
-
# TODO: fix field with errors for good
|
36
|
-
template.field_error_proc = ->(html_tag, instance) { html_tag }
|
34
|
+
template.field_error_proc = lambda {|html_tag, instance| html_tag }
|
35
|
+
|
37
36
|
template.content_tag(:fieldset) do
|
38
37
|
template.concat template.content_tag(:legend, legend) unless legend.nil?
|
39
38
|
block.call
|
@@ -41,7 +40,7 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
41
40
|
ensure
|
42
41
|
template.field_error_proc = original_field_error_proc
|
43
42
|
end
|
44
|
-
|
43
|
+
|
45
44
|
#
|
46
45
|
# Wraps groups of toggles (radio buttons, checkboxes) with a single label
|
47
46
|
# and the appropriate markup. All toggle buttons should be rendered
|
@@ -55,87 +54,100 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
55
54
|
}
|
56
55
|
end
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
#
|
60
59
|
# Wraps action buttons into their own styled container.
|
61
60
|
#
|
62
61
|
def actions(&block)
|
63
62
|
template.content_tag(:div, :class => 'actions', &block)
|
64
63
|
end
|
65
|
-
|
64
|
+
|
66
65
|
#
|
67
66
|
# Renders a submit tag with default classes to style it as a primary form
|
68
67
|
# button.
|
69
68
|
#
|
70
69
|
def submit(value = nil, options = {})
|
71
70
|
options[:class] ||= 'btn primary'
|
72
|
-
|
71
|
+
|
73
72
|
super value, options
|
74
73
|
end
|
75
|
-
|
74
|
+
|
76
75
|
INPUTS.each do |input|
|
77
76
|
define_method input do |attribute, *args, &block|
|
78
77
|
options = args.extract_options!
|
79
78
|
label = args.first.nil? ? '' : args.shift
|
80
79
|
classes = [ 'input' ]
|
81
80
|
classes << ('input-' + options.delete(:add_on).to_s) if options[:add_on]
|
82
|
-
|
83
|
-
self.div_wrapper(attribute
|
81
|
+
|
82
|
+
self.div_wrapper(attribute) do
|
84
83
|
template.concat self.label(attribute, label) if label
|
85
84
|
template.concat template.content_tag(:div, :class => classes.join(' ')) {
|
86
85
|
template.concat super(attribute, *(args << options))
|
87
|
-
template.concat
|
86
|
+
template.concat error_span(attribute)
|
88
87
|
block.call if block.present?
|
89
88
|
}
|
90
89
|
end
|
91
90
|
end
|
92
91
|
end
|
93
|
-
|
92
|
+
|
94
93
|
TOGGLES.each do |toggle|
|
95
94
|
define_method toggle do |attribute, *args, &block|
|
96
|
-
options = args.extract_options!
|
97
95
|
label = args.first.nil? ? '' : args.shift
|
98
96
|
target = self.object_name.to_s + '_' + attribute.to_s
|
99
|
-
|
97
|
+
|
100
98
|
template.content_tag(:li) do
|
101
99
|
template.concat template.content_tag(:label, :for => target) {
|
102
|
-
template.concat super(attribute, *
|
100
|
+
template.concat super(attribute, *args)
|
103
101
|
template.concat ' ' # give the input and span some room
|
104
102
|
template.concat template.content_tag(:span, label)
|
105
103
|
}
|
106
104
|
end
|
107
105
|
end
|
108
106
|
end
|
109
|
-
|
107
|
+
|
108
|
+
#
|
109
|
+
# Wraps the contents of +block+ inside a +tag+ with an appropriate class and
|
110
|
+
# id for the object's +attribute+. HTML options can be overridden by passing
|
111
|
+
# an +options+ hash.
|
112
|
+
#
|
110
113
|
def div_wrapper(attribute, options = {}, &block)
|
111
114
|
options[:id] = _wrapper_id attribute, options[:id]
|
112
|
-
options[:class] = _wrapper_classes attribute, options[:class]
|
113
|
-
|
114
|
-
template.content_tag
|
115
|
+
options[:class] = _wrapper_classes attribute, options[:class], 'clearfix'
|
116
|
+
|
117
|
+
template.content_tag :div, options, &block
|
115
118
|
end
|
116
|
-
|
119
|
+
|
120
|
+
def error_span(attribute, options = {})
|
121
|
+
options[:class] ||= 'help-inline'
|
122
|
+
|
123
|
+
template.content_tag(
|
124
|
+
:span, self.errors_for(attribute),
|
125
|
+
:class => options[:class]
|
126
|
+
) if self.errors_on?(attribute)
|
127
|
+
end
|
128
|
+
|
117
129
|
def errors_on?(attribute)
|
118
|
-
self.object.errors[attribute].present?
|
130
|
+
self.object.errors[attribute].present? if self.object.respond_to?(:errors)
|
119
131
|
end
|
120
|
-
|
132
|
+
|
121
133
|
def errors_for(attribute)
|
122
134
|
self.object.errors[attribute].try(:join, ', ')
|
123
135
|
end
|
124
|
-
|
136
|
+
|
125
137
|
private
|
126
|
-
|
138
|
+
|
127
139
|
#
|
128
140
|
# Returns an HTML id to uniquely identify the markup around an input field.
|
129
141
|
# If a +default+ is provided, it uses that one instead.
|
130
142
|
#
|
131
143
|
def _wrapper_id(attribute, default = nil)
|
132
144
|
default || [
|
133
|
-
_object_name + _object_index,
|
145
|
+
_object_name + _object_index,
|
134
146
|
_attribute_name(attribute),
|
135
147
|
'input'
|
136
148
|
].join('_')
|
137
149
|
end
|
138
|
-
|
150
|
+
|
139
151
|
#
|
140
152
|
# Returns any classes necessary for the wrapper div around fields for
|
141
153
|
# +attribute+, such as 'errors' if any errors are present on the attribute.
|
@@ -144,17 +156,17 @@ class TwitterBootstrapFormFor::FormBuilder < ActionView::Helpers::FormBuilder
|
|
144
156
|
def _wrapper_classes(attribute, *classes)
|
145
157
|
classes.tap do |classes|
|
146
158
|
classes.push 'error' if self.errors_on?(attribute)
|
147
|
-
end
|
159
|
+
end.join(' ')
|
148
160
|
end
|
149
|
-
|
161
|
+
|
150
162
|
def _attribute_name(attribute)
|
151
163
|
attribute.to_s.gsub(/[\?\/\-]$/, '')
|
152
164
|
end
|
153
|
-
|
165
|
+
|
154
166
|
def _object_name
|
155
167
|
self.object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, "_").sub(/_$/, "")
|
156
168
|
end
|
157
|
-
|
169
|
+
|
158
170
|
def _object_index
|
159
171
|
case
|
160
172
|
when options.has_key?(:index) then options[:index]
|
@@ -7,7 +7,7 @@ module TwitterBootstrapFormFor::FormHelpers
|
|
7
7
|
# add the TwitterBootstrap builder to the options
|
8
8
|
options = args.extract_options!
|
9
9
|
options[:builder] = TwitterBootstrapFormFor::FormBuilder
|
10
|
-
|
10
|
+
|
11
11
|
# call the original method with our overridden options
|
12
12
|
send method, record, *(args << options), &block
|
13
13
|
end
|
@@ -9,12 +9,11 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.homepage = 'http://github.com/stouset/twitter_bootstrap_form_for'
|
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
13
|
s.files = `git ls-files`.split("\n")
|
14
14
|
s.executables = `git ls-files`.split("\n").map {|f| f =~ /^bin\/(.*)/ ? $1 : nil }.compact
|
15
15
|
s.require_path = 'lib'
|
16
16
|
|
17
|
-
s.add_dependency '
|
18
|
-
|
19
|
-
# s.add_dependency 'twitter-bootstrap', '~> 1.3'
|
17
|
+
s.add_dependency 'railties', '~> 3'
|
18
|
+
s.add_dependency 'actionpack', '~> 3'
|
20
19
|
end
|
metadata
CHANGED
@@ -1,35 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_bootstrap_form_for
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 1.0.2
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Stephen Touset
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
|
18
|
+
date: 2011-10-31 00:00:00 -04:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: railties
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
25
|
none: false
|
18
|
-
requirements:
|
26
|
+
requirements:
|
19
27
|
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
version: "3"
|
22
33
|
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: actionpack
|
23
37
|
prerelease: false
|
24
|
-
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 5
|
44
|
+
segments:
|
45
|
+
- 3
|
46
|
+
version: "3"
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id002
|
25
49
|
description: A custom Rails FormBuilder that assumes the use of Twitter Bootstrap
|
26
|
-
email:
|
50
|
+
email:
|
27
51
|
- stephen@touset.org
|
28
52
|
executables: []
|
53
|
+
|
29
54
|
extensions: []
|
55
|
+
|
30
56
|
extra_rdoc_files: []
|
31
|
-
|
32
|
-
|
57
|
+
|
58
|
+
files:
|
33
59
|
- CHANGELOG.markdown
|
34
60
|
- README.markdown
|
35
61
|
- examples/screenshot.png
|
@@ -39,28 +65,39 @@ files:
|
|
39
65
|
- lib/twitter_bootstrap_form_for/railtie.rb
|
40
66
|
- lib/twitter_bootstrap_form_for/version.rb
|
41
67
|
- twitter_bootstrap_form_for.gemspec
|
68
|
+
has_rdoc: true
|
42
69
|
homepage: http://github.com/stouset/twitter_bootstrap_form_for
|
43
70
|
licenses: []
|
71
|
+
|
44
72
|
post_install_message:
|
45
73
|
rdoc_options: []
|
46
|
-
|
74
|
+
|
75
|
+
require_paths:
|
47
76
|
- lib
|
48
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
78
|
none: false
|
50
|
-
requirements:
|
51
|
-
- -
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
|
54
|
-
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
87
|
none: false
|
56
|
-
requirements:
|
57
|
-
- -
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
60
95
|
requirements: []
|
96
|
+
|
61
97
|
rubyforge_project:
|
62
|
-
rubygems_version: 1.
|
98
|
+
rubygems_version: 1.6.2
|
63
99
|
signing_key:
|
64
100
|
specification_version: 3
|
65
101
|
summary: Rails form builder optimized for Twitter Bootstrap
|
66
102
|
test_files: []
|
103
|
+
|
data/.gitignore
DELETED