comfy_bootstrap_form 4.0.6 → 4.0.7

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: f748f321101c2f0f88499a1d4bc0bc64528e4476dec757cf777d8f0c401f8f73
4
- data.tar.gz: d257304f9ddcf1f62a713d2b1af1b2771bb49291607e3f148b5c312c3a4b847e
3
+ metadata.gz: 650142fb9785a2c81b49af5b2cb5dd6664a0eb2d97d03d9ec45dc0f3e7a82028
4
+ data.tar.gz: 8a5ba3cc671134a65c7ef5e5f85d903d378896c4383d5c663ea696f475e8f663
5
5
  SHA512:
6
- metadata.gz: 751de8df7d4ad259428c50fc9df981cbb217471bf90cca3db10efb4c7fd493e24b30dc8cdcc86541932c98e79fcf32ebb54fdb3576ebfd6f2475c62061e2985f
7
- data.tar.gz: 8cd0df58261044d8afd54ec00fd1a2a5ced9c6f32e22b410f3406a3fac45047abe103a1e67e610044d33b4772f96c2e599f75ad5d5a5e6ada28bc4149828a644
6
+ metadata.gz: 88934f425273927bcc89ac5046b73882171328e804c687d63f4b59e3c2aa3baef14a21a731dc393da4c0a69128e09bbab9060148faec6881bf9574ed4132e578
7
+ data.tar.gz: 1557ced41cb9823d56b5c56c6be7bfe3cdbe806284424133d46455b09cf3a8e8027d43e84d271d060ad040b8c793ce5b02b2377fa88159a126a36b38024dcd9f
@@ -36,6 +36,9 @@ Metrics/AbcSize:
36
36
  Enabled: false
37
37
 
38
38
  # -- Layout --------------------------------------------------------------------
39
+ Layout/AlignHash:
40
+ EnforcedColonStyle: table
41
+
39
42
  Layout/MultilineOperationIndentation:
40
43
  Enabled: false
41
44
 
@@ -45,7 +48,7 @@ Layout/MultilineMethodCallIndentation:
45
48
  Layout/MultilineHashBraceLayout:
46
49
  Enabled: false
47
50
 
48
- Layout/IndentArray:
51
+ Layout/IndentFirstArrayElement:
49
52
  EnforcedStyle: consistent
50
53
 
51
54
  Layout/EmptyLinesAroundModuleBody:
@@ -1,12 +1,19 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.7
4
- - 2.4.4
5
- - 2.5.1
3
+ - 2.3.8
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
6
7
  gemfile:
7
8
  - test/gemfiles/5.0.gemfile
8
9
  - test/gemfiles/5.1.gemfile
9
10
  - test/gemfiles/5.2.gemfile
11
+ jobs:
12
+ include:
13
+ - rvm: 2.5.7
14
+ gemfile: test/gemfiles/6.0.gemfile
15
+ - rvm: 2.6.5
16
+ gemfile: test/gemfiles/6.0.gemfile
10
17
  branches:
11
18
  only:
12
19
  - master
data/Gemfile CHANGED
@@ -5,10 +5,22 @@ source "http://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  # Uncomment and change rails version for testing purposes
8
- gem "rails", "~> 5.2.0.rc1"
8
+ # gem "rails", "~> 5.0.0"
9
+ # gem "rails", "~> 5.1.0"
10
+ # gem "rails", "~> 5.2.0"
11
+ gem "rails", "~> 6.0.0"
12
+
13
+ # Rails 5.0 needs lower version of this gem:
14
+ # gem "sqlite3", "~> 1.3.0"
15
+ gem "sqlite3"
9
16
 
10
17
  group :development do
11
- gem "rubocop", require: false
18
+ # Access an interactive console on exception pages or by calling 'console' anywhere in the code.
19
+ gem "listen", ">= 3.0.5", "< 3.2"
20
+ gem "rubocop", "0.70.0", require: false
21
+ gem "sassc-rails"
22
+ gem "web-console", ">= 3.3.0"
23
+ gem "webpacker"
12
24
  end
13
25
 
14
26
  group :test do
@@ -16,6 +28,5 @@ group :test do
16
28
  gem "diffy"
17
29
  gem "equivalent-xml"
18
30
  gem "minitest"
19
- gem "sqlite3"
20
31
  gem "timecop"
21
32
  end
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018 Oleg Khabarov
1
+ Copyright 2018-19 Oleg Khabarov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -188,6 +188,7 @@ label: {}
188
188
  append: nil
189
189
  prepend: nil
190
190
  help: nil
191
+ error: nil
191
192
  check_inline: false
192
193
  custom_control: false
193
194
  ```
@@ -241,6 +242,7 @@ won't render all form elements. Things like errors messages won't show up right.
241
242
  You can change label generated by Rails to something else:
242
243
 
243
244
  ```erb
245
+ <%= form.text_field :value, bootstrap: {label: "Custom Label"} %>
244
246
  <%= form.text_field :value, bootstrap: {label: {text: "Custom Label"}} %>
245
247
  ```
246
248
 
@@ -329,4 +331,4 @@ You may completely disable bootstrap and use default form builder by passing
329
331
 
330
332
  ---
331
333
 
332
- Copyright 2018 Oleg Khabarov, Released under the [MIT License](LICENSE.md)
334
+ Copyright 2018-19 Oleg Khabarov, Released under the [MIT License](LICENSE.md)
@@ -12,22 +12,22 @@ module ComfyBootstrapForm
12
12
  class BootstrapOptions
13
13
 
14
14
  # When set to `true` only default rails form builder element is rendered.
15
- attr_reader :disabled
15
+ attr_accessor :disabled
16
16
 
17
17
  # Controls form layout. Can be: "vertical" (default), "horizontal" or "inline"
18
- attr_reader :layout
18
+ attr_accessor :layout
19
19
 
20
20
  # CSS class for label column when using horizontal form. Default: "col-sm-2"
21
- attr_reader :label_col_class
21
+ attr_accessor :label_col_class
22
22
 
23
23
  # CSS class for control column when using horizontal form. Default: "col-sm-10"
24
- attr_reader :control_col_class
24
+ attr_accessor :control_col_class
25
25
 
26
26
  # CSS class for label alignment in horizontal form. Default: "text-sm-right"
27
- attr_reader :label_align_class
27
+ attr_accessor :label_align_class
28
28
 
29
29
  # CSS class used to space out form groups for inline forms. Default: "mr-sm-2"
30
- attr_reader :inline_margin_class
30
+ attr_accessor :inline_margin_class
31
31
 
32
32
  # Label specific options. Default is and empty hash. Options are as follows:
33
33
  # text: "Label Text" - override automatically generated label text
@@ -48,26 +48,32 @@ module ComfyBootstrapForm
48
48
  #
49
49
  # form.text_field :search, bootstrap: {append: {html: "<button>Go</button>".html_safe}}
50
50
  #
51
- attr_reader :prepend
52
- attr_reader :append
51
+ attr_accessor :prepend
52
+ attr_accessor :append
53
53
 
54
54
  # Help text that goes under the form field. Example usage:
55
55
  #
56
56
  # form.password_field :password, bootstrap: {help: "Password should be more than 8 characters in length"}
57
57
  #
58
- attr_reader :help
58
+ attr_accessor :help
59
59
 
60
60
  # Options to render checkboxes and radio buttons inline. Default is false. Example:
61
61
  #
62
62
  # form.collection_radio_buttons :choices, ["yes", "no"], :to_s, :to_s, bootstrap: {check_inline: true}
63
63
  #
64
- attr_reader :check_inline
64
+ attr_accessor :check_inline
65
65
 
66
66
  # Enables special input styling for file_field, radio and checkboxes. Example:
67
67
  #
68
68
  # form.file_file :photo, bootstrap: {custom_control: true}
69
69
  #
70
- attr_reader :custom_control
70
+ attr_accessor :custom_control
71
+
72
+ # Manually rendering the error message. Example:
73
+ #
74
+ # form.text_field :foo, bootstrap: {error: "Error Message"}
75
+ #
76
+ attr_accessor :error
71
77
 
72
78
  def initialize(options = {})
73
79
  set_defaults
@@ -103,10 +109,14 @@ module ComfyBootstrapForm
103
109
 
104
110
  def set_options(options = {})
105
111
  options.is_a?(Hash) && options.each do |key, value|
106
- instance_variable_set("@#{key}", value)
112
+ public_send("#{key}=", value)
107
113
  end
108
114
  end
109
115
 
116
+ def label=(value)
117
+ @label = value.is_a?(Hash) ? value : { text: value }
118
+ end
119
+
110
120
  private
111
121
 
112
122
  def set_defaults
@@ -120,6 +130,7 @@ module ComfyBootstrapForm
120
130
  @append = nil
121
131
  @prepend = nil
122
132
  @help = nil
133
+ @error = nil
123
134
  @check_inline = false
124
135
  @custom_control = false
125
136
  end
@@ -7,8 +7,8 @@ module ComfyBootstrapForm
7
7
 
8
8
  FIELD_HELPERS = %w[
9
9
  color_field date_field datetime_field email_field month_field
10
- number_field password_field phone_field range_field search_field text_area
11
- text_field time_field url_field week_field
10
+ password_field phone_field range_field search_field text_area
11
+ text_field rich_text_area time_field url_field week_field
12
12
  ].freeze
13
13
 
14
14
  DATE_SELECT_HELPERS = %w[
@@ -67,6 +67,21 @@ module ComfyBootstrapForm
67
67
  RUBY_EVAL
68
68
  end
69
69
 
70
+ # Wrapper for the number field. It has default changed from `step: "1"` to `step: "any"`
71
+ # to prevent confusion when dealing with decimal numbers.
72
+ #
73
+ # number_field :amount, step: 5
74
+ #
75
+ def number_field(method, options = {})
76
+ bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
77
+ options.reverse_merge!(step: "any")
78
+ return super(method, options) if bootstrap.disabled
79
+
80
+ draw_form_group(bootstrap, method, options) do
81
+ super(method, options)
82
+ end
83
+ end
84
+
70
85
  # Wrapper for select helper. Boostrap options are sent via options hash:
71
86
  #
72
87
  # select :choices, ["a", "b"], bootstrap: {label: {text: "Custom"}}
@@ -116,8 +131,8 @@ module ComfyBootstrapForm
116
131
  bootstrap = form_bootstrap.scoped(options.delete(:bootstrap))
117
132
  return super if bootstrap.disabled
118
133
 
119
- help_text = draw_help(bootstrap.help)
120
- errors = draw_errors(method)
134
+ help_text = draw_help(bootstrap)
135
+ errors = draw_errors(bootstrap, method)
121
136
 
122
137
  add_css_class!(options, "form-check-input")
123
138
  add_css_class!(options, "is-invalid") if errors.present?
@@ -296,7 +311,7 @@ module ComfyBootstrapForm
296
311
  # form group wrapper for input fields
297
312
  def draw_form_group(bootstrap, method, options)
298
313
  label = draw_label(bootstrap, method, for_attr: options[:id])
299
- errors = draw_errors(method)
314
+ errors = draw_errors(bootstrap, method)
300
315
 
301
316
  control = draw_control(bootstrap, errors, method, options) do
302
317
  yield
@@ -312,9 +327,24 @@ module ComfyBootstrapForm
312
327
  end
313
328
  end
314
329
 
315
- def draw_errors(method)
316
- return unless object.present?
317
- return unless (errors = object.errors[method]).present?
330
+ def draw_errors(bootstrap, method)
331
+ errors = []
332
+
333
+ if bootstrap.error.present?
334
+ errors = [bootstrap.error]
335
+ else
336
+ return if object.nil?
337
+
338
+ errors = object.errors[method]
339
+
340
+ # If error is on association like `belongs_to :foo`, we need to render it
341
+ # on an input field with `:foo_id` name.
342
+ if errors.blank?
343
+ errors = object.errors[method.to_s.sub(%r{_id$}, "")]
344
+ end
345
+ end
346
+
347
+ return if errors.blank?
318
348
 
319
349
  content_tag(:div, class: "invalid-feedback") do
320
350
  errors.join(", ")
@@ -331,6 +361,10 @@ module ComfyBootstrapForm
331
361
  #
332
362
  # text_field(:value, bootstrap: {label: {text: "Custom", class: "custom"}})
333
363
  #
364
+ # You may also just set the label text by passing a string instead of label hash:
365
+ #
366
+ # text_field(:value, bootstrap: {label: "Custom Label"})
367
+ #
334
368
  def draw_label(bootstrap, method, for_attr: nil)
335
369
  options = bootstrap.label.dup
336
370
  text = options.delete(:text)
@@ -365,6 +399,7 @@ module ComfyBootstrapForm
365
399
  #
366
400
  def draw_control_column(bootstrap, offset:)
367
401
  return yield unless bootstrap.horizontal?
402
+
368
403
  css_class = bootstrap.control_col_class.to_s
369
404
  css_class += " #{bootstrap.offset_col_class}" if offset
370
405
  content_tag(:div, class: css_class) do
@@ -382,7 +417,7 @@ module ComfyBootstrapForm
382
417
  prepend_html = draw_input_group_content(bootstrap, :prepend)
383
418
  append_html = draw_input_group_content(bootstrap, :append)
384
419
 
385
- help_text = draw_help(bootstrap.help)
420
+ help_text = draw_help(bootstrap)
386
421
 
387
422
  # Not prepending or appending anything. Bail.
388
423
  if prepend_html.blank? && append_html.blank?
@@ -420,8 +455,10 @@ module ComfyBootstrapForm
420
455
  #
421
456
  # text_field(:value, bootstrap: {help: "help text"})
422
457
  #
423
- def draw_help(text)
458
+ def draw_help(bootstrap)
459
+ text = bootstrap.help
424
460
  return if text.blank?
461
+
425
462
  content_tag(:small, text, class: "form-text text-muted")
426
463
  end
427
464
 
@@ -451,8 +488,8 @@ module ComfyBootstrapForm
451
488
  add_css_class!(html_options, "form-check-input")
452
489
  end
453
490
 
454
- errors = draw_errors(method)
455
- help_text = draw_help(bootstrap.help)
491
+ errors = draw_errors(bootstrap, method)
492
+ help_text = draw_help(bootstrap)
456
493
 
457
494
  add_css_class!(html_options, "is-invalid") if errors.present?
458
495
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ComfyBootstrapForm
4
4
 
5
- VERSION = "4.0.6"
5
+ VERSION = "4.0.7"
6
6
 
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comfy_bootstrap_form
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.6
4
+ version: 4.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Khabarov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-09-03 00:00:00.000000000 Z
11
+ date: 2019-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails