view_component-form 0.2.5 → 0.2.6

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: bf9294810dc61eeda3187f0a15bd0fd41076a1aff08e35088123ff7b6394a7bc
4
- data.tar.gz: 1e354c3e739a66eabb5d4e33627ab6393a6385deebc4fbf05fbb7fdff514d8ce
3
+ metadata.gz: 128d4c769f1fa3e25cf83830db0b8279413dd8da3e9c7e312aeee06f0456336a
4
+ data.tar.gz: 63d592e4fa33d6bb77262bea0526761d5b251f26f37c6fac42a771f2506b3250
5
5
  SHA512:
6
- metadata.gz: 1ec60427e83e48970da97868e150f42796caeb0c4db320e6da67574aee28832e2d4c7fd540ecbdda3da3c6349e078d3a7038206ecd3c59934db58bc88fcc1a7e
7
- data.tar.gz: '058769880aa90ff14e44c80e36e9db16c7eda9f0262c92112a025a16e208b5fcde83f79d2b011f82d3f8802abc7eff4155fdb146b629cfdb5557db89ee87b5f7'
6
+ metadata.gz: f584160cf5560bf80869e4b98ea86d4ac0ce35b25c97dcbb5f38d4fbbacddfce7c64734697327d500b36e537391ac5c34f81470491b2ed75a3347e6664b53b08
7
+ data.tar.gz: 9fd72c0345d99a0207c006d916cf7e4f75224a88b4bc0175d3f56ffad491ebc42da14efa3619796896c12d37a8eef88dbd70911f47700eaa5fe520ea9f1277e0
data/CHANGELOG.md CHANGED
@@ -5,7 +5,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
7
  ## [Unreleased]
8
- Nothing yet
8
+
9
+ ## [0.2.6] - 2023-10-11
10
+ ### Added
11
+ - Support for Rails 7.1 (#151)
12
+ - Add `element_proc` option to `CollectionCheckBoxesComponent` and `CollectionRadioButtonsComponent` to customize the way the elements will be shown (#142)
9
13
 
10
14
  ## [0.2.5] - 2023-05-01
11
15
  ### Changed
data/README.md CHANGED
@@ -413,7 +413,7 @@ For more complex components, we recommend the [`rspec-html-matchers` gem](https:
413
413
 
414
414
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
415
415
 
416
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
416
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, run `bin/release x.x.x`, which will update the `version.rb` file, open the changelog for edition, create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
417
417
 
418
418
  ## Contributing
419
419
 
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ViewComponent
4
+ module Form
5
+ module ElementProc
6
+ attr_reader :element_proc
7
+
8
+ def initialize(*args, **kwargs)
9
+ super
10
+ set_element_proc!
11
+ end
12
+
13
+ protected
14
+
15
+ def set_element_proc!
16
+ options_element_proc = options.delete(:element_proc)
17
+ html_options_element_proc = html_options.delete(:element_proc)
18
+
19
+ if options_element_proc && html_options_element_proc
20
+ raise ArgumentError, "#{self.class.name} received :element_proc twice, expected only once"
21
+ end
22
+
23
+ @element_proc = options_element_proc || html_options_element_proc
24
+ end
25
+ end
26
+ end
27
+ end
@@ -3,6 +3,8 @@
3
3
  module ViewComponent
4
4
  module Form
5
5
  class CollectionCheckBoxesComponent < FieldComponent
6
+ include ElementProc
7
+
6
8
  attr_reader :collection, :value_method, :text_method, :html_options
7
9
 
8
10
  def initialize( # rubocop:disable Metrics/ParameterLists
@@ -36,7 +38,7 @@ module ViewComponent
36
38
  options,
37
39
  html_options,
38
40
  &content
39
- ).render
41
+ ).render(&element_proc)
40
42
  end
41
43
 
42
44
  protected
@@ -3,6 +3,8 @@
3
3
  module ViewComponent
4
4
  module Form
5
5
  class CollectionRadioButtonsComponent < FieldComponent
6
+ include ElementProc
7
+
6
8
  attr_reader :collection, :value_method, :text_method, :html_options
7
9
 
8
10
  def initialize( # rubocop:disable Metrics/ParameterLists
@@ -36,7 +38,7 @@ module ViewComponent
36
38
  options,
37
39
  html_options,
38
40
  &content
39
- ).render
41
+ ).render(&element_proc)
40
42
  end
41
43
 
42
44
  protected
@@ -71,13 +71,13 @@ module ViewComponent
71
71
  end
72
72
 
73
73
  def optional?(context: validation_context)
74
- return nil if object.nil?
74
+ return false if object.nil?
75
75
 
76
76
  !required?(context: context)
77
77
  end
78
78
 
79
79
  def required?(context: validation_context)
80
- return nil if object.nil?
80
+ return false if object.nil?
81
81
 
82
82
  validators(context: context).any?(ActiveModel::Validations::PresenceValidator)
83
83
  end
@@ -6,6 +6,7 @@ module ViewComponent
6
6
  class Engine < ::Rails::Engine
7
7
  config.autoload_once_paths = %W[
8
8
  #{root}/app/components
9
+ #{root}/app/components/concerns
9
10
  #{root}/app/lib
10
11
  ]
11
12
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ViewComponent
4
4
  module Form
5
- VERSION = "0.2.5"
5
+ VERSION = "0.2.6"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: view_component-form
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pantographe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-01 00:00:00.000000000 Z
11
+ date: 2023-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: 6.0.0
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '7.1'
22
+ version: '7.2'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: 6.0.0
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '7.1'
32
+ version: '7.2'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activesupport
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: 6.0.0
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '7.1'
42
+ version: '7.2'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,7 +49,7 @@ dependencies:
49
49
  version: 6.0.0
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '7.1'
52
+ version: '7.2'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: view_component
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +94,7 @@ files:
94
94
  - CHANGELOG.md
95
95
  - LICENSE.txt
96
96
  - README.md
97
+ - app/components/concerns/view_component/form/element_proc.rb
97
98
  - app/components/view_component/form/base_component.rb
98
99
  - app/components/view_component/form/button_component.rb
99
100
  - app/components/view_component/form/check_box_component.rb
@@ -167,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
167
168
  - !ruby/object:Gem::Version
168
169
  version: '0'
169
170
  requirements: []
170
- rubygems_version: 3.3.26
171
+ rubygems_version: 3.4.10
171
172
  signing_key:
172
173
  specification_version: 4
173
174
  summary: Rails FormBuilder for ViewComponent