tiny-smart-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/simple_form-5.4.1/CHANGELOG.md +259 -0
  3. data/simple_form-5.4.1/MIT-LICENSE +21 -0
  4. data/simple_form-5.4.1/README.md +1334 -0
  5. data/simple_form-5.4.1/lib/generators/simple_form/USAGE +3 -0
  6. data/simple_form-5.4.1/lib/generators/simple_form/install_generator.rb +190 -0
  7. data/simple_form-5.4.1/lib/generators/simple_form/templates/README +10 -0
  8. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.erb +15 -0
  9. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.haml +12 -0
  10. data/simple_form-5.4.1/lib/generators/simple_form/templates/_form.html.slim +11 -0
  11. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form.rb +176 -0
  12. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form_bootstrap.rb +372 -0
  13. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/initializers/simple_form_foundation.rb +122 -0
  14. data/simple_form-5.4.1/lib/generators/simple_form/templates/config/locales/simple_form.en.yml +31 -0
  15. data/simple_form-5.4.1/lib/simple_form/action_view_extensions/builder.rb +38 -0
  16. data/simple_form-5.4.1/lib/simple_form/action_view_extensions/form_helper.rb +72 -0
  17. data/simple_form-5.4.1/lib/simple_form/components/errors.rb +74 -0
  18. data/simple_form-5.4.1/lib/simple_form/components/hints.rb +24 -0
  19. data/simple_form-5.4.1/lib/simple_form/components/html5.rb +33 -0
  20. data/simple_form-5.4.1/lib/simple_form/components/label_input.rb +34 -0
  21. data/simple_form-5.4.1/lib/simple_form/components/labels.rb +88 -0
  22. data/simple_form-5.4.1/lib/simple_form/components/maxlength.rb +35 -0
  23. data/simple_form-5.4.1/lib/simple_form/components/min_max.rb +41 -0
  24. data/simple_form-5.4.1/lib/simple_form/components/minlength.rb +35 -0
  25. data/simple_form-5.4.1/lib/simple_form/components/pattern.rb +27 -0
  26. data/simple_form-5.4.1/lib/simple_form/components/placeholders.rb +17 -0
  27. data/simple_form-5.4.1/lib/simple_form/components/readonly.rb +23 -0
  28. data/simple_form-5.4.1/lib/simple_form/components.rb +24 -0
  29. data/simple_form-5.4.1/lib/simple_form/error_notification.rb +49 -0
  30. data/simple_form-5.4.1/lib/simple_form/form_builder.rb +723 -0
  31. data/simple_form-5.4.1/lib/simple_form/helpers/autofocus.rb +12 -0
  32. data/simple_form-5.4.1/lib/simple_form/helpers/disabled.rb +16 -0
  33. data/simple_form-5.4.1/lib/simple_form/helpers/readonly.rb +16 -0
  34. data/simple_form-5.4.1/lib/simple_form/helpers/required.rb +36 -0
  35. data/simple_form-5.4.1/lib/simple_form/helpers/validators.rb +66 -0
  36. data/simple_form-5.4.1/lib/simple_form/helpers.rb +13 -0
  37. data/simple_form-5.4.1/lib/simple_form/inputs/base.rb +232 -0
  38. data/simple_form-5.4.1/lib/simple_form/inputs/block_input.rb +15 -0
  39. data/simple_form-5.4.1/lib/simple_form/inputs/boolean_input.rb +108 -0
  40. data/simple_form-5.4.1/lib/simple_form/inputs/collection_check_boxes_input.rb +22 -0
  41. data/simple_form-5.4.1/lib/simple_form/inputs/collection_input.rb +122 -0
  42. data/simple_form-5.4.1/lib/simple_form/inputs/collection_radio_buttons_input.rb +59 -0
  43. data/simple_form-5.4.1/lib/simple_form/inputs/collection_select_input.rb +17 -0
  44. data/simple_form-5.4.1/lib/simple_form/inputs/color_input.rb +14 -0
  45. data/simple_form-5.4.1/lib/simple_form/inputs/date_time_input.rb +39 -0
  46. data/simple_form-5.4.1/lib/simple_form/inputs/file_input.rb +12 -0
  47. data/simple_form-5.4.1/lib/simple_form/inputs/grouped_collection_select_input.rb +54 -0
  48. data/simple_form-5.4.1/lib/simple_form/inputs/hidden_input.rb +20 -0
  49. data/simple_form-5.4.1/lib/simple_form/inputs/numeric_input.rb +20 -0
  50. data/simple_form-5.4.1/lib/simple_form/inputs/password_input.rb +14 -0
  51. data/simple_form-5.4.1/lib/simple_form/inputs/priority_input.rb +37 -0
  52. data/simple_form-5.4.1/lib/simple_form/inputs/range_input.rb +15 -0
  53. data/simple_form-5.4.1/lib/simple_form/inputs/rich_text_area_input.rb +14 -0
  54. data/simple_form-5.4.1/lib/simple_form/inputs/string_input.rb +25 -0
  55. data/simple_form-5.4.1/lib/simple_form/inputs/text_input.rb +14 -0
  56. data/simple_form-5.4.1/lib/simple_form/inputs/weekday_input.rb +14 -0
  57. data/simple_form-5.4.1/lib/simple_form/inputs.rb +27 -0
  58. data/simple_form-5.4.1/lib/simple_form/map_type.rb +17 -0
  59. data/simple_form-5.4.1/lib/simple_form/railtie.rb +19 -0
  60. data/simple_form-5.4.1/lib/simple_form/tags.rb +73 -0
  61. data/simple_form-5.4.1/lib/simple_form/version.rb +4 -0
  62. data/simple_form-5.4.1/lib/simple_form/wrappers/builder.rb +80 -0
  63. data/simple_form-5.4.1/lib/simple_form/wrappers/leaf.rb +29 -0
  64. data/simple_form-5.4.1/lib/simple_form/wrappers/many.rb +74 -0
  65. data/simple_form-5.4.1/lib/simple_form/wrappers/root.rb +43 -0
  66. data/simple_form-5.4.1/lib/simple_form/wrappers/single.rb +27 -0
  67. data/simple_form-5.4.1/lib/simple_form/wrappers.rb +10 -0
  68. data/simple_form-5.4.1/lib/simple_form.rb +340 -0
  69. data/tiny-smart-mod.gemspec +12 -0
  70. metadata +109 -0
@@ -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
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ module Components
4
+ # Needs to be enabled in order to do automatic lookups.
5
+ module Readonly
6
+ def readonly(wrapper_options = nil)
7
+ if readonly_attribute? && !has_readonly?
8
+ input_html_options[:readonly] ||= true
9
+ input_html_classes << :readonly
10
+ end
11
+ nil
12
+ end
13
+
14
+ private
15
+
16
+ def readonly_attribute?
17
+ object.class.respond_to?(:readonly_attributes) &&
18
+ object.persisted? &&
19
+ object.class.readonly_attributes.include?(attribute_name.to_s)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ # Components are a special type of helpers that can work on their own.
4
+ # For example, by using a component, it will automatically change the
5
+ # output under given circumstances without user input. For example,
6
+ # the disabled helper always need a disabled: true option given
7
+ # to the input in order to be enabled. On the other hand, things like
8
+ # hints can generate output automatically by doing I18n lookups.
9
+ module Components
10
+ extend ActiveSupport::Autoload
11
+
12
+ autoload :Errors
13
+ autoload :Hints
14
+ autoload :HTML5
15
+ autoload :LabelInput
16
+ autoload :Labels
17
+ autoload :MinMax
18
+ autoload :Maxlength
19
+ autoload :Minlength
20
+ autoload :Pattern
21
+ autoload :Placeholders
22
+ autoload :Readonly
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ module SimpleForm
3
+ class ErrorNotification
4
+ delegate :object, :object_name, :template, to: :@builder
5
+
6
+ def initialize(builder, options)
7
+ @builder = builder
8
+ @message = options.delete(:message)
9
+ @options = options
10
+ end
11
+
12
+ def render
13
+ if has_errors?
14
+ template.content_tag(error_notification_tag, error_message, html_options)
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def errors
21
+ object.errors
22
+ end
23
+
24
+ def has_errors?
25
+ object && object.respond_to?(:errors) && errors.present?
26
+ end
27
+
28
+ def error_message
29
+ (@message || translate_error_notification).html_safe
30
+ end
31
+
32
+ def error_notification_tag
33
+ SimpleForm.error_notification_tag
34
+ end
35
+
36
+ def html_options
37
+ @options[:class] = "#{SimpleForm.error_notification_class} #{@options[:class]}".strip
38
+ @options
39
+ end
40
+
41
+ def translate_error_notification
42
+ lookups = []
43
+ lookups << :"#{object_name}"
44
+ lookups << :default_message
45
+ lookups << "Please review the problems below:"
46
+ I18n.t(lookups.shift, scope: :"simple_form.error_notification", default: lookups)
47
+ end
48
+ end
49
+ end