vcfb 1.0.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.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +9 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.md +89 -0
  5. data/Rakefile +3 -0
  6. data/lib/generators/vcfb/components/USAGE.md +74 -0
  7. data/lib/generators/vcfb/components/components_generator.rb +172 -0
  8. data/lib/generators/vcfb/components/templates/button/component.html.erb +3 -0
  9. data/lib/generators/vcfb/components/templates/button/component.rb.tt +17 -0
  10. data/lib/generators/vcfb/components/templates/check_box/component.html.erb +1 -0
  11. data/lib/generators/vcfb/components/templates/check_box/component.rb.tt +19 -0
  12. data/lib/generators/vcfb/components/templates/collection_check_boxes/check_box/component.html.erb +1 -0
  13. data/lib/generators/vcfb/components/templates/collection_check_boxes/check_box/component.rb.tt +21 -0
  14. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.html.erb +3 -0
  15. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.rb.tt +29 -0
  16. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.html.erb +3 -0
  17. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.rb.tt +21 -0
  18. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.html.erb +3 -0
  19. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.rb.tt +29 -0
  20. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.html.erb +3 -0
  21. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.rb.tt +21 -0
  22. data/lib/generators/vcfb/components/templates/collection_radio_buttons/radio_button/component.html.erb +1 -0
  23. data/lib/generators/vcfb/components/templates/collection_radio_buttons/radio_button/component.rb.tt +20 -0
  24. data/lib/generators/vcfb/components/templates/collection_select/component.html.erb +1 -0
  25. data/lib/generators/vcfb/components/templates/collection_select/component.rb.tt +21 -0
  26. data/lib/generators/vcfb/components/templates/color_field/component.html.erb +1 -0
  27. data/lib/generators/vcfb/components/templates/color_field/component.rb.tt +17 -0
  28. data/lib/generators/vcfb/components/templates/date_field/component.html.erb +1 -0
  29. data/lib/generators/vcfb/components/templates/date_field/component.rb.tt +17 -0
  30. data/lib/generators/vcfb/components/templates/date_select/component.html.erb +1 -0
  31. data/lib/generators/vcfb/components/templates/date_select/component.rb.tt +18 -0
  32. data/lib/generators/vcfb/components/templates/datetime_field/component.html.erb +1 -0
  33. data/lib/generators/vcfb/components/templates/datetime_field/component.rb.tt +17 -0
  34. data/lib/generators/vcfb/components/templates/datetime_select/component.html.erb +1 -0
  35. data/lib/generators/vcfb/components/templates/datetime_select/component.rb.tt +18 -0
  36. data/lib/generators/vcfb/components/templates/email_field/component.html.erb +1 -0
  37. data/lib/generators/vcfb/components/templates/email_field/component.rb.tt +17 -0
  38. data/lib/generators/vcfb/components/templates/file_field/component.html.erb +1 -0
  39. data/lib/generators/vcfb/components/templates/file_field/component.rb.tt +17 -0
  40. data/lib/generators/vcfb/components/templates/grouped_collection_select/component.html.erb +1 -0
  41. data/lib/generators/vcfb/components/templates/grouped_collection_select/component.rb.tt +23 -0
  42. data/lib/generators/vcfb/components/templates/label/component.html.erb +3 -0
  43. data/lib/generators/vcfb/components/templates/label/component.rb.tt +19 -0
  44. data/lib/generators/vcfb/components/templates/month_field/component.html.erb +1 -0
  45. data/lib/generators/vcfb/components/templates/month_field/component.rb.tt +17 -0
  46. data/lib/generators/vcfb/components/templates/number_field/component.html.erb +1 -0
  47. data/lib/generators/vcfb/components/templates/number_field/component.rb.tt +17 -0
  48. data/lib/generators/vcfb/components/templates/password_field/component.html.erb +1 -0
  49. data/lib/generators/vcfb/components/templates/password_field/component.rb.tt +17 -0
  50. data/lib/generators/vcfb/components/templates/radio_button/component.html.erb +1 -0
  51. data/lib/generators/vcfb/components/templates/radio_button/component.rb.tt +18 -0
  52. data/lib/generators/vcfb/components/templates/range_field/component.html.erb +1 -0
  53. data/lib/generators/vcfb/components/templates/range_field/component.rb.tt +17 -0
  54. data/lib/generators/vcfb/components/templates/rich_text_area/component.html.erb +1 -0
  55. data/lib/generators/vcfb/components/templates/rich_text_area/component.rb.tt +17 -0
  56. data/lib/generators/vcfb/components/templates/search_field/component.html.erb +1 -0
  57. data/lib/generators/vcfb/components/templates/search_field/component.rb.tt +17 -0
  58. data/lib/generators/vcfb/components/templates/select/component.html.erb +1 -0
  59. data/lib/generators/vcfb/components/templates/select/component.rb.tt +23 -0
  60. data/lib/generators/vcfb/components/templates/submit/component.html.erb +1 -0
  61. data/lib/generators/vcfb/components/templates/submit/component.rb.tt +17 -0
  62. data/lib/generators/vcfb/components/templates/telephone_field/component.html.erb +1 -0
  63. data/lib/generators/vcfb/components/templates/telephone_field/component.rb.tt +17 -0
  64. data/lib/generators/vcfb/components/templates/text_area/component.html.erb +1 -0
  65. data/lib/generators/vcfb/components/templates/text_area/component.rb.tt +17 -0
  66. data/lib/generators/vcfb/components/templates/text_field/component.html.erb +1 -0
  67. data/lib/generators/vcfb/components/templates/text_field/component.rb.tt +17 -0
  68. data/lib/generators/vcfb/components/templates/time_field/component.html.erb +1 -0
  69. data/lib/generators/vcfb/components/templates/time_field/component.rb.tt +17 -0
  70. data/lib/generators/vcfb/components/templates/time_select/component.html.erb +1 -0
  71. data/lib/generators/vcfb/components/templates/time_select/component.rb.tt +18 -0
  72. data/lib/generators/vcfb/components/templates/time_zone_select/component.html.erb +1 -0
  73. data/lib/generators/vcfb/components/templates/time_zone_select/component.rb.tt +19 -0
  74. data/lib/generators/vcfb/components/templates/url_field/component.html.erb +1 -0
  75. data/lib/generators/vcfb/components/templates/url_field/component.rb.tt +17 -0
  76. data/lib/generators/vcfb/components/templates/week_field/component.html.erb +1 -0
  77. data/lib/generators/vcfb/components/templates/week_field/component.rb.tt +17 -0
  78. data/lib/generators/vcfb/components/templates/weekday_select/component.html.erb +1 -0
  79. data/lib/generators/vcfb/components/templates/weekday_select/component.rb.tt +18 -0
  80. data/lib/vcfb/action_view_tag_patch.rb +9 -0
  81. data/lib/vcfb/acts_as_form_collection_component.rb +19 -0
  82. data/lib/vcfb/acts_as_form_component.rb +22 -0
  83. data/lib/vcfb/acts_as_form_label_component.rb +21 -0
  84. data/lib/vcfb/form_builder.rb +188 -0
  85. data/lib/vcfb/railtie.rb +6 -0
  86. data/lib/vcfb/resolver.rb +18 -0
  87. data/lib/vcfb/tags/collection_check_boxes.rb +26 -0
  88. data/lib/vcfb/tags/collection_helpers.rb +19 -0
  89. data/lib/vcfb/tags/collection_radio_buttons.rb +25 -0
  90. data/lib/vcfb/template.rb +44 -0
  91. data/lib/vcfb/version.rb +3 -0
  92. data/lib/vcfb.rb +12 -0
  93. metadata +247 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d279e150ad43b12161abe30108b84e3e4dc37f03b9fb2ee39245875e671e573
4
+ data.tar.gz: ba88556e3028d56d89d3359aaf006163fab1ae4f1665cd3e094b97175258918b
5
+ SHA512:
6
+ metadata.gz: d0cc8de0c202e26745ec4442b8006681749717580c136769e9789ec308fc1efb76ca2f158fadba091ebf43a990f3532ae3bee6679c795c6da0f1c7f0dfb96dc7
7
+ data.tar.gz: 97a1b2840265b7b6fd773fa46e9bd45a77f929f5d25d157f1f92a4540bb98afe5013db3f3ec844b198c8b6382841926dc0872bd4cb0a9825a67219c3731eee14
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # CHANGELOG
2
+
3
+ ## Main
4
+
5
+ -
6
+
7
+ ## 1.0.0
8
+
9
+ - Initial release
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2022 Alex Monroe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # VCFB
2
+
3
+ > FormBuilder for Rails using ViewComponent
4
+
5
+ VCFB provides a `FormBuilder` for use with
6
+ [ViewComponent](https://viewcomponent.org/). It was inspired by
7
+ [ViewComponent::Form](https://github.com/pantographe/view_component-form), but
8
+ with the goal to make it easy to apply styling and other formatting within a
9
+ component's `.html.erb` file (rather than in Ruby code).
10
+
11
+ 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
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem "vcfb"
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```sh
26
+ bundle install
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Generate a set components to use with VCFB::FormBuilder
32
+
33
+ ```sh
34
+ rails generate vcfb:components
35
+ ```
36
+
37
+ 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`.
40
+
41
+ To generate components in a different namespace, use the `--namespace` option
42
+
43
+ ```sh
44
+ rails generate vcfb:components --namespace inline_form
45
+ ```
46
+
47
+ This will generate all the components under `module InlineForm`. To make use of
48
+ these namespaced components, create a custom `FormBuilder` in your application
49
+ inheriting from `VCFB::FormBuilder`.
50
+
51
+ ```ruby
52
+ class InlineFormBuilder < VCFB::FormBuilder
53
+ self.namespace = "inline_form"
54
+ end
55
+ ```
56
+
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`.
59
+
60
+ ```ruby
61
+ <%= form_with model: @author, builder: VCFB::FormBuilder do |form| %>
62
+ <%= form.label :name %>
63
+ <%= form.text_field :name %>
64
+ <% end %>
65
+ ```
66
+
67
+ ## Development
68
+
69
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
70
+ `bin/rspec` to run the tests. You can also run:
71
+
72
+ - `bin/console` for an interactive prompt that will allow you to experiment
73
+ - `bin/rubocop` to run RuboCop to check the code style and formatting
74
+
75
+ To install this gem onto your local machine, run `bundle exec rake install`. To
76
+ release a new version, update the version number in `version.rb`, and then run
77
+ `bundle exec rake release`, which will create a git tag for the version, push
78
+ git commits and the created tag, and push the `.gem` file to
79
+ [rubygems.org](https://rubygems.org).
80
+
81
+ ## Contributing
82
+
83
+ Bug reports and pull requests are welcome on GitHub at
84
+ https://github.com/wamonroe/vcfb.
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT
89
+ License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
@@ -0,0 +1,74 @@
1
+ Description:
2
+ Creates a set of form components for use with VCFB::FormBuilder. You can
3
+ optionally pass a namespace (defaults to "form") that the components will be
4
+ generated under.
5
+
6
+ Examples:
7
+ `rails generate vcfb:components [--namespace NAMESPACE]`
8
+
9
+ Creates the following ViewComponents:
10
+
11
+ app/components/form/button/component.html.erb
12
+ app/components/form/button/component.rb
13
+ app/components/form/check_box/component.html.erb
14
+ app/components/form/check_box/component.rb
15
+ app/components/form/collection_check_boxes/component.html.erb
16
+ app/components/form/collection_check_boxes/component.rb
17
+ app/components/form/collection_radio_buttons/component.html.erb
18
+ app/components/form/collection_radio_buttons/component.rb
19
+ app/components/form/collection_select/component.html.erb
20
+ app/components/form/collection_select/component.rb
21
+ app/components/form/color_field/component.html.erb
22
+ app/components/form/color_field/component.rb
23
+ app/components/form/date_field/component.html.erb
24
+ app/components/form/date_field/component.rb
25
+ app/components/form/date_select/component.html.erb
26
+ app/components/form/date_select/component.rb
27
+ app/components/form/datetime_field/component.html.erb
28
+ app/components/form/datetime_field/component.rb
29
+ app/components/form/datetime_select/component.html.erb
30
+ app/components/form/datetime_select/component.rb
31
+ app/components/form/email_field/component.html.erb
32
+ app/components/form/email_field/component.rb
33
+ app/components/form/file_field/component.html.erb
34
+ app/components/form/file_field/component.rb
35
+ app/components/form/grouped_collection_select/component.html.erb
36
+ app/components/form/grouped_collection_select/component.rb
37
+ app/components/form/label/component.html.erb
38
+ app/components/form/label/component.rb
39
+ app/components/form/month_field/component.html.erb
40
+ app/components/form/month_field/component.rb
41
+ app/components/form/number_field/component.html.erb
42
+ app/components/form/number_field/component.rb
43
+ app/components/form/password_field/component.html.erb
44
+ app/components/form/password_field/component.rb
45
+ app/components/form/radio_button/component.html.erb
46
+ app/components/form/radio_button/component.rb
47
+ app/components/form/range_field/component.html.erb
48
+ app/components/form/range_field/component.rb
49
+ app/components/form/rich_text_area/component.html.erb
50
+ app/components/form/rich_text_area/component.rb
51
+ app/components/form/search_field/component.html.erb
52
+ app/components/form/search_field/component.rb
53
+ app/components/form/select/component.html.erb
54
+ app/components/form/select/component.rb
55
+ app/components/form/submit/component.html.erb
56
+ app/components/form/submit/component.rb
57
+ app/components/form/telephone_field/component.html.erb
58
+ app/components/form/telephone_field/component.rb
59
+ app/components/form/text_area/component.html.erb
60
+ app/components/form/text_area/component.rb
61
+ app/components/form/text_field/component.html.erb
62
+ app/components/form/text_field/component.rb
63
+ app/components/form/time_field/component.html.erb
64
+ app/components/form/time_field/component.rb
65
+ app/components/form/time_select/component.html.erb
66
+ app/components/form/time_select/component.rb
67
+ app/components/form/time_zone_select/component.html.erb
68
+ app/components/form/time_zone_select/component.rb
69
+ app/components/form/url_field/component.html.erb
70
+ app/components/form/url_field/component.rb
71
+ app/components/form/week_field/component.html.erb
72
+ app/components/form/week_field/component.rb
73
+ app/components/form/weekday_select/component.html.erb
74
+ app/components/form/weekday_select/component.rb"
@@ -0,0 +1,172 @@
1
+ require "active_support/core_ext/string/inflections"
2
+ require "rails/generators/base"
3
+
4
+ module Vcfb
5
+ class ComponentsGenerator < ::Rails::Generators::Base
6
+ source_root File.expand_path("templates", __dir__)
7
+
8
+ class_option :namespace, type: :string, default: "form"
9
+
10
+ def create_button_component
11
+ directory "button", "#{destination}/button"
12
+ end
13
+
14
+ def create_check_box_component
15
+ directory "check_box", "#{destination}/check_box"
16
+ end
17
+
18
+ def create_collection_check_boxes_component
19
+ directory "collection_check_boxes", "#{destination}/collection_check_boxes"
20
+ end
21
+
22
+ def create_collection_radio_buttons_component
23
+ directory "collection_radio_buttons", "#{destination}/collection_radio_buttons"
24
+ end
25
+
26
+ def create_collection_select_component
27
+ directory "collection_select", "#{destination}/collection_select"
28
+ end
29
+
30
+ def create_color_field_component
31
+ directory "color_field", "#{destination}/color_field"
32
+ end
33
+
34
+ def create_date_field_component
35
+ directory "date_field", "#{destination}/date_field"
36
+ end
37
+
38
+ def create_date_select_component
39
+ directory "date_select", "#{destination}/date_select"
40
+ end
41
+
42
+ def create_datetime_field_component
43
+ directory "datetime_field", "#{destination}/datetime_field"
44
+ end
45
+
46
+ def create_datetime_select_component
47
+ directory "datetime_select", "#{destination}/datetime_select"
48
+ end
49
+
50
+ def create_email_field_component
51
+ directory "email_field", "#{destination}/email_field"
52
+ end
53
+
54
+ def create_file_field_component
55
+ directory "file_field", "#{destination}/file_field"
56
+ end
57
+
58
+ def create_grouped_collection_select_component
59
+ directory "grouped_collection_select", "#{destination}/grouped_collection_select"
60
+ end
61
+
62
+ def create_label_component
63
+ directory "label", "#{destination}/label"
64
+ end
65
+
66
+ def create_month_field_component
67
+ directory "month_field", "#{destination}/month_field"
68
+ end
69
+
70
+ def create_number_field_component
71
+ directory "number_field", "#{destination}/number_field"
72
+ end
73
+
74
+ def create_password_field_component
75
+ directory "password_field", "#{destination}/password_field"
76
+ end
77
+
78
+ def create_radio_button_component
79
+ directory "radio_button", "#{destination}/radio_button"
80
+ end
81
+
82
+ def create_range_field_component
83
+ directory "range_field", "#{destination}/range_field"
84
+ end
85
+
86
+ def create_rich_text_area_component
87
+ directory "rich_text_area", "#{destination}/rich_text_area"
88
+ end
89
+
90
+ def create_search_field_component
91
+ directory "search_field", "#{destination}/search_field"
92
+ end
93
+
94
+ def create_select_component
95
+ directory "select", "#{destination}/select"
96
+ end
97
+
98
+ def create_submit_component
99
+ directory "submit", "#{destination}/submit"
100
+ end
101
+
102
+ def create_telephone_field_component
103
+ directory "telephone_field", "#{destination}/telephone_field"
104
+ end
105
+
106
+ def create_text_area_component
107
+ directory "text_area", "#{destination}/text_area"
108
+ end
109
+
110
+ def create_text_field_component
111
+ directory "text_field", "#{destination}/text_field"
112
+ end
113
+
114
+ def create_time_field_component
115
+ directory "time_field", "#{destination}/time_field"
116
+ end
117
+
118
+ def create_time_select_component
119
+ directory "time_select", "#{destination}/time_select"
120
+ end
121
+
122
+ def create_time_zone_select_component
123
+ directory "time_zone_select", "#{destination}/time_zone_select"
124
+ end
125
+
126
+ def create_url_field_component
127
+ directory "url_field", "#{destination}/url_field"
128
+ end
129
+
130
+ def create_week_field_component
131
+ directory "week_field", "#{destination}/week_field"
132
+ end
133
+
134
+ if Gem::Version.new(Rails::VERSION::STRING) >= Gem::Version.new("7.0")
135
+ def create_weekday_select_component
136
+ directory "weekday_select", "#{destination}/weekday_select"
137
+ end
138
+ end
139
+
140
+ private
141
+
142
+ def destination
143
+ if options[:skip_namespace]
144
+ "app/components"
145
+ else
146
+ "app/components/#{options[:namespace]}"
147
+ end
148
+ end
149
+
150
+ def module_namespacing(&block)
151
+ content = capture(&block)
152
+ content = wrap_with_namespace(content) unless options[:skip_namespace]
153
+ concat(content)
154
+ end
155
+
156
+ def wrap_with_namespace(content)
157
+ result = ""
158
+ indent = 0
159
+ namespace_parts = options[:namespace].split("/")
160
+ namespace_parts.each do |module_name|
161
+ result += indent("module #{module_name.camelize}\n", indent)
162
+ indent += 2
163
+ end
164
+ result += indent(content, indent)
165
+ namespace_parts.size.times do
166
+ indent -= 2
167
+ result += indent("end\n", indent)
168
+ end
169
+ result
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,3 @@
1
+ <%= form_element @options do %>
2
+ <%= content || @text %>
3
+ <% end %>
@@ -0,0 +1,17 @@
1
+ <% module_namespacing do -%>
2
+ module Button
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormComponent
5
+
6
+ def initialize(form, text = nil, options = {})
7
+ @form = form
8
+ @text = text
9
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
+ end
11
+
12
+ def form_element(options = {}, &block)
13
+ button_tag(options, &block)
14
+ end
15
+ end
16
+ end
17
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= form_element @options %>
@@ -0,0 +1,19 @@
1
+ <% module_namespacing do -%>
2
+ module CheckBox
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormComponent
5
+
6
+ def initialize(form, method, options = {}, checked_value = "1", unchecked_value = "0")
7
+ @form = form
8
+ @method = method
9
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
+ @checked_value = checked_value
11
+ @unchecked_value = unchecked_value
12
+ end
13
+
14
+ def form_element(options = {})
15
+ check_box(@form.object_name, @method, options, @checked_value, @unchecked_value)
16
+ end
17
+ end
18
+ end
19
+ <% end -%>
@@ -0,0 +1,21 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionCheckBoxes
3
+ module CheckBox
4
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
5
+ include VCFB::ActsAsFormComponent
6
+
7
+ def initialize(form, method, options = {}, checked_value = "1", unchecked_value = "0")
8
+ @form = form
9
+ @method = method
10
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
11
+ @checked_value = checked_value
12
+ @unchecked_value = unchecked_value
13
+ end
14
+
15
+ def form_element(options = {})
16
+ check_box(@form.object_name, @method, options, @checked_value, @unchecked_value)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <%= form_element @options, @html_options do |builder| %>
2
+ <%= content(builder) %>
3
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionCheckBoxes
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormCollectionComponent
5
+
6
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
7
+ @form = form
8
+ @method = method
9
+ @collection = collection
10
+ @value_method = value_method
11
+ @text_method = text_method
12
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
13
+ @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
14
+ end
15
+
16
+ def form_element(options = {}, html_options = {}, &block)
17
+ collection_check_boxes(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
18
+ block&.call(builder)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def default_content(builder)
25
+ builder.check_box + builder.label
26
+ end
27
+ end
28
+ end
29
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <%= form_element @options do %>
2
+ <%= content.presence || @text %>
3
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionCheckBoxes
3
+ module Label
4
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
5
+ include VCFB::ActsAsFormLabelComponent
6
+
7
+ def initialize(form, method, text = nil, options = {})
8
+ @form = form
9
+ @method = method
10
+ @text = text
11
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
12
+ end
13
+
14
+ def form_element(options = {}, &block)
15
+ @text = capture(&block) if block
16
+ label(@form.object_name, @method, @text, options)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <%= form_element @options, @html_options do |builder| %>
2
+ <%= content(builder) %>
3
+ <% end %>
@@ -0,0 +1,29 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionRadioButtons
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormCollectionComponent
5
+
6
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
7
+ @form = form
8
+ @method = method
9
+ @collection = collection
10
+ @value_method = value_method
11
+ @text_method = text_method
12
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
13
+ @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
14
+ end
15
+
16
+ def form_element(options = {}, html_options = {}, &block)
17
+ collection_radio_buttons(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
18
+ block&.call(builder)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def default_content(builder)
25
+ builder.radio_button + builder.label
26
+ end
27
+ end
28
+ end
29
+ <% end -%>
@@ -0,0 +1,3 @@
1
+ <%= form_element @options do %>
2
+ <%= content.presence || @text %>
3
+ <% end %>
@@ -0,0 +1,21 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionRadioButtons
3
+ module Label
4
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
5
+ include VCFB::ActsAsFormLabelComponent
6
+
7
+ def initialize(form, method, text = nil, options = {})
8
+ @form = form
9
+ @method = method
10
+ @text = text
11
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
12
+ end
13
+
14
+ def form_element(options = {}, &block)
15
+ @text = capture(&block) if block
16
+ label(@form.object_name, @method, @text, options)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ <% end -%>
@@ -0,0 +1,20 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionRadioButtons
3
+ module RadioButton
4
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
5
+ include VCFB::ActsAsFormComponent
6
+
7
+ def initialize(form, method, value, options = {})
8
+ @form = form
9
+ @method = method
10
+ @value = value
11
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
12
+ end
13
+
14
+ def form_element(options = {})
15
+ radio_button(@form.object_name, @method, @value, options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= form_element @options, @html_options %>
@@ -0,0 +1,21 @@
1
+ <% module_namespacing do -%>
2
+ module CollectionSelect
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormCollectionComponent
5
+
6
+ def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
7
+ @form = form
8
+ @method = method
9
+ @collection = collection
10
+ @value_method = value_method
11
+ @text_method = text_method
12
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
13
+ @html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
14
+ end
15
+
16
+ def form_element(options = {}, html_options = {})
17
+ collection_select(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options)
18
+ end
19
+ end
20
+ end
21
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= form_element @options %>
@@ -0,0 +1,17 @@
1
+ <% module_namespacing do -%>
2
+ module ColorField
3
+ class Component < <%= defined?(ApplicationComponent) ? "ApplicationComponent" : "ViewComponent::Base" %>
4
+ include VCFB::ActsAsFormComponent
5
+
6
+ def initialize(form, method, options = {})
7
+ @form = form
8
+ @method = method
9
+ @options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
10
+ end
11
+
12
+ def form_element(options = {})
13
+ color_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ <% end -%>
@@ -0,0 +1 @@
1
+ <%= form_element @options %>