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 +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +78 -11
- data/lib/vcfb/component/base.rb +13 -0
- data/lib/vcfb/component/base_collection.rb +2 -0
- data/lib/vcfb/component/form.rb +2 -1
- data/lib/vcfb/form_builder.rb +7 -5
- data/lib/vcfb/version.rb +1 -1
- metadata +12 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd3eb37042a40675e814d4e61c8e0bcf936fccb3c6cd369a414a10673c18a078
|
4
|
+
data.tar.gz: dd354e2c1d69a1741be37082fd0ef42493682aef40359585a81cdded912a844f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05e18ffca6448e16faf4f1095ac3a0e37cc4debabafd722a9ef23c842e9003a16db65c62ca15ac2d15817a038d72ff250df860b03af13711717ff95f7192ccb6
|
7
|
+
data.tar.gz: 3eef3ba08063ef5727532272275fd0f4388e571def0d284349f25e1d08ca03ed22099ed12e70e52a73c0c4246dfbaab702676e5b3c07758ddd431a8dad728852
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# VCFB
|
2
2
|
|
3
|
+
[](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,
|
13
|
-
|
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
|
-
##
|
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
|
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,
|
58
|
-
|
73
|
+
To render forms using the generated components, use the included
|
74
|
+
`component_form_with` helper.
|
59
75
|
|
60
|
-
```
|
61
|
-
<%=
|
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
|
-
|
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
|
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
|
data/lib/vcfb/component/base.rb
CHANGED
@@ -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
|
data/lib/vcfb/component/form.rb
CHANGED
@@ -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
|
data/lib/vcfb/form_builder.rb
CHANGED
@@ -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
|
-
|
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
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
|
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:
|
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: '
|
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: '
|
52
|
+
version: '4.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
|
-
name:
|
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: '
|
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: '
|
66
|
+
version: '0'
|
123
67
|
description: FormBuilder for Rails using ViewComponent
|
124
68
|
email:
|
125
|
-
- alex
|
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:
|
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.
|
226
|
+
rubygems_version: 3.4.6
|
283
227
|
signing_key:
|
284
228
|
specification_version: 4
|
285
229
|
summary: FormBuilder for Rails using ViewComponent
|