bootstrap_forms 1.0.0 → 1.0.1
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/README.markdown +8 -1
- data/bootstrap_forms.gemspec +1 -1
- data/lib/bootstrap_forms/form_builder.rb +37 -8
- metadata +2 -2
data/README.markdown
CHANGED
@@ -33,7 +33,7 @@ Why?
|
|
33
33
|
With Bootstrap, you would need the following code for a form:
|
34
34
|
|
35
35
|
```haml
|
36
|
-
/ using
|
36
|
+
/ using HAML
|
37
37
|
= form_for @model do |f|
|
38
38
|
.clearfix
|
39
39
|
%label MyLabel
|
@@ -156,6 +156,13 @@ You can add as many options to any form helper tag. If they are interpreted by B
|
|
156
156
|
</tr>
|
157
157
|
</table>
|
158
158
|
|
159
|
+
Contributing
|
160
|
+
------------
|
161
|
+
I'm pretty dam active on github. Fork and submit a pull request. Most of my pull requests are merged the same day. Make sure you:
|
162
|
+
|
163
|
+
- Squash into a single commit (unless it makes sense to have multiple commits)
|
164
|
+
- Document your changes
|
165
|
+
|
159
166
|
License
|
160
167
|
-------
|
161
168
|
Copyright (c) 2012 Seth Vargo
|
data/bootstrap_forms.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "bootstrap_forms"
|
6
|
-
s.version = "1.0.
|
6
|
+
s.version = "1.0.1"
|
7
7
|
s.author = "Seth Vargo"
|
8
8
|
s.email = "sethvargo@gmail.com"
|
9
9
|
s.homepage = "https://github.com/sethvargo/bootstrap_forms"
|
@@ -23,7 +23,7 @@ module BootstrapForms
|
|
23
23
|
fields_for(record_name, record_object, options, &block)
|
24
24
|
end
|
25
25
|
|
26
|
-
%w(collection_select select
|
26
|
+
%w(collection_select select email_field file_field number_field password_field phone_field radio_button range_field search_field telephone_field text_area text_field url_field).each do |method_name|
|
27
27
|
define_method(method_name) do |name, *args|
|
28
28
|
@name = name
|
29
29
|
@options = args.extract_options!
|
@@ -37,6 +37,20 @@ module BootstrapForms
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
+
def check_box(name, *args)
|
41
|
+
@name = name
|
42
|
+
@options = args.extract_options!
|
43
|
+
@args = args
|
44
|
+
|
45
|
+
clearfix_div do
|
46
|
+
input_div do
|
47
|
+
label(@name, :class => [ 'checkbox', required_class ].compact.join(' ')) do
|
48
|
+
extras { super(name, *(@args << @options)) + object.class.human_attribute_name(name) }
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
40
54
|
def collection_check_boxes(attribute, records, record_id, record_name, *args)
|
41
55
|
@name = attribute
|
42
56
|
@options = args.extract_options!
|
@@ -141,17 +155,32 @@ module BootstrapForms
|
|
141
155
|
end
|
142
156
|
|
143
157
|
def label_field(&block)
|
144
|
-
|
145
|
-
|
158
|
+
label(@name, block_given? ? block : @options[:label], :class => [ 'control-label', required_class ].compact.join(' '))
|
159
|
+
end
|
160
|
+
|
161
|
+
def required_class
|
162
|
+
if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
|
163
|
+
'required'
|
164
|
+
else
|
165
|
+
nil
|
166
|
+
end
|
146
167
|
end
|
147
168
|
|
148
169
|
%w(help_inline error success warning help_block append prepend).each do |method_name|
|
149
170
|
define_method(method_name) do |*args|
|
150
171
|
return '' unless value = @options[method_name.to_sym]
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
172
|
+
case method_name
|
173
|
+
when 'help_block'
|
174
|
+
element = :p
|
175
|
+
klass = 'help-block'
|
176
|
+
when 'append', 'prepend'
|
177
|
+
element = :span
|
178
|
+
klass = 'add-on'
|
179
|
+
else
|
180
|
+
element = :span
|
181
|
+
klass = 'help-inline'
|
182
|
+
end
|
183
|
+
content_tag(element, value, :class => klass)
|
155
184
|
end
|
156
185
|
end
|
157
186
|
|
@@ -163,4 +192,4 @@ module BootstrapForms
|
|
163
192
|
super.except(:label, :help_inline, :error, :success, :warning, :help_block, :prepend, :append)
|
164
193
|
end
|
165
194
|
end
|
166
|
-
end
|
195
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bootstrap_forms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-07 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Bootstrap Forms makes Twitter's Bootstrap on Rails easy to use by creating
|
15
15
|
helpful form builders that minimize markup in your views.
|