vcfb 1.0.0 → 2.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 (101) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -0
  3. data/README.md +30 -0
  4. data/lib/generators/vcfb/components/components_generator.rb +5 -0
  5. data/lib/generators/vcfb/components/templates/button/component.html.erb +1 -1
  6. data/lib/generators/vcfb/components/templates/button/component.rb.tt +1 -12
  7. data/lib/generators/vcfb/components/templates/check_box/component.rb.tt +1 -14
  8. data/lib/generators/vcfb/components/templates/collection_check_boxes/check_box/component.rb.tt +1 -14
  9. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.html.erb +1 -1
  10. data/lib/generators/vcfb/components/templates/collection_check_boxes/component.rb.tt +1 -24
  11. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.html.erb +1 -1
  12. data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.rb.tt +1 -14
  13. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.html.erb +1 -1
  14. data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.rb.tt +1 -24
  15. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.html.erb +1 -1
  16. data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.rb.tt +1 -14
  17. data/lib/generators/vcfb/components/templates/collection_radio_buttons/radio_button/component.rb.tt +1 -13
  18. data/lib/generators/vcfb/components/templates/collection_select/component.rb.tt +1 -16
  19. data/lib/generators/vcfb/components/templates/color_field/component.rb.tt +1 -12
  20. data/lib/generators/vcfb/components/templates/component.html.erb +3 -0
  21. data/lib/generators/vcfb/components/templates/component.rb.tt +4 -0
  22. data/lib/generators/vcfb/components/templates/date_field/component.rb.tt +1 -12
  23. data/lib/generators/vcfb/components/templates/date_select/component.rb.tt +1 -13
  24. data/lib/generators/vcfb/components/templates/datetime_field/component.rb.tt +1 -12
  25. data/lib/generators/vcfb/components/templates/datetime_select/component.rb.tt +1 -13
  26. data/lib/generators/vcfb/components/templates/email_field/component.rb.tt +1 -12
  27. data/lib/generators/vcfb/components/templates/file_field/component.rb.tt +1 -12
  28. data/lib/generators/vcfb/components/templates/grouped_collection_select/component.rb.tt +1 -18
  29. data/lib/generators/vcfb/components/templates/label/component.html.erb +1 -1
  30. data/lib/generators/vcfb/components/templates/label/component.rb.tt +1 -14
  31. data/lib/generators/vcfb/components/templates/month_field/component.rb.tt +1 -12
  32. data/lib/generators/vcfb/components/templates/number_field/component.rb.tt +1 -12
  33. data/lib/generators/vcfb/components/templates/password_field/component.rb.tt +1 -12
  34. data/lib/generators/vcfb/components/templates/radio_button/component.rb.tt +1 -13
  35. data/lib/generators/vcfb/components/templates/range_field/component.rb.tt +1 -12
  36. data/lib/generators/vcfb/components/templates/rich_text_area/component.rb.tt +1 -12
  37. data/lib/generators/vcfb/components/templates/search_field/component.rb.tt +1 -12
  38. data/lib/generators/vcfb/components/templates/select/component.rb.tt +1 -18
  39. data/lib/generators/vcfb/components/templates/submit/component.rb.tt +1 -12
  40. data/lib/generators/vcfb/components/templates/telephone_field/component.rb.tt +1 -12
  41. data/lib/generators/vcfb/components/templates/text_area/component.rb.tt +1 -12
  42. data/lib/generators/vcfb/components/templates/text_field/component.rb.tt +1 -12
  43. data/lib/generators/vcfb/components/templates/time_field/component.rb.tt +1 -12
  44. data/lib/generators/vcfb/components/templates/time_select/component.rb.tt +1 -13
  45. data/lib/generators/vcfb/components/templates/time_zone_select/component.rb.tt +1 -14
  46. data/lib/generators/vcfb/components/templates/url_field/component.rb.tt +1 -12
  47. data/lib/generators/vcfb/components/templates/week_field/component.rb.tt +1 -12
  48. data/lib/generators/vcfb/components/templates/weekday_select/component.rb.tt +1 -13
  49. data/lib/generators/vcfb/initializer/initializer_generator.rb +12 -0
  50. data/lib/generators/vcfb/initializer/template/vcfb.rb.tt +3 -0
  51. data/lib/vcfb/component/base.rb +27 -0
  52. data/lib/vcfb/component/base_collection.rb +16 -0
  53. data/lib/vcfb/component/button.rb +17 -0
  54. data/lib/vcfb/component/check_box.rb +19 -0
  55. data/lib/vcfb/component/collection_check_boxes.rb +36 -0
  56. data/lib/vcfb/component/collection_radio_buttons.rb +36 -0
  57. data/lib/vcfb/component/collection_select.rb +21 -0
  58. data/lib/vcfb/component/color_field.rb +17 -0
  59. data/lib/vcfb/component/date_field.rb +17 -0
  60. data/lib/vcfb/component/date_select.rb +18 -0
  61. data/lib/vcfb/component/datetime_field.rb +17 -0
  62. data/lib/vcfb/component/datetime_select.rb +18 -0
  63. data/lib/vcfb/component/email_field.rb +17 -0
  64. data/lib/vcfb/component/file_field.rb +17 -0
  65. data/lib/vcfb/component/form.rb +40 -0
  66. data/lib/vcfb/component/grouped_collection_select.rb +23 -0
  67. data/lib/vcfb/component/label.rb +28 -0
  68. data/lib/vcfb/component/month_field.rb +17 -0
  69. data/lib/vcfb/component/number_field.rb +17 -0
  70. data/lib/vcfb/component/password_field.rb +17 -0
  71. data/lib/vcfb/component/radio_button.rb +18 -0
  72. data/lib/vcfb/component/range_field.rb +17 -0
  73. data/lib/vcfb/component/rich_text_area.rb +17 -0
  74. data/lib/vcfb/component/search_field.rb +17 -0
  75. data/lib/vcfb/component/select.rb +23 -0
  76. data/lib/vcfb/component/submit.rb +17 -0
  77. data/lib/vcfb/component/telephone_field.rb +17 -0
  78. data/lib/vcfb/component/text_area.rb +17 -0
  79. data/lib/vcfb/component/text_field.rb +17 -0
  80. data/lib/vcfb/component/time_field.rb +17 -0
  81. data/lib/vcfb/component/time_select.rb +18 -0
  82. data/lib/vcfb/component/time_zone_select.rb +19 -0
  83. data/lib/vcfb/component/url_field.rb +17 -0
  84. data/lib/vcfb/component/week_field.rb +17 -0
  85. data/lib/vcfb/component/weekday_select.rb +18 -0
  86. data/lib/vcfb/errors/component_missing.rb +5 -0
  87. data/lib/vcfb/errors/error.rb +5 -0
  88. data/lib/vcfb/form_builder.rb +56 -19
  89. data/lib/vcfb/form_helper.rb +12 -0
  90. data/lib/vcfb/railtie.rb +7 -0
  91. data/lib/vcfb/resolver.rb +8 -6
  92. data/lib/vcfb/tags/collection_check_boxes.rb +2 -2
  93. data/lib/vcfb/tags/collection_helpers.rb +0 -2
  94. data/lib/vcfb/tags/collection_radio_buttons.rb +2 -2
  95. data/lib/vcfb/template.rb +8 -6
  96. data/lib/vcfb/version.rb +1 -1
  97. data/lib/vcfb.rb +68 -10
  98. metadata +44 -5
  99. data/lib/vcfb/acts_as_form_collection_component.rb +0 -19
  100. data/lib/vcfb/acts_as_form_component.rb +0 -22
  101. data/lib/vcfb/acts_as_form_label_component.rb +0 -21
@@ -0,0 +1,28 @@
1
+ module VCFB
2
+ module Component
3
+ class Label < Base
4
+ delegate :translation, :to_s, to: :label_builder
5
+ alias_method :default_text, :translation
6
+
7
+ def initialize(form, method, text = nil, options = {})
8
+ run_callbacks :initialize do
9
+ @form = form
10
+ @method = method
11
+ @text = text
12
+ @options = options
13
+ end
14
+ end
15
+
16
+ def form_element(options = {}, &block)
17
+ label(@form.object_name, @method, options, &block)
18
+ end
19
+
20
+ private
21
+
22
+ def label_builder
23
+ @label_builder ||= ActionView::Helpers::Tags::Label::LabelBuilder
24
+ .new(@form.template, @form.object_name, @method, @form.object, @options[:value])
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class MonthField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ month_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class NumberField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ number_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class PasswordField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ password_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module VCFB
2
+ module Component
3
+ class RadioButton < Base
4
+ def initialize(form, method, value, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @value = value
9
+ @options = options
10
+ end
11
+ end
12
+
13
+ def form_element(options = {})
14
+ radio_button(@form.object_name, @method, @value, options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class RangeField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ range_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class RichTextArea < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ rich_text_area(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class SearchField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ search_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,23 @@
1
+ module VCFB
2
+ module Component
3
+ class Select < Base
4
+ def initialize(form, method, choices = nil, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @choices = choices
9
+ @options = options
10
+ @html_options = html_options
11
+ end
12
+ end
13
+
14
+ def before_render
15
+ @choices = content if content.present?
16
+ end
17
+
18
+ def form_element(options = {}, html_options = {})
19
+ select(@form.object_name, @method, @choices, options, html_options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class Submit < Base
4
+ def initialize(form, text = nil, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @text = text
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ submit_tag(@text, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class TelephoneField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ telephone_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class TextArea < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ text_area(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class TextField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ text_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class TimeField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ time_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module VCFB
2
+ module Component
3
+ class TimeSelect < Base
4
+ def initialize(form, method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ @html_options = html_options
10
+ end
11
+ end
12
+
13
+ def form_element(options = {}, html_options = {})
14
+ time_select(@form.object_name, @method, options, html_options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ module VCFB
2
+ module Component
3
+ class TimeZoneSelect < Base
4
+ def initialize(form, method, priority_zones = nil, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @priority_zones = priority_zones
9
+ @options = options
10
+ @html_options = html_options
11
+ end
12
+ end
13
+
14
+ def form_element(options = {}, html_options = {})
15
+ time_zone_select(@form.object_name, @method, @priority_zones, options, html_options)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class UrlField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ url_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module VCFB
2
+ module Component
3
+ class WeekField < Base
4
+ def initialize(form, method, options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ end
10
+ end
11
+
12
+ def form_element(options = {})
13
+ week_field(@form.object_name, @method, options)
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,18 @@
1
+ module VCFB
2
+ module Component
3
+ class WeekdaySelect < Base
4
+ def initialize(form, method, options = {}, html_options = {})
5
+ run_callbacks :initialize do
6
+ @form = form
7
+ @method = method
8
+ @options = options
9
+ @html_options = html_options
10
+ end
11
+ end
12
+
13
+ def form_element(options = {}, html_options = {})
14
+ weekday_select(@form.object_name, @method, options, html_options)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module VCFB
2
+ module Errors
3
+ class ComponentMissing < Error; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module VCFB
2
+ module Errors
3
+ class Error < StandardError; end
4
+ end
5
+ end
@@ -1,23 +1,27 @@
1
- require "active_support/core_ext/class/attribute"
2
- require "view_component"
3
-
4
- require "vcfb/acts_as_form_component"
5
- require "vcfb/acts_as_form_collection_component"
6
- require "vcfb/acts_as_form_label_component"
7
- require "vcfb/resolver"
8
- require "vcfb/template"
9
-
10
1
  module VCFB
11
2
  class FormBuilder < ::ActionView::Helpers::FormBuilder
12
3
  class_attribute :namespace, instance_writer: false, default: "form"
13
4
 
14
5
  attr_reader :object, :object_name, :template
6
+ attr_accessor :form_component
15
7
 
16
8
  def initialize(*args)
17
9
  super
18
10
  @template = Template.new(@template, self)
19
11
  end
20
12
 
13
+ # FORM COMPONENT
14
+
15
+ def self.form_component_class
16
+ "#{namespace}/component".camelize.constantize
17
+ end
18
+
19
+ def self.form_component_defined?
20
+ form_component_class.present?
21
+ rescue Errors::ComponentMissing
22
+ false
23
+ end
24
+
21
25
  # SIMPLE FIELDS
22
26
 
23
27
  SIMPLE_FIELDS = %i[color_field date_field datetime_field email_field month_field number_field password_field
@@ -64,6 +68,7 @@ module VCFB
64
68
  end
65
69
 
66
70
  def collection_check_boxes_label(method, text = nil, options = {}, &block)
71
+ options, text = text, nil if text.is_a?(Hash)
67
72
  if component_defined?(:"collection_check_boxes/label")
68
73
  componentify(:"collection_check_boxes/label", method, text, options, &block)
69
74
  elsif component_defined?(:label)
@@ -90,10 +95,11 @@ module VCFB
90
95
  end
91
96
 
92
97
  def collection_radio_buttons_label(method, text = nil, options = {}, &block)
98
+ options, text = text, nil if text.is_a?(Hash)
93
99
  if component_defined?(:"collection_radio_buttons/label")
94
- componentify(:"collection_radio_buttons/label", method, text, options, &block)
100
+ componentify_with_slots(:"collection_radio_buttons/label", method, text, options, &block)
95
101
  elsif component_defined?(:label)
96
- componentify(:label, method, text, options, &block)
102
+ componentify_with_slots(:label, method, text, options, &block)
97
103
  else
98
104
  label(method, text, options, &block)
99
105
  end
@@ -131,7 +137,8 @@ module VCFB
131
137
  def label(method, text = nil, options = {}, &block)
132
138
  return super unless component_defined?(:label)
133
139
 
134
- componentify(:label, method, text, objectify_options(options), &block)
140
+ options, text = text, nil if text.is_a?(Hash)
141
+ componentify_with_slots(:label, method, text, objectify_options(options), &block)
135
142
  end
136
143
 
137
144
  def radio_button(method, value, options = {})
@@ -166,23 +173,53 @@ module VCFB
166
173
  end
167
174
  end
168
175
 
169
- # COMPONENT LOOKUP
176
+ # BUTTONS
177
+
178
+ # The default #button method captures the block (it never makes it to the
179
+ # underlying button_tag helper). Stash it here into options so that we can
180
+ # pull it out later (see vcfb/template) and pass it on to the component so
181
+ # that we can support slots on button components.
182
+ def button(value = nil, options = {}, &block)
183
+ options[:_block_for_component] = block
184
+ super(value, options, &nil)
185
+ end
186
+
187
+ # COMPONENT SUPPORT
170
188
 
171
189
  def component_defined?(form_element)
172
- resolve_form_component(form_element).present?
173
- rescue
190
+ resolve_component_class(form_element).present?
191
+ rescue Errors::ComponentMissing
174
192
  false
175
193
  end
176
194
 
177
195
  def componentify(form_element, *args, **opts, &block)
178
- form_component_class = resolve_form_component(form_element)
179
- @template.render form_component_class.new(self, *args, **opts), &block
196
+ component_class = resolve_component_class(form_element)
197
+ @template.render component_class.new(self, *args, **opts), &block
180
198
  end
181
199
 
182
- private
200
+ def componentify_with_slots(form_element, *args, **opts, &block)
201
+ component_class = resolve_component_class(form_element)
202
+ @template.render component_class.new(self, *args, **opts) do |component|
203
+ block&.call(component)
204
+ end
205
+ end
183
206
 
184
- def resolve_form_component(form_element)
207
+ def resolve_component_class(form_element)
185
208
  VCFB::Resolver.call(namespace, form_element)
186
209
  end
210
+
211
+ # SUPPORT FORM COMPONENT SLOTS
212
+
213
+ def method_missing(method_name, *args, **opts, &block)
214
+ super unless method_name.to_s.start_with?("with_")
215
+
216
+ form_component.public_send(method_name, *args, **opts, &block)
217
+ end
218
+
219
+ def respond_to_missing?(method_name, include_private = false)
220
+ super unless method_name.to_s.start_with?("with_")
221
+
222
+ form_component.respond_to?(method_name, include_private)
223
+ end
187
224
  end
188
225
  end
@@ -0,0 +1,12 @@
1
+ module VCFB
2
+ module FormHelper
3
+ def component_form_with(model: nil, scope: nil, url: nil, format: nil, **options, &block)
4
+ options[:builder] ||= VCFB::FormBuilder
5
+ if options[:builder].try(:form_component_defined?)
6
+ render options[:builder].form_component_class.new(model: model, scope: scope, url: url, format: format, **options), &block
7
+ else
8
+ form_with(model: model, scope: scope, url: url, format: format, **options, &block)
9
+ end
10
+ end
11
+ end
12
+ end
data/lib/vcfb/railtie.rb CHANGED
@@ -2,5 +2,12 @@ require "rails/railtie"
2
2
 
3
3
  module VCFB
4
4
  class Railtie < ::Rails::Railtie
5
+ initializer "vcfb.helper" do |_app|
6
+ ActionView::Base.send :include, VCFB::FormHelper
7
+ end
8
+
9
+ config.to_prepare do
10
+ Component.setup!
11
+ end
5
12
  end
6
13
  end
data/lib/vcfb/resolver.rb CHANGED
@@ -1,17 +1,19 @@
1
- require "active_support/core_ext/string/inflections"
2
-
3
1
  module VCFB
4
2
  class Resolver
5
- def initialize(namespace, form_element)
3
+ def initialize(namespace, form_element = nil)
6
4
  @namespace = namespace.to_s.underscore
7
- @form_element = form_element.to_s.underscore
5
+ @form_element = form_element.to_s.underscore unless form_element.nil?
8
6
  end
9
7
 
10
8
  def call
11
- "#{@namespace}/#{@form_element}/component".camelize.constantize
9
+ component_name = "#{[@namespace, @form_element].compact.join("/")}/component"
10
+ component = component_name.camelize.safe_constantize
11
+ raise Errors::ComponentMissing, "unable to locate component #{component_name}" unless component
12
+
13
+ component
12
14
  end
13
15
 
14
- def self.call(namespace, form_element)
16
+ def self.call(namespace, form_element = nil)
15
17
  new(namespace, form_element).call
16
18
  end
17
19
  end
@@ -1,8 +1,7 @@
1
- require "vcfb/tags/collection_helpers"
2
-
3
1
  module VCFB
4
2
  module Tags
5
3
  class CollectionCheckBoxes < ActionView::Helpers::Tags::CollectionCheckBoxes
4
+ # Override the #label and #check_box methods to render via component
6
5
  class CheckBoxBuilder < ActionView::Helpers::Tags::CollectionCheckBoxes::Builder
7
6
  include CollectionHelpers
8
7
 
@@ -18,6 +17,7 @@ module VCFB
18
17
  end
19
18
  end
20
19
 
20
+ # Override the #render method to use our custom CheckBoxBuilder
21
21
  def render(&block)
22
22
  render_collection_for(CheckBoxBuilder, &block)
23
23
  end
@@ -1,5 +1,3 @@
1
- require "action_view/helpers/tags/collection_helpers"
2
-
3
1
  module VCFB
4
2
  module Tags
5
3
  module CollectionHelpers
@@ -1,8 +1,7 @@
1
- require "vcfb/tags/collection_helpers"
2
-
3
1
  module VCFB
4
2
  module Tags
5
3
  class CollectionRadioButtons < ActionView::Helpers::Tags::CollectionRadioButtons
4
+ # Override the #label and #radio_button methods to render via component
6
5
  class RadioButtonBuilder < ActionView::Helpers::Tags::CollectionRadioButtons::Builder
7
6
  include CollectionHelpers
8
7
 
@@ -17,6 +16,7 @@ module VCFB
17
16
  end
18
17
  end
19
18
 
19
+ # Override the #render method to use our custom RadioButtonBuilder
20
20
  def render(&block)
21
21
  render_collection_for(RadioButtonBuilder, &block)
22
22
  end
data/lib/vcfb/template.rb CHANGED
@@ -1,4 +1,9 @@
1
1
  module VCFB
2
+ # Several FormBuilder methods are more complex and have changed a good bit
3
+ # between between Rails releases. Rather than trying to keep up with these
4
+ # changes, we put together an intermediate Template class (see
5
+ # VCFB::FormBuilder) to defer the compnetifying until _after_ it's gone
6
+ # through ActionView::Helpers::FormBuilder.
2
7
  class Template
3
8
  def initialize(template, form)
4
9
  @template = template
@@ -7,14 +12,11 @@ module VCFB
7
12
 
8
13
  # Custom Tag Helpers
9
14
 
10
- def button_tag(value, options, &block)
15
+ def button_tag(value, options)
11
16
  return super unless @form.component_defined?(:button)
12
17
 
13
- if block
14
- value = @template.capture(value, &block)
15
- end
16
-
17
- @form.componentify(:button, value, options)
18
+ block = options.delete(:_block_for_component)
19
+ @form.componentify_with_slots(:button, value, options, &block)
18
20
  end
19
21
 
20
22
  def submit_tag(value, options)
data/lib/vcfb/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VCFB
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end