vcfb 1.0.0 → 2.0.2
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 +22 -0
- data/README.md +30 -0
- data/lib/generators/vcfb/components/components_generator.rb +5 -0
- data/lib/generators/vcfb/components/templates/button/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/button/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/check_box/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/collection_check_boxes/check_box/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/collection_check_boxes/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/collection_check_boxes/component.rb.tt +1 -24
- data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/collection_check_boxes/label/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/collection_radio_buttons/component.rb.tt +1 -24
- data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/collection_radio_buttons/label/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/collection_radio_buttons/radio_button/component.rb.tt +1 -13
- data/lib/generators/vcfb/components/templates/collection_select/component.rb.tt +1 -16
- data/lib/generators/vcfb/components/templates/color_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/component.html.erb +3 -0
- data/lib/generators/vcfb/components/templates/component.rb.tt +4 -0
- data/lib/generators/vcfb/components/templates/date_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/date_select/component.rb.tt +1 -13
- data/lib/generators/vcfb/components/templates/datetime_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/datetime_select/component.rb.tt +1 -13
- data/lib/generators/vcfb/components/templates/email_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/file_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/grouped_collection_select/component.rb.tt +1 -18
- data/lib/generators/vcfb/components/templates/label/component.html.erb +1 -1
- data/lib/generators/vcfb/components/templates/label/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/month_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/number_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/password_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/radio_button/component.rb.tt +1 -13
- data/lib/generators/vcfb/components/templates/range_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/rich_text_area/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/search_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/select/component.rb.tt +1 -18
- data/lib/generators/vcfb/components/templates/submit/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/telephone_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/text_area/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/text_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/time_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/time_select/component.rb.tt +1 -13
- data/lib/generators/vcfb/components/templates/time_zone_select/component.rb.tt +1 -14
- data/lib/generators/vcfb/components/templates/url_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/week_field/component.rb.tt +1 -12
- data/lib/generators/vcfb/components/templates/weekday_select/component.rb.tt +1 -13
- data/lib/generators/vcfb/initializer/initializer_generator.rb +12 -0
- data/lib/generators/vcfb/initializer/template/vcfb.rb.tt +3 -0
- data/lib/vcfb/component/base.rb +40 -0
- data/lib/vcfb/component/base_collection.rb +18 -0
- data/lib/vcfb/component/button.rb +17 -0
- data/lib/vcfb/component/check_box.rb +19 -0
- data/lib/vcfb/component/collection_check_boxes.rb +36 -0
- data/lib/vcfb/component/collection_radio_buttons.rb +36 -0
- data/lib/vcfb/component/collection_select.rb +21 -0
- data/lib/vcfb/component/color_field.rb +17 -0
- data/lib/vcfb/component/date_field.rb +17 -0
- data/lib/vcfb/component/date_select.rb +18 -0
- data/lib/vcfb/component/datetime_field.rb +17 -0
- data/lib/vcfb/component/datetime_select.rb +18 -0
- data/lib/vcfb/component/email_field.rb +17 -0
- data/lib/vcfb/component/file_field.rb +17 -0
- data/lib/vcfb/component/form.rb +41 -0
- data/lib/vcfb/component/grouped_collection_select.rb +23 -0
- data/lib/vcfb/component/label.rb +28 -0
- data/lib/vcfb/component/month_field.rb +17 -0
- data/lib/vcfb/component/number_field.rb +17 -0
- data/lib/vcfb/component/password_field.rb +17 -0
- data/lib/vcfb/component/radio_button.rb +18 -0
- data/lib/vcfb/component/range_field.rb +17 -0
- data/lib/vcfb/component/rich_text_area.rb +17 -0
- data/lib/vcfb/component/search_field.rb +17 -0
- data/lib/vcfb/component/select.rb +23 -0
- data/lib/vcfb/component/submit.rb +17 -0
- data/lib/vcfb/component/telephone_field.rb +17 -0
- data/lib/vcfb/component/text_area.rb +17 -0
- data/lib/vcfb/component/text_field.rb +17 -0
- data/lib/vcfb/component/time_field.rb +17 -0
- data/lib/vcfb/component/time_select.rb +18 -0
- data/lib/vcfb/component/time_zone_select.rb +19 -0
- data/lib/vcfb/component/url_field.rb +17 -0
- data/lib/vcfb/component/week_field.rb +17 -0
- data/lib/vcfb/component/weekday_select.rb +18 -0
- data/lib/vcfb/errors/component_missing.rb +5 -0
- data/lib/vcfb/errors/error.rb +5 -0
- data/lib/vcfb/form_builder.rb +56 -19
- data/lib/vcfb/form_helper.rb +12 -0
- data/lib/vcfb/railtie.rb +7 -0
- data/lib/vcfb/resolver.rb +8 -6
- data/lib/vcfb/tags/collection_check_boxes.rb +2 -2
- data/lib/vcfb/tags/collection_helpers.rb +0 -2
- data/lib/vcfb/tags/collection_radio_buttons.rb +2 -2
- data/lib/vcfb/template.rb +11 -6
- data/lib/vcfb/version.rb +1 -1
- data/lib/vcfb.rb +68 -10
- metadata +44 -5
- data/lib/vcfb/acts_as_form_collection_component.rb +0 -19
- data/lib/vcfb/acts_as_form_component.rb +0 -22
- data/lib/vcfb/acts_as_form_label_component.rb +0 -21
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module RichTextArea
|
3
|
-
class Component <
|
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
|
-
rich_text_area(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::RichTextArea
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module SearchField
|
3
|
-
class Component <
|
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
|
-
search_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::SearchField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,23 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module Select
|
3
|
-
class Component <
|
4
|
-
include VCFB::ActsAsFormComponent
|
5
|
-
|
6
|
-
def initialize(form, method, choices = nil, options = {}, html_options = {})
|
7
|
-
@form = form
|
8
|
-
@method = method
|
9
|
-
@choices = choices
|
10
|
-
@options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
|
11
|
-
@html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
|
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
|
3
|
+
class Component < VCFB::Component::Select
|
21
4
|
end
|
22
5
|
end
|
23
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module Submit
|
3
|
-
class Component <
|
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 = {})
|
13
|
-
submit_tag(@text, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::Submit
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TelephoneField
|
3
|
-
class Component <
|
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
|
-
telephone_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::TelephoneField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TextArea
|
3
|
-
class Component <
|
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
|
-
text_area(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::TextArea
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TextField
|
3
|
-
class Component <
|
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
|
-
text_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::TextField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TimeField
|
3
|
-
class Component <
|
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
|
-
time_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::TimeField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,18 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TimeSelect
|
3
|
-
class Component <
|
4
|
-
include VCFB::ActsAsFormComponent
|
5
|
-
|
6
|
-
def initialize(form, method, options = {}, html_options = {})
|
7
|
-
@form = form
|
8
|
-
@method = method
|
9
|
-
@options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
|
10
|
-
@html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
|
11
|
-
end
|
12
|
-
|
13
|
-
def form_element(options = {}, html_options = {})
|
14
|
-
time_select(@form.object_name, @method, options, html_options)
|
15
|
-
end
|
3
|
+
class Component < VCFB::Component::TimeSelect
|
16
4
|
end
|
17
5
|
end
|
18
6
|
<% end -%>
|
@@ -1,19 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module TimeZoneSelect
|
3
|
-
class Component <
|
4
|
-
include VCFB::ActsAsFormComponent
|
5
|
-
|
6
|
-
def initialize(form, method, priority_zones = nil, options = {}, html_options = {})
|
7
|
-
@form = form
|
8
|
-
@method = method
|
9
|
-
@priority_zones = priority_zones
|
10
|
-
@options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
|
11
|
-
@html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
|
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
|
3
|
+
class Component < VCFB::Component::TimeZoneSelect
|
17
4
|
end
|
18
5
|
end
|
19
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module UrlField
|
3
|
-
class Component <
|
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
|
-
url_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::UrlField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,17 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module WeekField
|
3
|
-
class Component <
|
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
|
-
week_field(@form.object_name, @method, options)
|
14
|
-
end
|
3
|
+
class Component < VCFB::Component::WeekField
|
15
4
|
end
|
16
5
|
end
|
17
6
|
<% end -%>
|
@@ -1,18 +1,6 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
2
|
module WeekdaySelect
|
3
|
-
class Component <
|
4
|
-
include VCFB::ActsAsFormComponent
|
5
|
-
|
6
|
-
def initialize(form, method, options = {}, html_options = {})
|
7
|
-
@form = form
|
8
|
-
@method = method
|
9
|
-
@options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(options)" : "options" %>
|
10
|
-
@html_options = <%= defined?(TagOptions::Hash) ? "TagOptions::Hash.new(html_options)" : "html_options" %>
|
11
|
-
end
|
12
|
-
|
13
|
-
def form_element(options = {}, html_options = {})
|
14
|
-
weekday_select(@form.object_name, @method, options, html_options)
|
15
|
-
end
|
3
|
+
class Component < VCFB::Component::WeekdaySelect
|
16
4
|
end
|
17
5
|
end
|
18
6
|
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "active_support/core_ext/string/inflections"
|
2
|
+
require "rails/generators/base"
|
3
|
+
|
4
|
+
module Vcfb
|
5
|
+
class InitializerGenerator < ::Rails::Generators::Base
|
6
|
+
source_root File.expand_path("template", __dir__)
|
7
|
+
|
8
|
+
def create_form_component
|
9
|
+
template "vcfb.rb.tt", "config/initializers/vcfb.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class Base < VCFB.parent_component.constantize
|
4
|
+
extend ActiveModel::Callbacks
|
5
|
+
|
6
|
+
# Define initialize callback to reduce need to override the initialize
|
7
|
+
# method on form components.
|
8
|
+
define_model_callbacks :initialize
|
9
|
+
|
10
|
+
# Work around ViewComponent not having access helpers we need via
|
11
|
+
# ActionText. For more information, see:
|
12
|
+
# https://github.com/github/view_component/blob/main/docs/compatibility.md#actiontext
|
13
|
+
delegate :rich_text_area_tag, to: :helpers
|
14
|
+
|
15
|
+
# Override the built-in methods to allow us to render custom collection
|
16
|
+
# tag builders that render using labels, check boxes, and radio buttons
|
17
|
+
# via components.
|
18
|
+
def collection_check_boxes(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
19
|
+
VCFB::Tags::CollectionCheckBoxes.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
20
|
+
end
|
21
|
+
|
22
|
+
def collection_radio_buttons(object, method, collection, value_method, text_method, options = {}, html_options = {}, &block)
|
23
|
+
VCFB::Tags::CollectionRadioButtons.new(object, method, self, collection, value_method, text_method, options, html_options).render(&block)
|
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
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class BaseCollection < Base
|
4
|
+
private
|
5
|
+
|
6
|
+
def content
|
7
|
+
return unless instance_variable_defined?(:@builder)
|
8
|
+
|
9
|
+
@__vc_content = if @view_context && @__vc_render_in_block
|
10
|
+
view_context.capture(@builder, &@__vc_render_in_block)
|
11
|
+
else
|
12
|
+
default_content
|
13
|
+
end
|
14
|
+
super()
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class Button < Base
|
4
|
+
def initialize(form, text = nil, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@text = text
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
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,19 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class CheckBox < Base
|
4
|
+
def initialize(form, method, options = {}, checked_value = "1", unchecked_value = "0")
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
@checked_value = checked_value
|
10
|
+
@unchecked_value = unchecked_value
|
11
|
+
end
|
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,36 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class CollectionCheckBoxes < BaseCollection
|
4
|
+
def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@collection = collection
|
9
|
+
@value_method = value_method
|
10
|
+
@text_method = text_method
|
11
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
12
|
+
@html_options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(html_options) : html_options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# The form element #collection_check_boxes yields a special builder that
|
17
|
+
# can be used to define a template to render each checkbox. We yield that
|
18
|
+
# builder here and override the ViewComponent #content method (see
|
19
|
+
# BaseCollection) to support render these elements using components.
|
20
|
+
def form_element(options = {}, html_options = {}, &block)
|
21
|
+
collection_check_boxes(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
|
22
|
+
@builder = builder
|
23
|
+
block&.call(@builder)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Define the default content / template to use if a block is not passed
|
30
|
+
# when calling #collection_check_boxes
|
31
|
+
def default_content
|
32
|
+
@builder.check_box + @builder.label
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class CollectionRadioButtons < BaseCollection
|
4
|
+
def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@collection = collection
|
9
|
+
@value_method = value_method
|
10
|
+
@text_method = text_method
|
11
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
12
|
+
@html_options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(html_options) : html_options
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# The form element #collection_radio_buttons yields a special builder that
|
17
|
+
# can be used to define a template to render each radio button. We yield
|
18
|
+
# that builder here and override the ViewComponent #content method (see
|
19
|
+
# BaseCollection) to support render these elements using components.
|
20
|
+
def form_element(options = {}, html_options = {}, &block)
|
21
|
+
collection_radio_buttons(@form.object_name, @method, @collection, @value_method, @text_method, options, html_options) do |builder|
|
22
|
+
@builder = builder
|
23
|
+
block&.call(@builder)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Define the default content / template to use if a block is not passed
|
30
|
+
# when calling #collection_radio_buttons
|
31
|
+
def default_content
|
32
|
+
@builder.radio_button + @builder.label
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class CollectionSelect < Base
|
4
|
+
def initialize(form, method, collection, value_method, text_method, options = {}, html_options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@collection = collection
|
9
|
+
@value_method = value_method
|
10
|
+
@text_method = text_method
|
11
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
12
|
+
@html_options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(html_options) : html_options
|
13
|
+
end
|
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,17 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class ColorField < Base
|
4
|
+
def initialize(form, method, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
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,17 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class DateField < Base
|
4
|
+
def initialize(form, method, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def form_element(options = {})
|
13
|
+
date_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 DateSelect < Base
|
4
|
+
def initialize(form, method, options = {}, html_options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
@html_options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(html_options) : html_options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def form_element(options = {}, html_options = {})
|
14
|
+
date_select(@form.object_name, @method, options, html_options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class DatetimeField < Base
|
4
|
+
def initialize(form, method, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def form_element(options = {})
|
13
|
+
datetime_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 DatetimeSelect < Base
|
4
|
+
def initialize(form, method, options = {}, html_options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
@html_options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(html_options) : html_options
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def form_element(options = {}, html_options = {})
|
14
|
+
datetime_select(@form.object_name, @method, options, html_options)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class EmailField < Base
|
4
|
+
def initialize(form, method, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def form_element(options = {})
|
13
|
+
email_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 FileField < Base
|
4
|
+
def initialize(form, method, options = {})
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@form = form
|
7
|
+
@method = method
|
8
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def form_element(options = {})
|
13
|
+
file_field(@form.object_name, @method, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module VCFB
|
2
|
+
module Component
|
3
|
+
class Form < Base
|
4
|
+
def initialize(model: nil, scope: nil, url: nil, format: nil, **options)
|
5
|
+
run_callbacks :initialize do
|
6
|
+
@model = model
|
7
|
+
@scope = scope
|
8
|
+
@url = url
|
9
|
+
@format = format
|
10
|
+
@options = defined?(TagOptions::Hash) ? TagOptions::Hash.new(options) : options
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Because we've overridden the #content and #get_slot methods below to
|
15
|
+
# support yielding the form, we need to save the component to our custom
|
16
|
+
# form builder to support rendering slots in the form components.
|
17
|
+
def form_tag(options = {}, &block)
|
18
|
+
form_with(model: @model, scope: @scope, url: @url, format: @format, **options) do |form|
|
19
|
+
form.form_component = self if form.respond_to?(:form_component=)
|
20
|
+
@form = form
|
21
|
+
block&.call(@form)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# Override #content and #get_slot from ViewComponent so that we can yield
|
30
|
+
# the form element (and not the component).
|
31
|
+
def content
|
32
|
+
return unless instance_variable_defined?(:@form)
|
33
|
+
|
34
|
+
if @view_context && @__vc_render_in_block
|
35
|
+
@__vc_content = view_context.capture(@form, &@__vc_render_in_block)
|
36
|
+
end
|
37
|
+
super()
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|