rails_bootstrap_form 0.6.2 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f33d8a7c5b5a17656dc325d688c903ccfdc7780ef400340b9980dfd2a341d164
4
- data.tar.gz: eff2f3c9613d598feca7192fbc973452a544215840e92e662f30e3e4462922ed
3
+ metadata.gz: f773eed0774b5b8895a39fb0e54dd557a4fbc044a4481d1cd9d969e58628ae6d
4
+ data.tar.gz: df7e9521626f1359d60c4d334cdb2e94520a18c5c4aad7ebf257874f6d3005b8
5
5
  SHA512:
6
- metadata.gz: 7ef75e441c851217ba6ba93a69f693547cac3726b4481b8a400c7a93653e1831aef21e9e6f6c18581809c3c402e9fc560b416a9949ebd44c36251b72c7b73771
7
- data.tar.gz: 4d73c166848a01b13bff4be90b41dfd6269e9a58d53765068451884a96d50aabee903109680ee7453659baf95163558918d249004801560299006bdc7af6f40b
6
+ metadata.gz: f436a23b69de6e53d63dd08726270f1e85df5d9f6d3b8ae2030a204edcae1454fb90f16b20fac087583dffebaf67f18053594771c20312fdf9460b8260013a37
7
+ data.tar.gz: 5c77b719bebdb2985c056ab03d7153d09e2de6e1ae15602db62395906f105b6b7d1f2271e6c83fbe371bdc27c59ea2220aae0b79cd06ddae7dc5bcca1c2958a5
data/CHANGELOG.md CHANGED
@@ -4,6 +4,22 @@ You can find recent releases with docs in GitHub:
4
4
 
5
5
  https://github.com/shivam091/rails_bootstrap_form/releases
6
6
 
7
+ ## [0.7.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.7.0...v0.7.1) - 2023-05-24
8
+
9
+ ### What's new
10
+ - Added wrapper method for `weekday_select`.
11
+
12
+ ## [0.7.0](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.2...v0.7.0) - 2023-05-24
13
+
14
+ ### What's new
15
+ - Added helper methods for rendering submit buttons on forms.
16
+
17
+ ## [0.6.2](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.1...v0.6.2) - 2023-05-24
18
+
19
+ ### What's fixed
20
+ - Added support for setting bootstrap options of parent form to `fields_for` ([#10](https://github.com/shivam091/rails_bootstrap_form/issues/10))
21
+ - Ignore skip_label option when field has floating labels ([#9](https://github.com/shivam091/rails_bootstrap_form/issues/9))
22
+
7
23
  ## [0.6.1](https://github.com/shivam091/rails_bootstrap_form/compare/v0.6.0...v0.6.1) - 2023-05-24
8
24
 
9
25
  ### What's changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rails_bootstrap_form (0.6.2)
4
+ rails_bootstrap_form (0.7.1)
5
5
  actionpack (~> 7.0)
6
6
  activemodel (~> 7.0)
7
7
 
@@ -24,7 +24,7 @@
24
24
  <% end %>
25
25
  <%= form.check_box :terms, required: true %>
26
26
  <div class="mt-3">
27
- <%= form.submit "Register", class: "btn btn-primary" %>
27
+ <%= form.primary "Register" %>
28
28
  <%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
29
29
  </div>
30
30
  <% end %>
@@ -24,7 +24,7 @@
24
24
  <% end %>
25
25
  <%= form.check_box :terms, required: true %>
26
26
  <div class="mt-3">
27
- <%= form.submit "Register", class: "btn btn-primary" %>
27
+ <%= form.primary "Register" %>
28
28
  <%= link_to "Cancel", users_path, class: "btn btn-secondary" %>
29
29
  </div>
30
30
  <% end %>
@@ -119,6 +119,11 @@ module RailsBootstrapForm
119
119
  # The default value is `col-sm-10`.
120
120
  attr_accessor :field_col_wrapper_class
121
121
 
122
+ # Option to render submit button using `<button type="submit">` instead of
123
+ # `<input type="submit">`.
124
+ # The default value is `false`.
125
+ attr_accessor :render_as_button
126
+
122
127
  def initialize(options = {})
123
128
  set_defaults
124
129
  set_bootstrap_form_options(options)
@@ -136,10 +141,6 @@ module RailsBootstrapForm
136
141
  @layout.to_s == "vertical"
137
142
  end
138
143
 
139
- def inline?
140
- self.inline
141
- end
142
-
143
144
  # This will return a copy of `BootstrapFormOptions` object with new options set
144
145
  # that don't affect original object. This way we can have options specific
145
146
  # to a given form field. For example, we can change grid just for one field:
@@ -161,6 +162,10 @@ module RailsBootstrapForm
161
162
  end
162
163
  end
163
164
 
165
+ %i(inline floating switch skip_label hide_label render_as_button).each do |method|
166
+ define_method("#{method}?") { self.send(method) }
167
+ end
168
+
164
169
  def set_defaults
165
170
  @layout = "vertical"
166
171
 
@@ -191,6 +196,8 @@ module RailsBootstrapForm
191
196
  @label_col_class = "col-form-label"
192
197
  @label_col_wrapper_class = "col-sm-2"
193
198
  @field_col_wrapper_class = "col-sm-10"
199
+
200
+ @render_as_button = false
194
201
  end
195
202
 
196
203
  private :set_defaults
@@ -27,7 +27,7 @@ module RailsBootstrapForm
27
27
  end)
28
28
  end
29
29
  else
30
- if bootstrap_options.floating
30
+ if bootstrap_options.floating?
31
31
  tag.div(**field_wrapper_options(bootstrap_options)) do
32
32
  concat(input_group_wrapper(attribute, bootstrap_options) do
33
33
  tag.div(class: floating_label_classes(attribute)) do
@@ -82,7 +82,7 @@ module RailsBootstrapForm
82
82
  css_options[:class] = field_classes.flatten.compact
83
83
  css_options.merge!(required_field_options(attribute, options))
84
84
 
85
- if (bootstrap_options.floating && !bootstrap_options.layout_horizontal?)
85
+ if (bootstrap_options.floating? && !bootstrap_options.layout_horizontal?)
86
86
  css_options[:placeholder] ||= label_text(attribute, bootstrap_options)
87
87
  end
88
88
 
@@ -0,0 +1,39 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Helpers
7
+ module Buttons
8
+ extend ActiveSupport::Concern
9
+
10
+ def self.included(base_class)
11
+ def render_button(value = nil, options = {}, &block)
12
+ value, options = nil, value if value.is_a?(Hash)
13
+ bootstrap_options = bootstrap_form_options.scoped(options.delete(:bootstrap_form))
14
+
15
+ if (bootstrap_options.render_as_button? || block)
16
+ button(value, options, &block)
17
+ else
18
+ submit(value, options)
19
+ end
20
+ end
21
+
22
+ def secondary(value = nil, options = {}, &block)
23
+ add_css_class!(options, "btn btn-secondary")
24
+ render_button(value, options, &block)
25
+ end
26
+
27
+ def primary(value = nil, options = {}, &block)
28
+ add_css_class!(options, "btn btn-primary")
29
+ render_button(value, options, &block)
30
+ end
31
+
32
+ def danger(value = nil, options = {}, &block)
33
+ add_css_class!(options, "btn btn-danger")
34
+ render_button(value, options, &block)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -9,7 +9,7 @@ module RailsBootstrapForm
9
9
 
10
10
  def self.included(base_class)
11
11
  def check_box_label(attribute, checked_value, options, bootstrap_options, &block)
12
- unless bootstrap_options.skip_label
12
+ unless bootstrap_options.skip_label?
13
13
  label_options = {
14
14
  class: check_box_label_class(attribute, bootstrap_options, options)
15
15
  }
@@ -54,13 +54,13 @@ module RailsBootstrapForm
54
54
  classes = Array("form-check-label") << bootstrap_options.additional_label_class
55
55
  classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
56
56
  classes << "is-invalid" if is_invalid?(attribute)
57
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label
57
+ classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
58
58
  classes.flatten.compact
59
59
  end
60
60
 
61
61
  def check_box_wrapper_class(bootstrap_options)
62
62
  classes = Array("form-check")
63
- classes << "form-switch" if bootstrap_options.switch
63
+ classes << "form-switch" if bootstrap_options.switch?
64
64
  classes << "form-check-inline" if bootstrap_options.inline?
65
65
  classes << "mb-3" unless (bootstrap_options.layout_horizontal? || bootstrap_options.inline?)
66
66
  classes.flatten.compact
@@ -9,7 +9,7 @@ module RailsBootstrapForm
9
9
 
10
10
  def self.included(base_class)
11
11
  def draw_label(attribute, options, bootstrap_options)
12
- unless bootstrap_options.skip_label && !bootstrap_options.floating
12
+ unless bootstrap_options.skip_label? && !bootstrap_options.floating?
13
13
  label_options = {
14
14
  class: label_classes(attribute, bootstrap_options)
15
15
  }
@@ -28,7 +28,7 @@ module RailsBootstrapForm
28
28
  bootstrap_options.label_class
29
29
  end
30
30
  classes << bootstrap_options.additional_label_class
31
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label
31
+ classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
32
32
  classes << "required" if is_attribute_required?(attribute)
33
33
  classes << "is-invalid" if is_invalid?(attribute)
34
34
  classes.flatten.compact
@@ -9,7 +9,7 @@ module RailsBootstrapForm
9
9
 
10
10
  def self.included(base_class)
11
11
  def radio_button_label(attribute, value, options, bootstrap_options)
12
- unless bootstrap_options.skip_label
12
+ unless bootstrap_options.skip_label?
13
13
  label_options = {
14
14
  value: value,
15
15
  class: radio_button_label_class(attribute, bootstrap_options, options)
@@ -51,7 +51,7 @@ module RailsBootstrapForm
51
51
  classes = Array("form-check-label") << bootstrap_options.additional_label_class
52
52
  classes << "required" if is_field_required?(attribute, options) && !bootstrap_options.inline?
53
53
  classes << "is-invalid" if is_invalid?(attribute)
54
- classes << bootstrap_options.hide_class if bootstrap_options.hide_label
54
+ classes << bootstrap_options.hide_class if bootstrap_options.hide_label?
55
55
  classes.flatten.compact
56
56
  end
57
57
 
@@ -13,6 +13,7 @@ module RailsBootstrapForm
13
13
  autoload :Errors
14
14
  autoload :CheckBox
15
15
  autoload :RadioButton
16
+ autoload :Buttons
16
17
 
17
18
  include HelpText
18
19
  include Labels
@@ -20,6 +21,7 @@ module RailsBootstrapForm
20
21
  include Errors
21
22
  include CheckBox
22
23
  include RadioButton
24
+ include Buttons
23
25
 
24
26
  def self.included(base_class)
25
27
  def collection_input_checked?(checked, obj, input_value)
@@ -39,7 +41,19 @@ module RailsBootstrapForm
39
41
  label_col_wrapper_class.gsub(/\bcol-(\w+)-(\d)\b/, 'offset-\1-\2')
40
42
  end
41
43
 
42
- private :collection_input_checked?, :control_specific_class, :is_size_valid?
44
+ def add_css_class!(options, css_class)
45
+ the_class = [options[:class], css_class].compact
46
+ options[:class] = the_class if the_class.present?
47
+ end
48
+
49
+ def remove_css_class!(options, css_class)
50
+ the_class = options[:class].to_s.split(" ")
51
+ options[:class] = (the_class - [css_class]).compact.join(" ")
52
+ options.delete(:class) if options[:class].blank?
53
+ end
54
+
55
+ private :collection_input_checked?, :control_specific_class, :is_size_valid?,
56
+ :add_css_class!, :remove_css_class!
43
57
  end
44
58
  end
45
59
  end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # -*- frozen_string_literal: true -*-
3
+ # -*- warn_indent: true -*-
4
+
5
+ module RailsBootstrapForm
6
+ module Inputs
7
+ module WeekdaySelect
8
+ extend ActiveSupport::Concern
9
+
10
+ included do
11
+ def weekday_select(attribute, options = {}, html_options = {}, &block)
12
+ options = {bootstrap_form: {field_class: "form-select"}}.deep_merge!(options)
13
+
14
+ field_wrapper_builder(attribute, options, html_options) do
15
+ super(attribute, options, html_options, &block)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -38,6 +38,7 @@ module RailsBootstrapForm
38
38
  autoload :TimeZoneSelect
39
39
  autoload :UrlField
40
40
  autoload :WeekField
41
+ autoload :WeekdaySelect
41
42
 
42
43
  include Base
43
44
  include CheckBox
@@ -71,5 +72,6 @@ module RailsBootstrapForm
71
72
  include TimeZoneSelect
72
73
  include UrlField
73
74
  include WeekField
75
+ include WeekdaySelect
74
76
  end
75
77
  end
@@ -3,6 +3,6 @@
3
3
  # -*- warn_indent: true -*-
4
4
 
5
5
  module RailsBootstrapForm
6
- VERSION = "0.6.2".freeze
6
+ VERSION = "0.7.1".freeze
7
7
  REQUIRED_RAILS_VERSION = "~> 7.0".freeze
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harshal LADHE (shivam091)
@@ -143,6 +143,7 @@ files:
143
143
  - lib/rails_bootstrap_form/engine.rb
144
144
  - lib/rails_bootstrap_form/field_wrapper_builder.rb
145
145
  - lib/rails_bootstrap_form/helpers.rb
146
+ - lib/rails_bootstrap_form/helpers/buttons.rb
146
147
  - lib/rails_bootstrap_form/helpers/check_box.rb
147
148
  - lib/rails_bootstrap_form/helpers/errors.rb
148
149
  - lib/rails_bootstrap_form/helpers/help_text.rb
@@ -183,6 +184,7 @@ files:
183
184
  - lib/rails_bootstrap_form/inputs/time_zone_select.rb
184
185
  - lib/rails_bootstrap_form/inputs/url_field.rb
185
186
  - lib/rails_bootstrap_form/inputs/week_field.rb
187
+ - lib/rails_bootstrap_form/inputs/weekday_select.rb
186
188
  - lib/rails_bootstrap_form/version.rb
187
189
  - sig/rails_bootstrap_form.rbs
188
190
  homepage: https://github.com/shivam091/rails_bootstrap_form