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,122 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # Uncomment this and change the path if necessary to include your own
4
+ # components.
5
+ # See https://github.com/heartcombo/simple_form#custom-components to know
6
+ # more about custom components.
7
+ # Dir[Rails.root.join('lib/components/**/*.rb')].each { |f| require f }
8
+ #
9
+ # Use this setup block to configure all options available in SimpleForm.
10
+ SimpleForm.setup do |config|
11
+ # Don't forget to edit this file to adapt it to your needs (specially
12
+ # all the grid-related classes)
13
+ #
14
+ # Please note that hints are commented out by default since Foundation
15
+ # doesn't provide styles for hints. You will need to provide your own CSS styles for hints.
16
+ # Uncomment them to enable hints.
17
+
18
+ config.wrappers :vertical_form, class: :input, hint_class: :field_with_hint, error_class: :error, valid_class: :valid do |b|
19
+ b.use :html5
20
+ b.use :placeholder
21
+ b.optional :maxlength
22
+ b.optional :minlength
23
+ b.optional :pattern
24
+ b.optional :min_max
25
+ b.optional :readonly
26
+ b.use :label_input
27
+ b.use :error, wrap_with: { tag: :small, class: :error }
28
+
29
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
30
+ end
31
+
32
+ config.wrappers :horizontal_form, tag: 'div', class: 'row', hint_class: :field_with_hint, error_class: :error, valid_class: :valid do |b|
33
+ b.use :html5
34
+ b.use :placeholder
35
+ b.optional :maxlength
36
+ b.optional :minlength
37
+ b.optional :pattern
38
+ b.optional :min_max
39
+ b.optional :readonly
40
+
41
+ b.wrapper :label_wrapper, tag: :div, class: 'small-3 columns' do |ba|
42
+ ba.use :label, class: 'text-right inline'
43
+ end
44
+
45
+ b.wrapper :right_input_wrapper, tag: :div, class: 'small-9 columns' do |ba|
46
+ ba.use :input
47
+ ba.use :error, wrap_with: { tag: :small, class: :error }
48
+ # ba.use :hint, wrap_with: { tag: :span, class: :hint }
49
+ end
50
+ end
51
+
52
+ config.wrappers :horizontal_radio_and_checkboxes, tag: 'div', class: 'row' do |b|
53
+ b.use :html5
54
+ b.optional :readonly
55
+
56
+ b.wrapper :container_wrapper, tag: 'div', class: 'small-offset-3 small-9 columns' do |ba|
57
+ ba.wrapper tag: 'label', class: 'checkbox' do |bb|
58
+ bb.use :input
59
+ bb.use :label_text
60
+ end
61
+
62
+ ba.use :error, wrap_with: { tag: :small, class: :error }
63
+ # ba.use :hint, wrap_with: { tag: :span, class: :hint }
64
+ end
65
+ end
66
+
67
+ # Foundation does not provide a way to handle inline forms
68
+ # This wrapper can be used to create an inline form
69
+ # by hiding that labels on every screen sizes ('hidden-for-small-up').
70
+ #
71
+ # Note that you need to adapt this wrapper to your needs. If you need a 4
72
+ # columns form then change the wrapper class to 'small-3', if you need
73
+ # only two use 'small-6' and so on.
74
+ config.wrappers :inline_form, tag: 'div', class: 'column small-4', hint_class: :field_with_hint, error_class: :error, valid_class: :valid do |b|
75
+ b.use :html5
76
+ b.use :placeholder
77
+ b.optional :maxlength
78
+ b.optional :minlength
79
+ b.optional :pattern
80
+ b.optional :min_max
81
+ b.optional :readonly
82
+
83
+ b.use :label, class: 'hidden-for-small-up'
84
+ b.use :input
85
+
86
+ b.use :error, wrap_with: { tag: :small, class: :error }
87
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
88
+ end
89
+
90
+ # Examples of use:
91
+ # - wrapper_html: {class: 'row'}, custom_wrapper_html: {class: 'column small-12'}
92
+ # - custom_wrapper_html: {class: 'column small-3 end'}
93
+ config.wrappers :customizable_wrapper, tag: 'div', error_class: :error, valid_class: :valid do |b|
94
+ b.use :html5
95
+ b.optional :readonly
96
+
97
+ b.wrapper :custom_wrapper, tag: :div do |ba|
98
+ ba.use :label_input
99
+ end
100
+
101
+ b.use :error, wrap_with: { tag: :small, class: :error }
102
+ # b.use :hint, wrap_with: { tag: :span, class: :hint }
103
+ end
104
+
105
+ # CSS class for buttons
106
+ config.button_class = 'button'
107
+
108
+ # Set this to div to make the checkbox and radio properly work
109
+ # otherwise simple_form adds a label tag instead of a div around
110
+ # the nested label
111
+ config.item_wrapper_tag = :div
112
+
113
+ # CSS class to add for error notification helper.
114
+ config.error_notification_class = 'alert-box alert'
115
+
116
+ # The default wrapper to be used by the FormBuilder.
117
+ config.default_wrapper = :vertical_form
118
+
119
+ # Defines validation classes to the input_field. By default it's nil.
120
+ # config.input_field_valid_class = 'is-valid'
121
+ # config.input_field_error_class = 'is-invalid'
122
+ end
@@ -0,0 +1,31 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
4
+ "no": 'No'
5
+ required:
6
+ text: 'required'
7
+ mark: '*'
8
+ # You can uncomment the line below if you need to overwrite the whole required html.
9
+ # When using html, text and mark won't be used.
10
+ # html: '<abbr title="required">*</abbr>'
11
+ error_notification:
12
+ default_message: "Please review the problems below:"
13
+ # Examples
14
+ # labels:
15
+ # defaults:
16
+ # password: 'Password'
17
+ # user:
18
+ # new:
19
+ # email: 'E-mail to sign in.'
20
+ # edit:
21
+ # email: 'E-mail.'
22
+ # hints:
23
+ # defaults:
24
+ # username: 'User name to sign in.'
25
+ # password: 'No special characters, please.'
26
+ # include_blanks:
27
+ # defaults:
28
+ # age: 'Rather not say'
29
+ # prompts:
30
+ # defaults:
31
+ # age: 'Select your age'
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module ActionViewExtensions
4
+ # A collection of methods required by simple_form but added to rails default form.
5
+ # This means that you can use such methods outside simple_form context.
6
+ module Builder
7
+
8
+ # Wrapper for using SimpleForm inside a default rails form.
9
+ # Example:
10
+ #
11
+ # form_for @user do |f|
12
+ # f.simple_fields_for :posts do |posts_form|
13
+ # # Here you have all simple_form methods available
14
+ # posts_form.input :title
15
+ # end
16
+ # end
17
+ def simple_fields_for(*args, &block)
18
+ options = args.extract_options!
19
+ options[:wrapper] = self.options[:wrapper] if options[:wrapper].nil?
20
+ options[:defaults] ||= self.options[:defaults]
21
+ options[:wrapper_mappings] ||= self.options[:wrapper_mappings]
22
+
23
+ if self.class < ActionView::Helpers::FormBuilder
24
+ options[:builder] ||= self.class
25
+ else
26
+ options[:builder] ||= SimpleForm::FormBuilder
27
+ end
28
+ fields_for(*args, options, &block)
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ module ActionView::Helpers
35
+ class FormBuilder
36
+ include SimpleForm::ActionViewExtensions::Builder
37
+ end
38
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module ActionViewExtensions
4
+ # This module creates SimpleForm wrappers around default form_for and fields_for.
5
+ #
6
+ # Example:
7
+ #
8
+ # simple_form_for @user do |f|
9
+ # f.input :name, hint: 'My hint'
10
+ # end
11
+ #
12
+ module FormHelper
13
+
14
+ def simple_form_for(record, options = {}, &block)
15
+ options[:builder] ||= SimpleForm::FormBuilder
16
+ options[:html] ||= {}
17
+ unless options[:html].key?(:novalidate)
18
+ options[:html][:novalidate] = !SimpleForm.browser_validations
19
+ end
20
+ if options[:html].key?(:class)
21
+ options[:html][:class] = [SimpleForm.form_class, options[:html][:class]].compact
22
+ else
23
+ options[:html][:class] = [SimpleForm.form_class, SimpleForm.default_form_class, simple_form_css_class(record, options)].compact
24
+ end
25
+
26
+ with_simple_form_field_error_proc do
27
+ form_for(record, options, &block)
28
+ end
29
+ end
30
+
31
+ def simple_fields_for(record_name, record_object = nil, options = {}, &block)
32
+ options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
33
+ options[:builder] ||= SimpleForm::FormBuilder
34
+
35
+ with_simple_form_field_error_proc do
36
+ fields_for(record_name, record_object, options, &block)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def with_simple_form_field_error_proc
43
+ default_field_error_proc = ::ActionView::Base.field_error_proc
44
+ begin
45
+ ::ActionView::Base.field_error_proc = SimpleForm.field_error_proc
46
+ yield
47
+ ensure
48
+ ::ActionView::Base.field_error_proc = default_field_error_proc
49
+ end
50
+ end
51
+
52
+ def simple_form_css_class(record, options)
53
+ html_options = options[:html]
54
+ as = options[:as]
55
+
56
+ if html_options.key?(:class)
57
+ html_options[:class]
58
+ elsif record.is_a?(String) || record.is_a?(Symbol)
59
+ as || record
60
+ else
61
+ record = record.last if record.is_a?(Array)
62
+ action = record.respond_to?(:persisted?) && record.persisted? ? :edit : :new
63
+ as ? "#{action}_#{as}" : dom_class(record, action)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+
70
+ ActiveSupport.on_load(:action_view) do
71
+ include SimpleForm::ActionViewExtensions::FormHelper
72
+ end
@@ -0,0 +1,74 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ module Errors
5
+ def error(wrapper_options = nil)
6
+ error_text if has_errors?
7
+ end
8
+
9
+ def full_error(wrapper_options = nil)
10
+ full_error_text if options[:error] != false && has_errors?
11
+ end
12
+
13
+ def has_errors?
14
+ object_with_errors? || !object && has_custom_error?
15
+ end
16
+
17
+ def has_value?
18
+ object && object.respond_to?(attribute_name) && object.send(attribute_name).present?
19
+ end
20
+
21
+ def valid?
22
+ !has_errors? && has_value?
23
+ end
24
+
25
+ protected
26
+
27
+ def error_text
28
+ text = has_custom_error? ? options[:error] : errors.send(error_method)
29
+
30
+ "#{html_escape(options[:error_prefix])} #{html_escape(text)}".lstrip.html_safe
31
+ end
32
+
33
+ def full_error_text
34
+ has_custom_error? ? options[:error] : full_errors.send(error_method)
35
+ end
36
+
37
+ def object_with_errors?
38
+ object && object.respond_to?(:errors) && errors.present?
39
+ end
40
+
41
+ def error_method
42
+ options[:error_method] || SimpleForm.error_method
43
+ end
44
+
45
+ def errors
46
+ @errors ||= (errors_on_attribute + errors_on_association).compact
47
+ end
48
+
49
+ def full_errors
50
+ @full_errors ||= (full_errors_on_attribute + full_errors_on_association).compact
51
+ end
52
+
53
+ def errors_on_attribute
54
+ object.errors[attribute_name] || []
55
+ end
56
+
57
+ def full_errors_on_attribute
58
+ object.errors.full_messages_for(attribute_name)
59
+ end
60
+
61
+ def errors_on_association
62
+ reflection ? object.errors[reflection.name] : []
63
+ end
64
+
65
+ def full_errors_on_association
66
+ reflection ? object.errors.full_messages_for(reflection.name) : []
67
+ end
68
+
69
+ def has_custom_error?
70
+ options[:error].is_a?(String)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Hints
6
+ def hint(wrapper_options = nil)
7
+ @hint ||= begin
8
+ hint = options[:hint]
9
+
10
+ if hint.is_a?(String)
11
+ html_escape(hint)
12
+ else
13
+ content = translate_from_namespace(:hints)
14
+ content.html_safe if content
15
+ end
16
+ end
17
+ end
18
+
19
+ def has_hint?
20
+ options[:hint] != false && hint.present?
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ module HTML5
5
+ def initialize(*)
6
+ @html5 = false
7
+ end
8
+
9
+ def html5(wrapper_options = nil)
10
+ @html5 = true
11
+
12
+ input_html_options[:required] = input_html_required_option
13
+ input_html_options[:'aria-invalid'] = has_errors? || nil
14
+ nil
15
+ end
16
+
17
+ def html5?
18
+ @html5
19
+ end
20
+
21
+ def input_html_required_option
22
+ !options[:required].nil? ? required_field? : has_required?
23
+ end
24
+
25
+ def has_required?
26
+ # We need to check browser_validations because
27
+ # some browsers are still checking required even
28
+ # if novalidate was given.
29
+ required_field? && SimpleForm.browser_validations
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ module LabelInput
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ include SimpleForm::Components::Labels
9
+ end
10
+
11
+ def label_input(wrapper_options = nil)
12
+ if options[:label] == false
13
+ deprecated_component(:input, wrapper_options)
14
+ else
15
+ deprecated_component(:label, wrapper_options) + deprecated_component(:input, wrapper_options)
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def deprecated_component(namespace, wrapper_options)
22
+ method = method(namespace)
23
+
24
+ if method.arity.zero?
25
+ SimpleForm.deprecator.warn(SimpleForm::CUSTOM_INPUT_DEPRECATION_WARN % { name: namespace })
26
+
27
+ method.call
28
+ else
29
+ method.call(wrapper_options)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ module Labels
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods #:nodoc:
8
+ def translate_required_html
9
+ I18n.t(:"required.html", scope: i18n_scope, default:
10
+ %(<abbr title="#{translate_required_text}">#{translate_required_mark}</abbr>)
11
+ )
12
+ end
13
+
14
+ def translate_required_text
15
+ I18n.t(:"required.text", scope: i18n_scope, default: 'required')
16
+ end
17
+
18
+ def translate_required_mark
19
+ I18n.t(:"required.mark", scope: i18n_scope, default: '*')
20
+ end
21
+
22
+ private
23
+
24
+ def i18n_scope
25
+ SimpleForm.i18n_scope
26
+ end
27
+ end
28
+
29
+ def label(wrapper_options = nil)
30
+ label_options = merge_wrapper_options(label_html_options, wrapper_options)
31
+
32
+ if generate_label_for_attribute?
33
+ @builder.label(label_target, label_text, label_options)
34
+ else
35
+ template.label_tag(nil, label_text, label_options)
36
+ end
37
+ end
38
+
39
+ def label_text(wrapper_options = nil)
40
+ label_text = options[:label_text] || SimpleForm.label_text
41
+ label_text.call(html_escape(raw_label_text), required_label_text, options[:label].present?).strip.html_safe
42
+ end
43
+
44
+ def label_target
45
+ attribute_name
46
+ end
47
+
48
+ def label_html_options
49
+ label_html_classes = SimpleForm.additional_classes_for(:label) {
50
+ [input_type, required_class, disabled_class, SimpleForm.label_class].compact
51
+ }
52
+
53
+ label_options = html_options_for(:label, label_html_classes)
54
+ if options.key?(:input_html) && options[:input_html].key?(:id)
55
+ label_options[:for] = options[:input_html][:id]
56
+ end
57
+
58
+ label_options
59
+ end
60
+
61
+ protected
62
+
63
+ def raw_label_text #:nodoc:
64
+ options[:label] || label_translation
65
+ end
66
+
67
+ # Default required text when attribute is required.
68
+ def required_label_text #:nodoc:
69
+ required_field? ? self.class.translate_required_html.dup : ''
70
+ end
71
+
72
+ # First check labels translation and then human attribute name.
73
+ def label_translation #:nodoc:
74
+ if SimpleForm.translate_labels && (translated_label = translate_from_namespace(:labels))
75
+ translated_label
76
+ elsif object.class.respond_to?(:human_attribute_name)
77
+ object.class.human_attribute_name(reflection_or_attribute_name.to_s, { base: object })
78
+ else
79
+ attribute_name.to_s.humanize
80
+ end
81
+ end
82
+
83
+ def generate_label_for_attribute?
84
+ true
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Maxlength
6
+ def maxlength(wrapper_options = nil)
7
+ input_html_options[:maxlength] ||= maximum_length_from_validation || limit
8
+ nil
9
+ end
10
+
11
+ private
12
+
13
+ def maximum_length_from_validation
14
+ maxlength = options[:maxlength]
15
+ if maxlength.is_a?(String) || maxlength.is_a?(Integer)
16
+ maxlength
17
+ else
18
+ length_validator = find_length_validator
19
+ maximum_length_value_from(length_validator)
20
+ end
21
+ end
22
+
23
+ def find_length_validator
24
+ find_validator(:length)
25
+ end
26
+
27
+ def maximum_length_value_from(length_validator)
28
+ if length_validator
29
+ value = length_validator.options[:is] || length_validator.options[:maximum]
30
+ resolve_validator_value(value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ module MinMax
5
+ def min_max(wrapper_options = nil)
6
+ if numeric_validator = find_numericality_validator
7
+ validator_options = numeric_validator.options
8
+ input_html_options[:min] ||= minimum_value(validator_options)
9
+ input_html_options[:max] ||= maximum_value(validator_options)
10
+ end
11
+ nil
12
+ end
13
+
14
+ private
15
+
16
+ def integer?
17
+ input_type == :integer
18
+ end
19
+
20
+ def minimum_value(validator_options)
21
+ if integer? && validator_options.key?(:greater_than)
22
+ resolve_validator_value(validator_options[:greater_than]) + 1
23
+ else
24
+ resolve_validator_value(validator_options[:greater_than_or_equal_to])
25
+ end
26
+ end
27
+
28
+ def maximum_value(validator_options)
29
+ if integer? && validator_options.key?(:less_than)
30
+ resolve_validator_value(validator_options[:less_than]) - 1
31
+ else
32
+ resolve_validator_value(validator_options[:less_than_or_equal_to])
33
+ end
34
+ end
35
+
36
+ def find_numericality_validator
37
+ find_validator(:numericality)
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Minlength
6
+ def minlength(wrapper_options = nil)
7
+ input_html_options[:minlength] ||= minimum_length_from_validation
8
+ nil
9
+ end
10
+
11
+ private
12
+
13
+ def minimum_length_from_validation
14
+ minlength = options[:minlength]
15
+ if minlength.is_a?(String) || minlength.is_a?(Integer)
16
+ minlength
17
+ else
18
+ length_validator = find_length_validator
19
+ minimum_length_value_from(length_validator)
20
+ end
21
+ end
22
+
23
+ def find_length_validator
24
+ find_validator(:length)
25
+ end
26
+
27
+ def minimum_length_value_from(length_validator)
28
+ if length_validator
29
+ value = length_validator.options[:is] || length_validator.options[:minimum]
30
+ resolve_validator_value(value)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Pattern
6
+ def pattern(wrapper_options = nil)
7
+ input_html_options[:pattern] ||= pattern_source
8
+ nil
9
+ end
10
+
11
+ private
12
+
13
+ def pattern_source
14
+ pattern = options[:pattern]
15
+ if pattern.is_a?(String)
16
+ pattern
17
+ elsif (pattern_validator = find_pattern_validator) && (with = pattern_validator.options[:with])
18
+ resolve_validator_value(with).source
19
+ end
20
+ end
21
+
22
+ def find_pattern_validator
23
+ find_validator(:format)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Placeholders
6
+ def placeholder(wrapper_options = nil)
7
+ input_html_options[:placeholder] ||= placeholder_text
8
+ nil
9
+ end
10
+
11
+ def placeholder_text(wrapper_options = nil)
12
+ placeholder = options[:placeholder]
13
+ placeholder.is_a?(String) ? placeholder : translate_from_namespace(:placeholders)
14
+ end
15
+ end
16
+ end
17
+ end