bootstrap_forms 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,7 +24,7 @@ Add it to your `Gemfile`:
24
24
 
25
25
  gem 'bootstrap_forms'
26
26
 
27
- Don't forget to run the `bundle` command. The gem will add 2 methods `bootstrap_form_for` and `bootstrap_fields_for` for use in your project. This is different from `bootstrap_forms < 0.1.0`. In previous versions, the default form builders were overridden by default. With backlash from various community members, this is no longer the default.
27
+ Don't forget to run the `bundle` command. The gem will add the method `bootstrap_form_for` for use in your project. This is different from `bootstrap_forms < 0.1.0`. In previous versions, the default form builders were overridden by default. With backlash from various community members, this is no longer the default.
28
28
 
29
29
  Be sure to restart your Rails server after installing the gem.
30
30
 
@@ -69,6 +69,14 @@ See description above...
69
69
  = f.collection_radio_buttons :primary_category_id, Category.all, :id, :name
70
70
  ```
71
71
 
72
+ ### radio_buttons
73
+
74
+ ```haml
75
+ = f.radio_buttons :published, { "Published" => true, "Unpublished" => false }
76
+ ```
77
+
78
+ Ruby 1.8 doesn't guarantee hashes are ordered. If you care, pass in nested arrays or `ActiveSupport::OrderedHash`.
79
+
72
80
  Uneditable Input
73
81
  ----------------
74
82
  Bootstrap Forms adds another helper method that generates the necessary markup for uneditable inputs:
@@ -105,6 +113,8 @@ generates:
105
113
  </div>
106
114
  ```
107
115
 
116
+ You can skip the cancel button by passing the `:include_cancel` button a `false` value.
117
+
108
118
  Pretty swell if you ask me.
109
119
 
110
120
  Adding More Options
@@ -187,4 +197,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
187
197
 
188
198
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
189
199
 
190
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
200
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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.3"
6
+ s.version = "1.0.4"
7
7
  s.author = "Seth Vargo"
8
8
  s.email = "sethvargo@gmail.com"
9
9
  s.homepage = "https://github.com/sethvargo/bootstrap_forms"
@@ -0,0 +1,6 @@
1
+ sv:
2
+ bootstrap_forms:
3
+ errors:
4
+ header: "Kunde inte spara på grund av nedanstående fel:"
5
+ buttons:
6
+ cancel: 'Avbryt'
@@ -4,9 +4,8 @@ module BootstrapForms
4
4
 
5
5
  def error_messages
6
6
  if object.errors.full_messages.any?
7
- content_tag(:div, :class => 'alert alert-block alert-error') do
8
- link_to('&times;'.html_safe, '#', {:class => 'close', :data => { :dismiss => 'alert' }}) +
9
- content_tag(:h4, I18n.t('bootstrap_forms.errors.header', :model => object.class.model_name.humanize), :class => 'alert-heading') +
7
+ content_tag(:div, :class => 'alert alert-block alert-error validation-errors') do
8
+ content_tag(:h4, I18n.t('bootstrap_forms.errors.header', :model => object.class.model_name.human), :class => 'alert-heading') +
10
9
  content_tag(:ul) do
11
10
  object.errors.full_messages.map do |message|
12
11
  content_tag(:li, message)
@@ -18,20 +17,15 @@ module BootstrapForms
18
17
  end
19
18
  end
20
19
 
21
- def bootstrap_fields_for(record_name, record_object = nil, options = {}, &block)
22
- options[:builder] = BootstrapForms::FormBuilder
23
- fields_for(record_name, record_object, options, &block)
24
- end
25
-
26
20
  %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
21
  define_method(method_name) do |name, *args|
28
22
  @name = name
29
- @options = args.extract_options!
23
+ @field_options = args.extract_options!
30
24
  @args = args
31
25
 
32
26
  control_group_div do
33
27
  label_field + input_div do
34
- extras { super(name, *(@args << @options)) }
28
+ extras { super(name, *(@args << @field_options)) }
35
29
  end
36
30
  end
37
31
  end
@@ -39,21 +33,36 @@ module BootstrapForms
39
33
 
40
34
  def check_box(name, *args)
41
35
  @name = name
42
- @options = args.extract_options!
36
+ @field_options = args.extract_options!
43
37
  @args = args
44
38
 
45
39
  control_group_div do
46
40
  input_div do
47
41
  label(@name, :class => [ 'checkbox', required_class ].compact.join(' ')) do
48
- extras { super(name, *(@args << @options)) + object.class.human_attribute_name(name) }
42
+ extras { super(name, *(@args << @field_options)) + human_attribute_name }
49
43
  end
50
44
  end
51
45
  end
52
46
  end
53
47
 
48
+ def radio_buttons(name, values={}, opts={})
49
+ @name = name
50
+ @options = opts
51
+
52
+ control_group_div do
53
+ label_field + input_div do
54
+ values.map do |text, value|
55
+ label("#{@name}_#{value}", :class => [ 'radio', required_class ].compact.join(' ')) do
56
+ extras { radio_button(name, value, @options) + text }
57
+ end
58
+ end.join.html_safe
59
+ end
60
+ end
61
+ end
62
+
54
63
  def collection_check_boxes(attribute, records, record_id, record_name, *args)
55
64
  @name = attribute
56
- @options = args.extract_options!
65
+ @field_options = args.extract_options!
57
66
  @args = args
58
67
 
59
68
  control_group_div do
@@ -61,9 +70,9 @@ module BootstrapForms
61
70
  content_tag(:div, :class => 'controls') do
62
71
  records.collect do |record|
63
72
  element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
64
- checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [object.send(attribute)].flatten.include?(record.send(record_id)), @options.merge({:id => element_id}))
73
+ checkbox = check_box_tag("#{object_name}[#{attribute}][]", record.send(record_id), [object.send(attribute)].flatten.include?(record.send(record_id)), @field_options.merge({:id => element_id}))
65
74
 
66
- content_tag(:label, :class => ['checkbox', ('inline' if @options[:inline])].compact.join(' ')) do
75
+ content_tag(:label, :class => ['checkbox', ('inline' if @field_options[:inline])].compact.join(' ')) do
67
76
  checkbox + content_tag(:span, record.send(record_name))
68
77
  end
69
78
  end.join('').html_safe
@@ -74,7 +83,7 @@ module BootstrapForms
74
83
 
75
84
  def collection_radio_buttons(attribute, records, record_id, record_name, *args)
76
85
  @name = attribute
77
- @options = args.extract_options!
86
+ @field_options = args.extract_options!
78
87
  @args = args
79
88
 
80
89
  control_group_div do
@@ -82,9 +91,9 @@ module BootstrapForms
82
91
  content_tag(:div, :class => 'controls') do
83
92
  records.collect do |record|
84
93
  element_id = "#{object_name}_#{attribute}_#{record.send(record_id)}"
85
- radiobutton = radio_button_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), @options.merge({:id => element_id}))
94
+ radiobutton = radio_button_tag("#{object_name}[#{attribute}][]", record.send(record_id), object.send(attribute) == record.send(record_id), @field_options.merge({:id => element_id}))
86
95
 
87
- content_tag(:label, :class => ['radio', ('inline' if @options[:inline])].compact.join(' ')) do
96
+ content_tag(:label, :class => ['radio', ('inline' if @field_options[:inline])].compact.join(' ')) do
88
97
  radiobutton + content_tag(:span, record.send(record_name))
89
98
  end
90
99
  end.join('').html_safe
@@ -95,14 +104,14 @@ module BootstrapForms
95
104
 
96
105
  def uneditable_input(name, *args)
97
106
  @name = name
98
- @options = args.extract_options!
107
+ @field_options = args.extract_options!
99
108
  @args = args
100
109
 
101
110
  control_group_div do
102
111
  label_field + input_div do
103
112
  extras do
104
113
  content_tag(:span, :class => 'uneditable-input') do
105
- @options[:value] || object.send(@name.to_sym)
114
+ @field_options[:value] || object.send(@name.to_sym)
106
115
  end
107
116
  end
108
117
  end
@@ -111,34 +120,51 @@ module BootstrapForms
111
120
 
112
121
  def submit(name = nil, *args)
113
122
  @name = name
114
- @options = args.extract_options!
123
+ @field_options = args.extract_options!
115
124
  @args = args
116
125
 
117
- @options[:class] = 'btn btn-primary'
126
+ @field_options[:class] = 'btn btn-primary'
118
127
 
119
128
  content_tag(:div, :class => 'form-actions') do
120
- super(name, *(args << @options)) + ' ' + button_tag(I18n.t('bootstrap_forms.buttons.cancel'), :type => 'reset', :class => 'btn cancel')
129
+ if @field_options[:include_cancel] == false
130
+ super(name, *(args << @field_options))
131
+ else
132
+ super(name, *(args << @field_options)) + ' ' + link_to(I18n.t('bootstrap_forms.buttons.cancel'), (@field_options[:back] || :back), :class => 'btn cancel')
133
+ end
121
134
  end
122
135
  end
123
136
 
124
137
  private
125
138
  def control_group_div(&block)
126
- @options[:error] = object.errors[@name].collect{|e| "#{@options[:label] || @name} #{e}".humanize}.join(', ') unless object.errors[@name].empty?
139
+ @field_options[:error] = error_string
127
140
 
128
141
  klasses = ['control-group']
129
- klasses << 'error' if @options[:error]
130
- klasses << 'success' if @options[:success]
131
- klasses << 'warning' if @options[:warning]
142
+ klasses << 'error' if @field_options[:error]
143
+ klasses << 'success' if @field_options[:success]
144
+ klasses << 'warning' if @field_options[:warning]
132
145
  klass = klasses.join(' ')
133
146
 
134
147
  content_tag(:div, :class => klass, &block)
135
148
  end
136
149
 
150
+ def error_string
151
+ errors = object.errors[@name]
152
+ if errors.present?
153
+ errors.map { |e|
154
+ "#{@options[:label] || human_attribute_name} #{e}"
155
+ }.join(", ")
156
+ end
157
+ end
158
+
159
+ def human_attribute_name
160
+ object.class.human_attribute_name(@name)
161
+ end
162
+
137
163
  def input_div(&block)
138
164
  content_tag(:div, :class => 'controls') do
139
- if @options[:append] || @options[:prepend]
140
- klass = 'input-prepend' if @options[:prepend]
141
- klass = 'input-append' if @options[:append]
165
+ if @field_options[:append] || @field_options[:prepend]
166
+ klass = 'input-prepend' if @field_options[:prepend]
167
+ klass = 'input-append' if @field_options[:append]
142
168
  content_tag(:div, :class => klass, &block)
143
169
  else
144
170
  yield if block_given?
@@ -147,17 +173,17 @@ module BootstrapForms
147
173
  end
148
174
 
149
175
  def label_field(&block)
150
- label(@name, block_given? ? block : @options[:label], :class => ['control-label', required_class].compact.join(' '))
176
+ label(@name, block_given? ? block : @field_options[:label], :class => ['control-label', required_class].compact.join(' '))
151
177
  end
152
178
 
153
179
  def required_class
154
- 'required' if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
180
+ return 'required' if object.class.validators_on(@name).any? { |v| v.kind_of? ActiveModel::Validations::PresenceValidator }
155
181
  nil
156
182
  end
157
183
 
158
184
  %w(help_inline error success warning help_block append prepend).each do |method_name|
159
185
  define_method(method_name) do |*args|
160
- return '' unless value = @options[method_name.to_sym]
186
+ return '' unless value = @field_options[method_name.to_sym]
161
187
  case method_name
162
188
  when 'help_block'
163
189
  element = :p
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.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -25,6 +25,7 @@ files:
25
25
  - Rakefile
26
26
  - bootstrap_forms.gemspec
27
27
  - config/locales/en.yml
28
+ - config/locales/sv.yml
28
29
  - lib/bootstrap_forms.rb
29
30
  - lib/bootstrap_forms/engine.rb
30
31
  - lib/bootstrap_forms/form_builder.rb