arara 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +38 -0
- data/Rakefile +32 -0
- data/app/assets/config/arara_manifest.js +1 -0
- data/app/assets/javascripts/arara.js +603 -0
- data/app/assets/stylesheets/arara/application.css +15 -0
- data/app/components/arara.rb +2 -0
- data/app/components/arara/base_component.rb +62 -0
- data/app/components/arara/button_component.html.erb +7 -0
- data/app/components/arara/button_component.rb +50 -0
- data/app/components/arara/card_action_buttons_component.html.erb +3 -0
- data/app/components/arara/card_action_buttons_component.rb +15 -0
- data/app/components/arara/card_action_icons_component.html.erb +3 -0
- data/app/components/arara/card_action_icons_component.rb +15 -0
- data/app/components/arara/card_actions_component.html.erb +3 -0
- data/app/components/arara/card_actions_component.rb +15 -0
- data/app/components/arara/card_component.html.erb +3 -0
- data/app/components/arara/card_component.rb +15 -0
- data/app/components/arara/card_media_component.html.erb +3 -0
- data/app/components/arara/card_media_component.rb +20 -0
- data/app/components/arara/card_media_content_component.html.erb +3 -0
- data/app/components/arara/card_media_content_component.rb +15 -0
- data/app/components/arara/card_primary_content_component.html.erb +3 -0
- data/app/components/arara/card_primary_content_component.rb +18 -0
- data/app/components/arara/checkbox_component.html.erb +22 -0
- data/app/components/arara/checkbox_component.rb +25 -0
- data/app/components/arara/chip_component.html.erb +13 -0
- data/app/components/arara/chip_component.rb +22 -0
- data/app/components/arara/chipset_component.html.erb +6 -0
- data/app/components/arara/chipset_component.rb +23 -0
- data/app/components/arara/data_table_body_cell_component.html.erb +3 -0
- data/app/components/arara/data_table_body_cell_component.rb +18 -0
- data/app/components/arara/data_table_body_checkbox_component.html.erb +11 -0
- data/app/components/arara/data_table_body_checkbox_component.rb +25 -0
- data/app/components/arara/data_table_body_component.html.erb +3 -0
- data/app/components/arara/data_table_body_component.rb +15 -0
- data/app/components/arara/data_table_body_row_component.html.erb +3 -0
- data/app/components/arara/data_table_body_row_component.rb +27 -0
- data/app/components/arara/data_table_component.html.erb +5 -0
- data/app/components/arara/data_table_component.rb +36 -0
- data/app/components/arara/data_table_header_cell_component.html.erb +3 -0
- data/app/components/arara/data_table_header_cell_component.rb +24 -0
- data/app/components/arara/data_table_header_checkbox_component.html.erb +11 -0
- data/app/components/arara/data_table_header_checkbox_component.rb +25 -0
- data/app/components/arara/data_table_header_component.html.erb +3 -0
- data/app/components/arara/data_table_header_component.rb +11 -0
- data/app/components/arara/data_table_header_row_component.html.erb +3 -0
- data/app/components/arara/data_table_header_row_component.rb +15 -0
- data/app/components/arara/dialog_button_component.html.erb +4 -0
- data/app/components/arara/dialog_button_component.rb +31 -0
- data/app/components/arara/dialog_component.html.erb +8 -0
- data/app/components/arara/dialog_component.rb +34 -0
- data/app/components/arara/dialog_content_component.html.erb +3 -0
- data/app/components/arara/dialog_content_component.rb +15 -0
- data/app/components/arara/dialog_footer_component.html.erb +3 -0
- data/app/components/arara/dialog_footer_component.rb +15 -0
- data/app/components/arara/dialog_title_component.html.erb +3 -0
- data/app/components/arara/dialog_title_component.rb +16 -0
- data/app/components/arara/elevation_component.html.erb +3 -0
- data/app/components/arara/elevation_component.rb +19 -0
- data/app/components/arara/fab_component.html.erb +13 -0
- data/app/components/arara/fab_component.rb +42 -0
- data/app/components/arara/fab_icon_component.html.erb +3 -0
- data/app/components/arara/fab_icon_component.rb +15 -0
- data/app/components/arara/form_builder.rb +142 -0
- data/app/components/arara/form_field_component.html.erb +3 -0
- data/app/components/arara/form_field_component.rb +15 -0
- data/app/components/arara/google_calendar/menu_item_component.html.erb +11 -0
- data/app/components/arara/google_calendar/menu_item_component.rb +34 -0
- data/app/components/arara/google_calendar/nav_bar_component.html.erb +176 -0
- data/app/components/arara/google_calendar/nav_bar_component.rb +6 -0
- data/app/components/arara/icon_button_component.html.erb +3 -0
- data/app/components/arara/icon_button_component.rb +42 -0
- data/app/components/arara/icon_toggle_component.html.erb +3 -0
- data/app/components/arara/icon_toggle_component.rb +18 -0
- data/app/components/arara/material_icon_component.html.erb +3 -0
- data/app/components/arara/material_icon_component.rb +18 -0
- data/app/components/arara/menu_component.html.erb +5 -0
- data/app/components/arara/menu_component.rb +19 -0
- data/app/components/arara/menu_divider_component.html.erb +1 -0
- data/app/components/arara/menu_divider_component.rb +19 -0
- data/app/components/arara/menu_item_component.html.erb +3 -0
- data/app/components/arara/menu_item_component.rb +22 -0
- data/app/components/arara/nav_bar_component.html.erb +293 -0
- data/app/components/arara/nav_bar_component.rb +7 -0
- data/app/components/arara/radio_button_component.html.erb +8 -0
- data/app/components/arara/radio_button_component.rb +35 -0
- data/app/components/arara/select_component.html.erb +22 -0
- data/app/components/arara/select_component.rb +27 -0
- data/app/components/arara/select_item_component.html.erb +3 -0
- data/app/components/arara/select_item_component.rb +45 -0
- data/app/components/arara/step_component.html.erb +27 -0
- data/app/components/arara/step_component.rb +100 -0
- data/app/components/arara/step_connector_component.html.erb +4 -0
- data/app/components/arara/step_connector_component.rb +31 -0
- data/app/components/arara/stepper_component.html.erb +3 -0
- data/app/components/arara/stepper_component.rb +20 -0
- data/app/components/arara/switch_component.html.erb +8 -0
- data/app/components/arara/switch_component.rb +35 -0
- data/app/components/arara/tags.rb +2 -0
- data/app/components/arara/tags/check_box.rb +63 -0
- data/app/components/arara/tags/chip_choice.rb +81 -0
- data/app/components/arara/tags/chipset.rb +39 -0
- data/app/components/arara/tags/country_select.rb +110 -0
- data/app/components/arara/tags/label.rb +78 -0
- data/app/components/arara/tags/password_field.rb +16 -0
- data/app/components/arara/tags/radio_button.rb +31 -0
- data/app/components/arara/tags/select.rb +120 -0
- data/app/components/arara/tags/text_area.rb +25 -0
- data/app/components/arara/tags/text_field.rb +31 -0
- data/app/components/arara/text_field_component.html.erb +47 -0
- data/app/components/arara/text_field_component.rb +101 -0
- data/app/components/arara/typography_component.html.erb +1 -0
- data/app/components/arara/typography_component.rb +51 -0
- data/app/controllers/arara/application_controller.rb +5 -0
- data/app/helpers/arara/application_helper.rb +4 -0
- data/app/javascript/arara/controllers/body_class_toggler_controller.js +20 -0
- data/app/javascript/arara/controllers/counter_controller.js +22 -0
- data/app/javascript/arara/controllers/demo_dialog_controller.js +24 -0
- data/app/javascript/arara/controllers/mdc_chip_set_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_data_table_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_form_field_controller.js +40 -0
- data/app/javascript/arara/controllers/mdc_icon_toggle_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_linear_progress_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_list_controller.js +23 -0
- data/app/javascript/arara/controllers/mdc_menu_controller.js +25 -0
- data/app/javascript/arara/controllers/mdc_ripple_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_select_controller.js +27 -0
- data/app/javascript/arara/controllers/mdc_slider_controller.js +21 -0
- data/app/javascript/arara/controllers/mdc_snackbar_controller.js +38 -0
- data/app/javascript/arara/controllers/mdc_switch_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_tab_bar_controller.js +18 -0
- data/app/javascript/arara/controllers/mdc_text_field_controller.js +35 -0
- data/app/javascript/arara/controllers/mdc_top_app_bar_controller.js +18 -0
- data/app/javascript/arara/controllers/rails_chip_set_choice_controller.js +31 -0
- data/app/javascript/arara/controllers/rails_chip_set_filter_controller.js +39 -0
- data/app/javascript/arara/controllers/remote_form_controller.js +79 -0
- data/app/javascript/arara/helpers/sum.js +5 -0
- data/app/javascript/arara/index.js +65 -0
- data/app/javascript/arara/scss/_material_design.scss +34 -0
- data/app/javascript/arara/scss/_tailwind.scss +4 -0
- data/app/javascript/arara/scss/arara.scss +5 -0
- data/app/javascript/arara/scss/material_design/_custom.scss +61 -0
- data/app/javascript/arara/scss/tailwind/_ripple_workaround.scss +22 -0
- data/app/jobs/arara/application_job.rb +4 -0
- data/app/mailers/arara/application_mailer.rb +6 -0
- data/app/models/arara/application_record.rb +5 -0
- data/app/views/layouts/arara/application.html.erb +15 -0
- data/config/routes.rb +2 -0
- data/lib/arara.rb +5 -0
- data/lib/arara/engine.rb +7 -0
- data/lib/arara/version.rb +3 -0
- data/lib/tasks/arara_tasks.rake +4 -0
- metadata +238 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/helpers/tags/placeholderable"
|
4
|
+
|
5
|
+
module Arara
|
6
|
+
module Tags # :nodoc:
|
7
|
+
class Chipset < ActionView::Helpers::Tags::Base # :nodoc:
|
8
|
+
attr_reader :block
|
9
|
+
include ActionView::Helpers::Tags::Placeholderable
|
10
|
+
|
11
|
+
def initialize(object_name, method_name, template_object, options = {}, &block)
|
12
|
+
@block = block
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def render
|
17
|
+
options = @options.stringify_keys
|
18
|
+
options["value"] = options.fetch("value") { value_before_type_cast } unless field_type == "file"
|
19
|
+
if options["variant"] == :choice
|
20
|
+
options["include_choice_hidden_field"] = true
|
21
|
+
end
|
22
|
+
add_default_name_and_id(options)
|
23
|
+
|
24
|
+
@template_object.template.render(Arara::ChipsetComponent, options.symbolize_keys, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
def field_type
|
29
|
+
@field_type ||= name.split("::").last.sub("Field", "").downcase
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
def field_type
|
35
|
+
self.class.field_type
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Arara
|
4
|
+
module Tags # :nodoc:
|
5
|
+
class CountrySelect < ActionView::Helpers::Tags::Base # :nodoc:
|
6
|
+
include ::CountrySelect::TagHelper
|
7
|
+
|
8
|
+
# def initialize(object_name, method_name, template_object, choices, options, html_options)
|
9
|
+
# @choices = block_given? ? template_object.capture { yield || "" } : choices
|
10
|
+
# @choices = @choices.to_a if @choices.is_a?(Range)
|
11
|
+
|
12
|
+
# @html_options = html_options
|
13
|
+
|
14
|
+
# super(object_name, method_name, template_object, options)
|
15
|
+
# end
|
16
|
+
def initialize(object_name, method_name, template_object, options, html_options)
|
17
|
+
@html_options = html_options
|
18
|
+
|
19
|
+
super(object_name, method_name, template_object, options)
|
20
|
+
end
|
21
|
+
|
22
|
+
# def render
|
23
|
+
# option_tags_options = {
|
24
|
+
# selected: @options.fetch(:selected) { value.to_s },
|
25
|
+
# disabled: @options[:disabled]
|
26
|
+
# }
|
27
|
+
|
28
|
+
# option_tags = if grouped_choices?
|
29
|
+
# grouped_options_for_select(@choices, option_tags_options)
|
30
|
+
# else
|
31
|
+
# options_for_select(@choices, option_tags_options)
|
32
|
+
# end
|
33
|
+
|
34
|
+
# if option_tags_options[:selected]
|
35
|
+
# selected_element = @choices.select { |x| x[1].to_s == option_tags_options[:selected] }.first
|
36
|
+
# if selected_element
|
37
|
+
# selected_label = selected_element[0].to_s
|
38
|
+
# selected_value = selected_element[1].to_s
|
39
|
+
# end
|
40
|
+
# @options.merge!(
|
41
|
+
# selected_value: selected_value,
|
42
|
+
# selected_label: selected_label,
|
43
|
+
# )
|
44
|
+
# end
|
45
|
+
|
46
|
+
# select_content_tag(option_tags, @options, @html_options)
|
47
|
+
# end
|
48
|
+
def render
|
49
|
+
select_content_tag(country_option_tags, @options, @html_options)
|
50
|
+
end
|
51
|
+
|
52
|
+
# my method
|
53
|
+
def options_for_select(container, selected = nil)
|
54
|
+
return container if String === container
|
55
|
+
|
56
|
+
selected, disabled = extract_selected_and_disabled(selected).map do |r|
|
57
|
+
Array(r).map(&:to_s)
|
58
|
+
end
|
59
|
+
|
60
|
+
container.map do |element|
|
61
|
+
html_attributes = option_html_attributes(element)
|
62
|
+
text, value = option_text_and_value(element).map(&:to_s)
|
63
|
+
|
64
|
+
html_attributes[:selected] ||= option_value_selected?(value, selected)
|
65
|
+
html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
|
66
|
+
html_attributes[:value] = value
|
67
|
+
|
68
|
+
# also set the label
|
69
|
+
html_attributes[:label] = text
|
70
|
+
|
71
|
+
# and render our component
|
72
|
+
@template_object.template.render(Arara::SelectItemComponent, html_attributes.symbolize_keys)
|
73
|
+
end.join("\n").html_safe
|
74
|
+
end
|
75
|
+
|
76
|
+
def select_content_tag(option_tags, options, html_options)
|
77
|
+
html_options = html_options.stringify_keys
|
78
|
+
add_default_name_and_id(html_options)
|
79
|
+
|
80
|
+
if placeholder_required?(html_options)
|
81
|
+
raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
|
82
|
+
options[:include_blank] ||= true unless options[:prompt]
|
83
|
+
end
|
84
|
+
|
85
|
+
value = options.fetch(:selected) { value() }
|
86
|
+
select = content_tag("select", add_options(option_tags, options, value), html_options)
|
87
|
+
|
88
|
+
if html_options["multiple"] && options.fetch(:include_hidden, true)
|
89
|
+
tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "") + select
|
90
|
+
else
|
91
|
+
select
|
92
|
+
end
|
93
|
+
|
94
|
+
select_options = options.merge(html_options)
|
95
|
+
@template_object.template.render(Arara::SelectComponent, select_options.symbolize_keys) do
|
96
|
+
option_tags
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
# Grouped choices look like this:
|
102
|
+
#
|
103
|
+
# [nil, []]
|
104
|
+
# { nil => [] }
|
105
|
+
def grouped_choices?
|
106
|
+
!@choices.blank? && @choices.first.respond_to?(:last) && Array === @choices.first.last
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Arara
|
4
|
+
module Tags # :nodoc:
|
5
|
+
class Label < ActionView::Helpers::Tags::Base # :nodoc:
|
6
|
+
class LabelBuilder # :nodoc:
|
7
|
+
attr_reader :object
|
8
|
+
|
9
|
+
def initialize(template_object, object_name, method_name, object, tag_value)
|
10
|
+
@template_object = template_object
|
11
|
+
@object_name = object_name
|
12
|
+
@method_name = method_name
|
13
|
+
@object = object
|
14
|
+
@tag_value = tag_value
|
15
|
+
end
|
16
|
+
|
17
|
+
def translation
|
18
|
+
method_and_value = @tag_value.present? ? "#{@method_name}.#{@tag_value}" : @method_name
|
19
|
+
|
20
|
+
content ||= Translator
|
21
|
+
.new(object, @object_name, method_and_value, scope: "helpers.label")
|
22
|
+
.translate
|
23
|
+
content ||= @method_name.humanize
|
24
|
+
|
25
|
+
content
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(object_name, method_name, template_object, content_or_options = nil, options = nil)
|
30
|
+
options ||= {}
|
31
|
+
|
32
|
+
content_is_options = content_or_options.is_a?(Hash)
|
33
|
+
if content_is_options
|
34
|
+
options.merge! content_or_options
|
35
|
+
@content = nil
|
36
|
+
else
|
37
|
+
@content = content_or_options
|
38
|
+
end
|
39
|
+
|
40
|
+
super(object_name, method_name, template_object, options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def render(&block)
|
44
|
+
options = @options.stringify_keys
|
45
|
+
tag_value = options.delete("value")
|
46
|
+
name_and_id = options.dup
|
47
|
+
|
48
|
+
if name_and_id["for"]
|
49
|
+
name_and_id["id"] = name_and_id["for"]
|
50
|
+
else
|
51
|
+
name_and_id.delete("id")
|
52
|
+
end
|
53
|
+
|
54
|
+
add_default_name_and_id_for_value(tag_value, name_and_id)
|
55
|
+
options.delete("index")
|
56
|
+
options.delete("namespace")
|
57
|
+
options["for"] = name_and_id["id"] unless options.key?("for")
|
58
|
+
|
59
|
+
builder = LabelBuilder.new(@template_object, @object_name, @method_name, @object, tag_value)
|
60
|
+
|
61
|
+
content = if block_given?
|
62
|
+
@template_object.capture(builder, &block)
|
63
|
+
elsif @content.present?
|
64
|
+
@content.to_s
|
65
|
+
else
|
66
|
+
render_component(builder)
|
67
|
+
end
|
68
|
+
|
69
|
+
label_tag(name_and_id["id"], content, options)
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
def render_component(builder)
|
74
|
+
builder.translation
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/helpers/tags/placeholderable"
|
4
|
+
|
5
|
+
module Arara
|
6
|
+
module Tags # :nodoc:
|
7
|
+
class PasswordField < TextField # :nodoc:
|
8
|
+
include ActionView::Helpers::Tags::Placeholderable
|
9
|
+
|
10
|
+
def render
|
11
|
+
@options = { value: nil }.merge!(@options)
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/helpers/tags/checkable"
|
4
|
+
|
5
|
+
module Arara
|
6
|
+
module Tags # :nodoc:
|
7
|
+
class RadioButton < ActionView::Helpers::Tags::Base # :nodoc:
|
8
|
+
include ActionView::Helpers::Tags::Checkable
|
9
|
+
|
10
|
+
def initialize(object_name, method_name, template_object, tag_value, options)
|
11
|
+
@tag_value = tag_value
|
12
|
+
super(object_name, method_name, template_object, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
options = @options.stringify_keys
|
17
|
+
options["type"] = "radio"
|
18
|
+
options["value"] = @tag_value
|
19
|
+
options["checked"] = "checked" if input_checked?(options)
|
20
|
+
add_default_name_and_id_for_value(@tag_value, options)
|
21
|
+
|
22
|
+
@template_object.template.render(Arara::RadioButtonComponent, options.symbolize_keys)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def checked?(value)
|
27
|
+
value.to_s == @tag_value.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,120 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Arara
|
4
|
+
module Tags # :nodoc:
|
5
|
+
class Select < ActionView::Helpers::Tags::Base # :nodoc:
|
6
|
+
def initialize(object_name, method_name, template_object, choices, options, html_options)
|
7
|
+
@choices = block_given? ? template_object.capture { yield || "" } : choices
|
8
|
+
@choices = @choices.to_a if @choices.is_a?(Range)
|
9
|
+
|
10
|
+
@html_options = html_options
|
11
|
+
|
12
|
+
super(object_name, method_name, template_object, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
option_tags_options = {
|
17
|
+
selected: @options.fetch(:selected) { value.to_s },
|
18
|
+
disabled: @options[:disabled]
|
19
|
+
}
|
20
|
+
|
21
|
+
option_tags = if grouped_choices?
|
22
|
+
grouped_options_for_select(@choices, option_tags_options)
|
23
|
+
else
|
24
|
+
options_for_select(@choices, option_tags_options)
|
25
|
+
end
|
26
|
+
|
27
|
+
if option_tags_options[:selected]
|
28
|
+
selected_element = @choices.select { |x| x[1].to_s == option_tags_options[:selected] }.first
|
29
|
+
if selected_element
|
30
|
+
selected_label = selected_element[0].to_s
|
31
|
+
selected_value = selected_element[1].to_s
|
32
|
+
end
|
33
|
+
@options.merge!(
|
34
|
+
selected_value: selected_value,
|
35
|
+
selected_label: selected_label,
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
select_content_tag(option_tags, @options, @html_options)
|
40
|
+
end
|
41
|
+
|
42
|
+
# def render
|
43
|
+
# option_tags_options = {
|
44
|
+
# selected: @options.fetch(:selected) { value.to_s },
|
45
|
+
# disabled: @options[:disabled]
|
46
|
+
# }
|
47
|
+
|
48
|
+
# option_tags = if grouped_choices?
|
49
|
+
# grouped_options_for_select(@choices, option_tags_options)
|
50
|
+
# else
|
51
|
+
# options_for_select(@choices, option_tags_options)
|
52
|
+
# end
|
53
|
+
|
54
|
+
# # select_content_tag(option_tags, @options, @html_options)
|
55
|
+
|
56
|
+
# @options.merge!(@html_options)
|
57
|
+
# @template_object.template.render(SelectComponent, @options.symbolize_keys) do
|
58
|
+
# option_tags
|
59
|
+
# end
|
60
|
+
# end
|
61
|
+
|
62
|
+
# my method
|
63
|
+
def options_for_select(container, selected = nil)
|
64
|
+
return container if String === container
|
65
|
+
|
66
|
+
selected, disabled = extract_selected_and_disabled(selected).map do |r|
|
67
|
+
Array(r).map(&:to_s)
|
68
|
+
end
|
69
|
+
|
70
|
+
container.map do |element|
|
71
|
+
html_attributes = option_html_attributes(element)
|
72
|
+
text, value = option_text_and_value(element).map(&:to_s)
|
73
|
+
|
74
|
+
html_attributes[:selected] ||= option_value_selected?(value, selected)
|
75
|
+
html_attributes[:disabled] ||= disabled && option_value_selected?(value, disabled)
|
76
|
+
html_attributes[:value] = value
|
77
|
+
|
78
|
+
# also set the label
|
79
|
+
html_attributes[:label] = text
|
80
|
+
|
81
|
+
# and render our component
|
82
|
+
@template_object.template.render(Arara::SelectItemComponent, html_attributes.symbolize_keys)
|
83
|
+
end.join("\n").html_safe
|
84
|
+
end
|
85
|
+
|
86
|
+
def select_content_tag(option_tags, options, html_options)
|
87
|
+
html_options = html_options.stringify_keys
|
88
|
+
add_default_name_and_id(html_options)
|
89
|
+
|
90
|
+
if placeholder_required?(html_options)
|
91
|
+
raise ArgumentError, "include_blank cannot be false for a required field." if options[:include_blank] == false
|
92
|
+
options[:include_blank] ||= true unless options[:prompt]
|
93
|
+
end
|
94
|
+
|
95
|
+
value = options.fetch(:selected) { value() }
|
96
|
+
select = content_tag("select", add_options(option_tags, options, value), html_options)
|
97
|
+
|
98
|
+
if html_options["multiple"] && options.fetch(:include_hidden, true)
|
99
|
+
tag("input", disabled: html_options["disabled"], name: html_options["name"], type: "hidden", value: "") + select
|
100
|
+
else
|
101
|
+
select
|
102
|
+
end
|
103
|
+
|
104
|
+
select_options = options.merge(html_options)
|
105
|
+
@template_object.template.render(Arara::SelectComponent, select_options.symbolize_keys) do
|
106
|
+
option_tags
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
private
|
111
|
+
# Grouped choices look like this:
|
112
|
+
#
|
113
|
+
# [nil, []]
|
114
|
+
# { nil => [] }
|
115
|
+
def grouped_choices?
|
116
|
+
!@choices.blank? && @choices.first.respond_to?(:last) && Array === @choices.first.last
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/helpers/tags/placeholderable"
|
4
|
+
|
5
|
+
module Arara
|
6
|
+
module Tags # :nodoc:
|
7
|
+
class TextArea < ActionView::Helpers::Tags::Base # :nodoc:
|
8
|
+
include ActionView::Helpers::Tags::Placeholderable
|
9
|
+
|
10
|
+
def render
|
11
|
+
options = @options.stringify_keys
|
12
|
+
add_default_name_and_id(options)
|
13
|
+
|
14
|
+
if size = options.delete("size")
|
15
|
+
options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split)
|
16
|
+
end
|
17
|
+
|
18
|
+
options["textarea"] = true
|
19
|
+
options["value"] = options.delete("value") { value_before_type_cast }
|
20
|
+
|
21
|
+
@template_object.template.render(Arara::TextFieldComponent, options.symbolize_keys)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "action_view/helpers/tags/placeholderable"
|
4
|
+
|
5
|
+
module Arara
|
6
|
+
module Tags # :nodoc:
|
7
|
+
class TextField < ActionView::Helpers::Tags::Base # :nodoc:
|
8
|
+
include ActionView::Helpers::Tags::Placeholderable
|
9
|
+
|
10
|
+
def render
|
11
|
+
options = @options.stringify_keys
|
12
|
+
options["size"] = options["maxlength"] unless options.key?("size")
|
13
|
+
options["type"] ||= field_type
|
14
|
+
options["value"] = options.fetch("value") { value_before_type_cast } unless field_type == "file"
|
15
|
+
add_default_name_and_id(options)
|
16
|
+
@template_object.template.render(Arara::TextFieldComponent, options.symbolize_keys)
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
def field_type
|
21
|
+
@field_type ||= name.split("::").last.sub("Field", "").downcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def field_type
|
27
|
+
self.class.field_type
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|