vcfb 2.0.1 → 2.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fbb45046003eb60f818dab6f8f6840fd2db12448638b6e0bbf037febe7eb1181
4
- data.tar.gz: 848611876927e81bb4a7d6aa83e56e4748c65b400e8883a34b97abfc8b994a9c
3
+ metadata.gz: fd3eb37042a40675e814d4e61c8e0bcf936fccb3c6cd369a414a10673c18a078
4
+ data.tar.gz: dd354e2c1d69a1741be37082fd0ef42493682aef40359585a81cdded912a844f
5
5
  SHA512:
6
- metadata.gz: 67b3d105c6dd5f46531bd9662fb0d90b1a7ccaca8d861cb617d1fbb8999eb9a4772a9aa113fa6f1bf6733f6697e1a468247cbab55a113f5de14914e6cc5be079
7
- data.tar.gz: c38374b0aa001bbfb897b0587eded3bd085b33f404ca415775f206ef37bd8b0fdc33367bad3c8851754d34bce28f6593a524a13b0a37503237ec58f5c0d2f138
6
+ metadata.gz: 05e18ffca6448e16faf4f1095ac3a0e37cc4debabafd722a9ef23c842e9003a16db65c62ca15ac2d15817a038d72ff250df860b03af13711717ff95f7192ccb6
7
+ data.tar.gz: 3eef3ba08063ef5727532272275fd0f4388e571def0d284349f25e1d08ca03ed22099ed12e70e52a73c0c4246dfbaab702676e5b3c07758ddd431a8dad728852
data/CHANGELOG.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  -
6
6
 
7
+ ## 2.1.0
8
+
9
+ - Removed support for Ruby 2.7.
10
+
11
+ ## 2.0.2
12
+
13
+ - Support for ViewComponent 2.61.0.
14
+
7
15
  ## 2.0.1
8
16
 
9
17
  - Restore usage of tag options gem if present.
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # VCFB
2
2
 
3
+ [![Test](https://github.com/wamonroe/vcfb/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/wamonroe/vcfb/actions/workflows/test.yml)
4
+
3
5
  > FormBuilder for Rails using ViewComponent
4
6
 
5
7
  VCFB provides a `FormBuilder` for use with
@@ -9,8 +11,16 @@ with the goal to make it easy to apply styling and other formatting within a
9
11
  component's `.html.erb` file (rather than in Ruby code).
10
12
 
11
13
  To further support this goal, if the application includes the
12
- [TagOptions](https://github.com/wamonroe/tag_options) gem, the `vcfb:components`
13
- will make use of it when saving `options` and `html_options` hashes.
14
+ [TagOptions](https://github.com/wamonroe/tag_options) gem, `VCFB` will make use
15
+ of it when initializing `@options` and `@html_options` hashes.
16
+
17
+ ## Table of Contents
18
+
19
+ - [Installation](#installation)
20
+ - [Getting Started](#getting-started)
21
+ - [Settings](#settings)
22
+ - [Styling Components with TagOptions](#styling-components-with-tagoptions)
23
+ - [Development](#development)
14
24
 
15
25
  ## Installation
16
26
 
@@ -26,7 +36,7 @@ And then execute:
26
36
  bundle install
27
37
  ```
28
38
 
29
- ## Usage
39
+ ## Getting Started
30
40
 
31
41
  Generate a set components to use with VCFB::FormBuilder
32
42
 
@@ -35,8 +45,14 @@ rails generate vcfb:components
35
45
  ```
36
46
 
37
47
  The generator will install view components for ALL of the form elements
38
- supported by the version of Rails installed. By default, all of the components
39
- will be namespaced in `module Form`.
48
+ supported by the version of Rails installed, including a component to generate
49
+ the form itself. By default, all of the components will be namespaced in `module Form`.
50
+
51
+ `VCFB::FormBuilder` with its default set of components renders form elements
52
+ functionaly identical to the the built-in Rails tag helpers. If, however, you
53
+ don't need or want to render certain form elements using a component it is safe
54
+ to delete the unused ones. `VCFB::FormBuilder` will fall back to rendering using
55
+ the built-in Rails tag helpers if a component for that element doesn't exist.
40
56
 
41
57
  To generate components in a different namespace, use the `--namespace` option
42
58
 
@@ -54,17 +70,29 @@ class InlineFormBuilder < VCFB::FormBuilder
54
70
  end
55
71
  ```
56
72
 
57
- To render forms using the generated components, sepecify `VCFB::FormBuilder` or
58
- a class that inherits from it when using `form_with` or `form_for`.
73
+ To render forms using the generated components, use the included
74
+ `component_form_with` helper.
59
75
 
60
- ```ruby
61
- <%= form_with model: @author, builder: VCFB::FormBuilder do |form| %>
76
+ ```erb
77
+ <%= component_form_with model: @author do |form| %>
62
78
  <%= form.label :name %>
63
79
  <%= form.text_field :name %>
64
80
  <% end %>
65
81
  ```
66
82
 
67
- Generated components support `before_initialize`, `after_initialization`, and `around_initialize` callbacks to minimize the need to override the initlialize methods.
83
+ If using a custom form builder inheriting from `VCFB::FormBuilder`, pass the
84
+ `:builder` option to `component_form_with`.
85
+
86
+ ```erb
87
+ <%= component_form_with model: @author, builder: InlineFormBuilder do |form| %>
88
+ <%= form.label :name %>
89
+ <%= form.text_field :name %>
90
+ <% end %>
91
+ ```
92
+
93
+ Generated components support `before_initialize`, `after_initialization`, and
94
+ `around_initialize` callbacks to minimize the need to override the initlialize
95
+ methods.
68
96
 
69
97
  ```ruby
70
98
  module Form
@@ -80,6 +108,8 @@ module Form
80
108
  end
81
109
  ```
82
110
 
111
+ ## Settings
112
+
83
113
  By default, components will inherit from `ApplicationComponent` if it exists or
84
114
  `ViewComponent::Base` if it does not. If you wish to change this behavior,
85
115
  generate an initializer and specify the `parent_component`.
@@ -94,6 +124,43 @@ VCFB.configure do |config|
94
124
  end
95
125
  ```
96
126
 
127
+ ## Styling Components with TagOptions
128
+
129
+ > The examples below use `TagOptions::Hash` to make it easy to manipulate
130
+ > options passed to generate the form elements. See
131
+ > [TagOptions](https://github.com/wamonroe/tag_options) for more information
132
+ > about the options available.
133
+
134
+ For form elements, `VCFB` provides a `form_element` helper that will render
135
+ the field, select, button, etc.
136
+
137
+ The `button`, `check_box`, `label`, `radio_buton`, `rich_text_area`, `submit`,
138
+ `text_area` and all the `*_field` elements are styled using only an `@options`
139
+ hash.
140
+
141
+ ```erb
142
+ <%# app/components/form/text_field/component.html.erb %>
143
+ <%= form_element @options.at(:class).combine!("shadow-sm block border-gray-300 rounded-md") %>
144
+ ```
145
+
146
+ The `collection_check_boxes`, `collection_radio_buttons`, `select`, and all of
147
+ the `*_select` elements have an `@options`, but are styled with an
148
+ `@html_options` hash.
149
+
150
+ ```erb
151
+ <%# app/components/form/select/component.html.erb %>
152
+ <%= form_element @options, @html_options.at(:class).combine!("shadow-sm block border-gray-300 rounded-md") %>
153
+ ```
154
+
155
+ The main form element is rendered with a `form_tag` helper and is styled with an `@options` hash.
156
+
157
+ ```erb
158
+ <%# app/components/form/component.html.erb %>
159
+ <%= form_tag @options.at(:class).combine!("mt-8 space-y-6") do |form| %>
160
+ <%= content %>
161
+ <% end %>
162
+ ```
163
+
97
164
  ## Development
98
165
 
99
166
  After checking out the repo, run `bin/setup` to install dependencies. Then, run
@@ -102,7 +169,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
102
169
  - `bin/console` for an interactive prompt that will allow you to experiment
103
170
  - `bin/rubocop` to run RuboCop to check the code style and formatting
104
171
 
105
- To install this gem onto your local machine, run `bundle exec rake install`. To
172
+ To build this gem on your local machine, run `bundle exec rake build`. To
106
173
  release a new version, update the version number in `version.rb`, and then run
107
174
  `bundle exec rake release`, which will create a git tag for the version, push
108
175
  git commits and the created tag, and push the `.gem` file to
@@ -22,6 +22,19 @@ module VCFB
22
22
  def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
23
23
  VCFB::Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
24
24
  end
25
+
26
+ private
27
+
28
+ def deobjectify_options!(options)
29
+ if instance_variable_defined?(:@form)
30
+ keys = @form.send(:objectify_options, {}).keys
31
+ options.extract!(*keys)
32
+ elsif defined?(TagOptions::Hash)
33
+ TagOptions::Hash.new
34
+ else
35
+ {}
36
+ end
37
+ end
25
38
  end
26
39
  end
27
40
  end
@@ -4,6 +4,8 @@ module VCFB
4
4
  private
5
5
 
6
6
  def content
7
+ return unless instance_variable_defined?(:@builder)
8
+
7
9
  @__vc_content = if @view_context && @__vc_render_in_block
8
10
  view_context.capture(@builder, &@__vc_render_in_block)
9
11
  else
@@ -8,7 +8,6 @@ module VCFB
8
8
  @url = url
9
9
  @format = format
10
10
  @options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
11
- @form = nil
12
11
  end
13
12
  end
14
13
 
@@ -30,6 +29,8 @@ module VCFB
30
29
  # Override #content and #get_slot from ViewComponent so that we can yield
31
30
  # the form element (and not the component).
32
31
  def content
32
+ return unless instance_variable_defined?(:@form)
33
+
33
34
  if @view_context && @__vc_render_in_block
34
35
  @__vc_content = view_context.capture(@form, &@__vc_render_in_block)
35
36
  end
@@ -2,6 +2,8 @@ module VCFB
2
2
  class FormBuilder < ::ActionView::Helpers::FormBuilder
3
3
  class_attribute :namespace, instance_writer: false, default: "form"
4
4
 
5
+ delegate :resolve_component_class, to: "self.class"
6
+
5
7
  attr_reader :object, :object_name, :template
6
8
  attr_accessor :form_component
7
9
 
@@ -13,7 +15,7 @@ module VCFB
13
15
  # FORM COMPONENT
14
16
 
15
17
  def self.form_component_class
16
- "#{namespace}/component".camelize.constantize
18
+ resolve_component_class
17
19
  end
18
20
 
19
21
  def self.form_component_defined?
@@ -22,6 +24,10 @@ module VCFB
22
24
  false
23
25
  end
24
26
 
27
+ def self.resolve_component_class(form_element = nil)
28
+ VCFB::Resolver.call(namespace, form_element)
29
+ end
30
+
25
31
  # SIMPLE FIELDS
26
32
 
27
33
  SIMPLE_FIELDS = %i[color_field date_field datetime_field email_field month_field number_field password_field
@@ -204,10 +210,6 @@ module VCFB
204
210
  end
205
211
  end
206
212
 
207
- def resolve_component_class(form_element)
208
- VCFB::Resolver.call(namespace, form_element)
209
- end
210
-
211
213
  # SUPPORT FORM COMPONENT SLOTS
212
214
 
213
215
  def method_missing(method_name, *args, **opts, &block)
data/lib/vcfb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VCFB
2
- VERSION = "2.0.1"
2
+ VERSION = "2.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vcfb
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Monroe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-05 00:00:00.000000000 Z
11
+ date: 2023-04-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,7 +39,7 @@ dependencies:
39
39
  version: '2.35'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
- version: '3.0'
42
+ version: '4.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -49,80 +49,24 @@ dependencies:
49
49
  version: '2.35'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
- version: '3.0'
52
+ version: '4.0'
53
53
  - !ruby/object:Gem::Dependency
54
- name: combustion
54
+ name: sqlite3
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - "~>"
58
- - !ruby/object:Gem::Version
59
- version: '1.3'
60
- type: :development
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - "~>"
65
- - !ruby/object:Gem::Version
66
- version: '1.3'
67
- - !ruby/object:Gem::Dependency
68
- name: rake
69
- requirement: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - "~>"
72
- - !ruby/object:Gem::Version
73
- version: '13.0'
74
- type: :development
75
- prerelease: false
76
- version_requirements: !ruby/object:Gem::Requirement
77
- requirements:
78
- - - "~>"
79
- - !ruby/object:Gem::Version
80
- version: '13.0'
81
- - !ruby/object:Gem::Dependency
82
- name: rspec-rails
83
- requirement: !ruby/object:Gem::Requirement
84
- requirements:
85
- - - "~>"
86
- - !ruby/object:Gem::Version
87
- version: '5.1'
88
- type: :development
89
- prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - "~>"
93
- - !ruby/object:Gem::Version
94
- version: '5.1'
95
- - !ruby/object:Gem::Dependency
96
- name: rubocop-rspec
97
- requirement: !ruby/object:Gem::Requirement
98
- requirements:
99
- - - "~>"
100
- - !ruby/object:Gem::Version
101
- version: '2.11'
102
- type: :development
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- requirements:
106
- - - "~>"
107
- - !ruby/object:Gem::Version
108
- version: '2.11'
109
- - !ruby/object:Gem::Dependency
110
- name: standard
111
- requirement: !ruby/object:Gem::Requirement
112
- requirements:
113
- - - "~>"
57
+ - - ">="
114
58
  - !ruby/object:Gem::Version
115
- version: '1.12'
59
+ version: '0'
116
60
  type: :development
117
61
  prerelease: false
118
62
  version_requirements: !ruby/object:Gem::Requirement
119
63
  requirements:
120
- - - "~>"
64
+ - - ">="
121
65
  - !ruby/object:Gem::Version
122
- version: '1.12'
66
+ version: '0'
123
67
  description: FormBuilder for Rails using ViewComponent
124
68
  email:
125
- - alex.monroe@cofense.com
69
+ - alex@monroepost.com
126
70
  executables: []
127
71
  extensions: []
128
72
  extra_rdoc_files: []
@@ -272,14 +216,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
272
216
  requirements:
273
217
  - - ">="
274
218
  - !ruby/object:Gem::Version
275
- version: 2.7.0
219
+ version: 3.0.0
276
220
  required_rubygems_version: !ruby/object:Gem::Requirement
277
221
  requirements:
278
222
  - - ">="
279
223
  - !ruby/object:Gem::Version
280
224
  version: '0'
281
225
  requirements: []
282
- rubygems_version: 3.3.7
226
+ rubygems_version: 3.4.6
283
227
  signing_key:
284
228
  specification_version: 4
285
229
  summary: FormBuilder for Rails using ViewComponent