mini-sharp-mod 0.0.1

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 (70) hide show
  1. checksums.yaml +7 -0
  2. data/mini-sharp-mod.gemspec +12 -0
  3. data/simple_form-5.4.1/CHANGELOG.md +259 -0
  4. data/simple_form-5.4.1/MIT-LICENSE +21 -0
  5. data/simple_form-5.4.1/README.md +1334 -0
  6. data/simple_form-5.4.1/lib/generators/simple_form/USAGE +3 -0
  7. data/simple_form-5.4.1/lib/generators/simple_form/install_generator.rb +42 -0
  8. data/simple_form-5.4.1/lib/generators/simple_form/templates/README +10 -0
  9. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.erb +15 -0
  10. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.haml +12 -0
  11. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.slim +11 -0
  12. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form.rb +176 -0
  13. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +372 -0
  14. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +122 -0
  15. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +31 -0
  16. data/simple_form-5.4.1/lib/simple_form/action_view_extensions/builder.rb +38 -0
  17. data/simple_form-5.4.1/lib/simple_form/action_view_extensions/form_helper.rb +72 -0
  18. data/simple_form-5.4.1/lib/simple_form/components/errors.rb +74 -0
  19. data/simple_form-5.4.1/lib/simple_form/components/hints.rb +24 -0
  20. data/simple_form-5.4.1/lib/simple_form/components/html5.rb +33 -0
  21. data/simple_form-5.4.1/lib/simple_form/components/label_input.rb +34 -0
  22. data/simple_form-5.4.1/lib/simple_form/components/labels.rb +88 -0
  23. data/simple_form-5.4.1/lib/simple_form/components/maxlength.rb +35 -0
  24. data/simple_form-5.4.1/lib/simple_form/components/min_max.rb +41 -0
  25. data/simple_form-5.4.1/lib/simple_form/components/minlength.rb +35 -0
  26. data/simple_form-5.4.1/lib/simple_form/components/pattern.rb +27 -0
  27. data/simple_form-5.4.1/lib/simple_form/components/placeholders.rb +17 -0
  28. data/simple_form-5.4.1/lib/simple_form/components/readonly.rb +23 -0
  29. data/simple_form-5.4.1/lib/simple_form/components.rb +24 -0
  30. data/simple_form-5.4.1/lib/simple_form/error_notification.rb +49 -0
  31. data/simple_form-5.4.1/lib/simple_form/form_builder.rb +723 -0
  32. data/simple_form-5.4.1/lib/simple_form/helpers/autofocus.rb +12 -0
  33. data/simple_form-5.4.1/lib/simple_form/helpers/disabled.rb +16 -0
  34. data/simple_form-5.4.1/lib/simple_form/helpers/readonly.rb +16 -0
  35. data/simple_form-5.4.1/lib/simple_form/helpers/required.rb +36 -0
  36. data/simple_form-5.4.1/lib/simple_form/helpers/validators.rb +66 -0
  37. data/simple_form-5.4.1/lib/simple_form/helpers.rb +13 -0
  38. data/simple_form-5.4.1/lib/simple_form/inputs/base.rb +232 -0
  39. data/simple_form-5.4.1/lib/simple_form/inputs/block_input.rb +15 -0
  40. data/simple_form-5.4.1/lib/simple_form/inputs/boolean_input.rb +108 -0
  41. data/simple_form-5.4.1/lib/simple_form/inputs/collection_check_boxes_input.rb +22 -0
  42. data/simple_form-5.4.1/lib/simple_form/inputs/collection_input.rb +122 -0
  43. data/simple_form-5.4.1/lib/simple_form/inputs/collection_radio_buttons_input.rb +59 -0
  44. data/simple_form-5.4.1/lib/simple_form/inputs/collection_select_input.rb +17 -0
  45. data/simple_form-5.4.1/lib/simple_form/inputs/color_input.rb +14 -0
  46. data/simple_form-5.4.1/lib/simple_form/inputs/date_time_input.rb +39 -0
  47. data/simple_form-5.4.1/lib/simple_form/inputs/file_input.rb +12 -0
  48. data/simple_form-5.4.1/lib/simple_form/inputs/grouped_collection_select_input.rb +54 -0
  49. data/simple_form-5.4.1/lib/simple_form/inputs/hidden_input.rb +20 -0
  50. data/simple_form-5.4.1/lib/simple_form/inputs/numeric_input.rb +20 -0
  51. data/simple_form-5.4.1/lib/simple_form/inputs/password_input.rb +14 -0
  52. data/simple_form-5.4.1/lib/simple_form/inputs/priority_input.rb +37 -0
  53. data/simple_form-5.4.1/lib/simple_form/inputs/range_input.rb +15 -0
  54. data/simple_form-5.4.1/lib/simple_form/inputs/rich_text_area_input.rb +14 -0
  55. data/simple_form-5.4.1/lib/simple_form/inputs/string_input.rb +25 -0
  56. data/simple_form-5.4.1/lib/simple_form/inputs/text_input.rb +14 -0
  57. data/simple_form-5.4.1/lib/simple_form/inputs/weekday_input.rb +14 -0
  58. data/simple_form-5.4.1/lib/simple_form/inputs.rb +27 -0
  59. data/simple_form-5.4.1/lib/simple_form/map_type.rb +17 -0
  60. data/simple_form-5.4.1/lib/simple_form/railtie.rb +19 -0
  61. data/simple_form-5.4.1/lib/simple_form/tags.rb +73 -0
  62. data/simple_form-5.4.1/lib/simple_form/version.rb +4 -0
  63. data/simple_form-5.4.1/lib/simple_form/wrappers/builder.rb +80 -0
  64. data/simple_form-5.4.1/lib/simple_form/wrappers/leaf.rb +29 -0
  65. data/simple_form-5.4.1/lib/simple_form/wrappers/many.rb +74 -0
  66. data/simple_form-5.4.1/lib/simple_form/wrappers/root.rb +43 -0
  67. data/simple_form-5.4.1/lib/simple_form/wrappers/single.rb +27 -0
  68. data/simple_form-5.4.1/lib/simple_form/wrappers.rb +10 -0
  69. data/simple_form-5.4.1/lib/simple_form.rb +340 -0
  70. metadata +109 -0
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class CollectionRadioButtonsInput < CollectionInput
5
+ def input(wrapper_options = nil)
6
+ label_method, value_method = detect_collection_methods
7
+
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.send(:"collection_#{input_type}",
11
+ attribute_name, collection, value_method, label_method,
12
+ input_options, merged_input_options,
13
+ &collection_block_for_nested_boolean_style
14
+ )
15
+ end
16
+
17
+ def input_options
18
+ options = super
19
+ apply_default_collection_options!(options)
20
+ options
21
+ end
22
+
23
+ protected
24
+
25
+ def apply_default_collection_options!(options)
26
+ options[:item_wrapper_tag] ||= options.fetch(:item_wrapper_tag, SimpleForm.item_wrapper_tag)
27
+ options[:item_wrapper_class] = [
28
+ item_wrapper_class, options[:item_wrapper_class], SimpleForm.item_wrapper_class
29
+ ].compact.presence if SimpleForm.include_default_input_wrapper_class
30
+
31
+ options[:collection_wrapper_tag] ||= options.fetch(:collection_wrapper_tag, SimpleForm.collection_wrapper_tag)
32
+ options[:collection_wrapper_class] = [
33
+ options[:collection_wrapper_class], SimpleForm.collection_wrapper_class
34
+ ].compact.presence
35
+ end
36
+
37
+ def collection_block_for_nested_boolean_style
38
+ return unless nested_boolean_style?
39
+
40
+ proc { |builder| build_nested_boolean_style_item_tag(builder) }
41
+ end
42
+
43
+ def build_nested_boolean_style_item_tag(collection_builder)
44
+ collection_builder.radio_button + collection_builder.text.to_s
45
+ end
46
+
47
+ def item_wrapper_class
48
+ "radio"
49
+ end
50
+
51
+ # Do not attempt to generate label[for] attributes by default, unless an
52
+ # explicit html option is given. This avoids generating labels pointing to
53
+ # non existent fields.
54
+ def generate_label_for_attribute?
55
+ false
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class CollectionSelectInput < CollectionInput
5
+ def input(wrapper_options = nil)
6
+ label_method, value_method = detect_collection_methods
7
+
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.collection_select(
11
+ attribute_name, collection, value_method, label_method,
12
+ input_options, merged_input_options
13
+ )
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class ColorInput < Base
5
+ def input(wrapper_options = nil)
6
+ input_html_options[:type] ||= "color" if html5?
7
+
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.text_field(attribute_name, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class DateTimeInput < Base
5
+ def input(wrapper_options = nil)
6
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
+
8
+ if use_html5_inputs?
9
+ @builder.send(:"#{input_type}_field", attribute_name, merged_input_options)
10
+ else
11
+ @builder.send(:"#{input_type}_select", attribute_name, input_options, merged_input_options)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def label_target
18
+ if use_html5_inputs?
19
+ attribute_name
20
+ else
21
+ position = case input_type
22
+ when :date, :datetime
23
+ date_order = input_options[:order] || I18n.t('date.order')
24
+ date_order.first.to_sym
25
+ else
26
+ :hour
27
+ end
28
+
29
+ position = ActionView::Helpers::DateTimeSelector::POSITION[position]
30
+ "#{attribute_name}_#{position}i"
31
+ end
32
+ end
33
+
34
+ def use_html5_inputs?
35
+ input_options[:html5]
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class FileInput < Base
5
+ def input(wrapper_options = nil)
6
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
+
8
+ @builder.file_field(attribute_name, merged_input_options)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class GroupedCollectionSelectInput < CollectionInput
5
+ def input(wrapper_options = nil)
6
+ label_method, value_method = detect_collection_methods
7
+
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.grouped_collection_select(attribute_name, grouped_collection,
11
+ group_method, group_label_method, value_method, label_method,
12
+ input_options, merged_input_options)
13
+ end
14
+
15
+ private
16
+
17
+ def grouped_collection
18
+ @grouped_collection ||= begin
19
+ grouped_collection = options.delete(:collection)
20
+ grouped_collection.respond_to?(:call) ? grouped_collection.call : grouped_collection.to_a
21
+ end
22
+ end
23
+
24
+ # Sample collection
25
+ def collection
26
+ @collection ||= grouped_collection.map { |collection| group_method.respond_to?(:call) ? group_method.call(collection) : collection.try(:send, group_method) }.detect(&:present?) || []
27
+ end
28
+
29
+ def group_method
30
+ @group_method ||= options.delete(:group_method)
31
+ end
32
+
33
+ def group_label_method
34
+ label = options.delete(:group_label_method)
35
+
36
+ unless label
37
+ common_method_for = detect_common_display_methods(detect_collection_classes(grouped_collection))
38
+ label = common_method_for[:label]
39
+ end
40
+
41
+ label
42
+ end
43
+
44
+ def detect_method_from_class(collection_classes)
45
+ return {} if collection_classes.empty?
46
+
47
+ sample = collection_classes.first
48
+
49
+ { label: SimpleForm.collection_label_methods.find { |m| sample.instance_methods.include?(m) },
50
+ value: SimpleForm.collection_value_methods.find { |m| sample.instance_methods.include?(m) } }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class HiddenInput < Base
5
+ disable :label, :errors, :hint, :required
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.hidden_field(attribute_name, merged_input_options)
11
+ end
12
+
13
+ private
14
+
15
+ def required_class
16
+ nil
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class NumericInput < Base
5
+ enable :placeholder, :min_max
6
+
7
+ def input(wrapper_options = nil)
8
+ input_html_classes.unshift("numeric")
9
+ if html5?
10
+ input_html_options[:type] ||= "number"
11
+ input_html_options[:step] ||= integer? ? 1 : "any"
12
+ end
13
+
14
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
15
+
16
+ @builder.text_field(attribute_name, merged_input_options)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class PasswordInput < Base
5
+ enable :placeholder, :maxlength, :minlength
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.password_field(attribute_name, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class PriorityInput < CollectionSelectInput
5
+ def input(wrapper_options = nil)
6
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
7
+
8
+ send(:"#{input_type}_input", merged_input_options)
9
+ end
10
+
11
+ def input_priority
12
+ options[:priority] || SimpleForm.send(:"#{input_type}_priority")
13
+ end
14
+
15
+ protected
16
+
17
+ def country_input(merged_input_options)
18
+ @builder.send(:country_select,
19
+ attribute_name,
20
+ input_options.merge(priority_countries: input_priority),
21
+ merged_input_options)
22
+ end
23
+
24
+ def time_zone_input(merged_input_options)
25
+ @builder.send(:time_zone_select,
26
+ attribute_name,
27
+ input_priority,
28
+ input_options,
29
+ merged_input_options)
30
+ end
31
+
32
+ def skip_include_blank?
33
+ super || input_priority.present?
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class RangeInput < NumericInput
5
+ def input(wrapper_options = nil)
6
+ if html5?
7
+ input_html_options[:type] ||= "range"
8
+ input_html_options[:step] ||= 1
9
+ end
10
+
11
+ super
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class RichTextAreaInput < Base
5
+ enable :placeholder
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.rich_text_area(attribute_name, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class StringInput < Base
5
+ enable :placeholder, :maxlength, :minlength, :pattern
6
+
7
+ def input(wrapper_options = nil)
8
+ unless string?
9
+ input_html_classes.unshift("string")
10
+ input_html_options[:type] ||= input_type if html5?
11
+ end
12
+
13
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
14
+
15
+ @builder.text_field(attribute_name, merged_input_options)
16
+ end
17
+
18
+ private
19
+
20
+ def string?
21
+ input_type == :string || input_type == :citext
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class TextInput < Base
5
+ enable :placeholder, :maxlength, :minlength
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.text_area(attribute_name, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ class WeekdayInput < CollectionSelectInput
5
+ enable :placeholder
6
+
7
+ def input(wrapper_options = nil)
8
+ merged_input_options = merge_wrapper_options(input_html_options, wrapper_options)
9
+
10
+ @builder.weekday_select(attribute_name, input_options, merged_input_options)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Inputs
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Base
7
+ autoload :BlockInput
8
+ autoload :BooleanInput
9
+ autoload :CollectionCheckBoxesInput
10
+ autoload :CollectionInput
11
+ autoload :CollectionRadioButtonsInput
12
+ autoload :CollectionSelectInput
13
+ autoload :ColorInput
14
+ autoload :DateTimeInput
15
+ autoload :FileInput
16
+ autoload :GroupedCollectionSelectInput
17
+ autoload :HiddenInput
18
+ autoload :NumericInput
19
+ autoload :PasswordInput
20
+ autoload :PriorityInput
21
+ autoload :RangeInput
22
+ autoload :RichTextAreaInput
23
+ autoload :StringInput
24
+ autoload :TextInput
25
+ autoload :WeekdayInput
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/core_ext/class/attribute'
3
+
4
+ module SimpleForm
5
+ module MapType
6
+ def self.extended(base)
7
+ base.class_attribute :mappings
8
+ base.mappings = {}
9
+ end
10
+
11
+ def map_type(*types)
12
+ map_to = types.extract_options![:to]
13
+ raise ArgumentError, "You need to give :to as option to map_type" unless map_to
14
+ self.mappings = mappings.merge types.each_with_object({}) { |t, m| m[t] = map_to }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'rails/railtie'
3
+
4
+ module SimpleForm
5
+ class Railtie < Rails::Railtie
6
+ config.eager_load_namespaces << SimpleForm
7
+
8
+ config.after_initialize do
9
+ unless SimpleForm.configured?
10
+ warn '[Simple Form] Simple Form is not configured in the application and will use the default values.' +
11
+ ' Use `rails generate simple_form:install` to generate the Simple Form configuration.'
12
+ end
13
+ end
14
+
15
+ initializer "simple_form.deprecator" do |app|
16
+ app.deprecators[:simple_form] = SimpleForm.deprecator if app.respond_to?(:deprecators)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Tags
4
+ module CollectionExtensions
5
+ private
6
+
7
+ def render_collection
8
+ item_wrapper_tag = @options.fetch(:item_wrapper_tag, :span)
9
+ item_wrapper_class = @options[:item_wrapper_class]
10
+
11
+ @collection.map do |item|
12
+ value = value_for_collection(item, @value_method)
13
+ text = value_for_collection(item, @text_method)
14
+ default_html_options = default_html_options_for_collection(item, value)
15
+ additional_html_options = option_html_attributes(item)
16
+
17
+ rendered_item = yield item, value, text, default_html_options.merge(additional_html_options)
18
+
19
+ if @options.fetch(:boolean_style, SimpleForm.boolean_style) == :nested
20
+ label_options = default_html_options.slice(:index, :namespace)
21
+ label_options['class'] = @options[:item_label_class]
22
+ rendered_item = @template_object.label(@object_name, sanitize_attribute_name(value), rendered_item, label_options)
23
+ end
24
+
25
+ item_wrapper_tag ? @template_object.content_tag(item_wrapper_tag, rendered_item, class: item_wrapper_class) : rendered_item
26
+ end.join.html_safe
27
+ end
28
+
29
+ def wrap_rendered_collection(collection)
30
+ wrapper_tag = @options[:collection_wrapper_tag]
31
+
32
+ if wrapper_tag
33
+ wrapper_class = @options[:collection_wrapper_class]
34
+ @template_object.content_tag(wrapper_tag, collection, class: wrapper_class)
35
+ else
36
+ collection
37
+ end
38
+ end
39
+ end
40
+
41
+ class CollectionRadioButtons < ActionView::Helpers::Tags::CollectionRadioButtons
42
+ include CollectionExtensions
43
+
44
+ def render
45
+ wrap_rendered_collection(super)
46
+ end
47
+
48
+ private
49
+
50
+ def render_component(builder)
51
+ label_class = "#{@options[:item_label_class]} collection_radio_buttons".strip
52
+
53
+ builder.radio_button + builder.label(class: label_class)
54
+ end
55
+ end
56
+
57
+ class CollectionCheckBoxes < ActionView::Helpers::Tags::CollectionCheckBoxes
58
+ include CollectionExtensions
59
+
60
+ def render
61
+ wrap_rendered_collection(super)
62
+ end
63
+
64
+ private
65
+
66
+ def render_component(builder)
67
+ label_class = "#{@options[:item_label_class]} collection_check_boxes".strip
68
+
69
+ builder.check_box + builder.label(class: label_class)
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ VERSION = "5.4.1".freeze
4
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Wrappers
4
+ # Provides the builder syntax for components. The builder provides
5
+ # three methods `use`, `optional` and `wrapper` and they allow the following invocations:
6
+ #
7
+ # config.wrappers do |b|
8
+ # # Use a single component
9
+ # b.use :html5
10
+ #
11
+ # # Use the component, but do not automatically lookup. It will only be triggered when
12
+ # # :placeholder is explicitly set.
13
+ # b.optional :placeholder
14
+ #
15
+ # # Use a component with specific wrapper options
16
+ # b.use :error, wrap_with: { tag: "span", class: "error" }
17
+ #
18
+ # # Use a set of components by wrapping them in a tag+class.
19
+ # b.wrapper tag: "div", class: "another" do |ba|
20
+ # ba.use :label
21
+ # ba.use :input
22
+ # end
23
+ #
24
+ # # Use a set of components by wrapping them in a tag+class.
25
+ # # This wrapper is identified by :label_input, which means it can
26
+ # # be turned off on demand with `f.input :name, label_input: false`
27
+ # b.wrapper :label_input, tag: "div", class: "another" do |ba|
28
+ # ba.use :label
29
+ # ba.use :input
30
+ # end
31
+ # end
32
+ #
33
+ # The builder also accepts default options at the root level. This is usually
34
+ # used if you want a component to be disabled by default:
35
+ #
36
+ # config.wrappers hint: false do |b|
37
+ # b.use :hint
38
+ # b.use :label_input
39
+ # end
40
+ #
41
+ # In the example above, hint defaults to false, which means it won't automatically
42
+ # do the lookup anymore. It will only be triggered when :hint is explicitly set.
43
+ class Builder
44
+ def initialize(options)
45
+ @options = options
46
+ @components = []
47
+ end
48
+
49
+ def use(name, options = {})
50
+ if options && wrapper = options[:wrap_with]
51
+ @components << Single.new(name, wrapper, options.except(:wrap_with))
52
+ else
53
+ @components << Leaf.new(name, options)
54
+ end
55
+ end
56
+
57
+ def optional(name, options = {}, &block)
58
+ @options[name] = false
59
+ use(name, options)
60
+ end
61
+
62
+ def wrapper(name, options = nil)
63
+ if block_given?
64
+ name, options = nil, name if name.is_a?(Hash)
65
+ builder = self.class.new(@options)
66
+ options ||= {}
67
+ options[:tag] = :div if options[:tag].nil?
68
+ yield builder
69
+ @components << Many.new(name, builder.to_a, options)
70
+ else
71
+ raise ArgumentError, "A block is required as argument to wrapper"
72
+ end
73
+ end
74
+
75
+ def to_a
76
+ @components
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Wrappers
4
+ class Leaf
5
+ attr_reader :namespace
6
+
7
+ def initialize(namespace, options = {})
8
+ @namespace = namespace
9
+ @options = options
10
+ end
11
+
12
+ def render(input)
13
+ method = input.method(@namespace)
14
+
15
+ if method.arity.zero?
16
+ SimpleForm.deprecator.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: @namespace })
17
+
18
+ method.call
19
+ else
20
+ method.call(@options)
21
+ end
22
+ end
23
+
24
+ def find(name)
25
+ self if @namespace == name
26
+ end
27
+ end
28
+ end
29
+ end