mega-safe-tool 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 (171) hide show
  1. checksums.yaml +7 -0
  2. data/formtastic-6.0.0/Appraisals +23 -0
  3. data/formtastic-6.0.0/CONTRIBUTING.md +27 -0
  4. data/formtastic-6.0.0/Gemfile +8 -0
  5. data/formtastic-6.0.0/MIT-LICENSE +20 -0
  6. data/formtastic-6.0.0/README.md +600 -0
  7. data/formtastic-6.0.0/RELEASE_PROCESS +7 -0
  8. data/formtastic-6.0.0/Rakefile +54 -0
  9. data/formtastic-6.0.0/bin/appraisal +8 -0
  10. data/formtastic-6.0.0/formtastic.gemspec +45 -0
  11. data/formtastic-6.0.0/gemfiles/rails_72.gemfile +9 -0
  12. data/formtastic-6.0.0/gemfiles/rails_80.gemfile +9 -0
  13. data/formtastic-6.0.0/gemfiles/rails_81.gemfile +9 -0
  14. data/formtastic-6.0.0/gemfiles/rails_edge.gemfile +9 -0
  15. data/formtastic-6.0.0/lib/formtastic/action_class_finder.rb +19 -0
  16. data/formtastic-6.0.0/lib/formtastic/actions/base.rb +157 -0
  17. data/formtastic-6.0.0/lib/formtastic/actions/button_action.rb +68 -0
  18. data/formtastic-6.0.0/lib/formtastic/actions/buttonish.rb +18 -0
  19. data/formtastic-6.0.0/lib/formtastic/actions/input_action.rb +71 -0
  20. data/formtastic-6.0.0/lib/formtastic/actions/link_action.rb +89 -0
  21. data/formtastic-6.0.0/lib/formtastic/actions.rb +15 -0
  22. data/formtastic-6.0.0/lib/formtastic/deprecation.rb +6 -0
  23. data/formtastic-6.0.0/lib/formtastic/form_builder.rb +109 -0
  24. data/formtastic-6.0.0/lib/formtastic/helpers/action_helper.rb +115 -0
  25. data/formtastic-6.0.0/lib/formtastic/helpers/actions_helper.rb +169 -0
  26. data/formtastic-6.0.0/lib/formtastic/helpers/enum.rb +14 -0
  27. data/formtastic-6.0.0/lib/formtastic/helpers/errors_helper.rb +139 -0
  28. data/formtastic-6.0.0/lib/formtastic/helpers/fieldset_wrapper.rb +85 -0
  29. data/formtastic-6.0.0/lib/formtastic/helpers/file_column_detection.rb +17 -0
  30. data/formtastic-6.0.0/lib/formtastic/helpers/form_helper.rb +204 -0
  31. data/formtastic-6.0.0/lib/formtastic/helpers/input_helper.rb +349 -0
  32. data/formtastic-6.0.0/lib/formtastic/helpers/inputs_helper.rb +421 -0
  33. data/formtastic-6.0.0/lib/formtastic/helpers/reflection.rb +38 -0
  34. data/formtastic-6.0.0/lib/formtastic/helpers.rb +16 -0
  35. data/formtastic-6.0.0/lib/formtastic/html_attributes.rb +33 -0
  36. data/formtastic-6.0.0/lib/formtastic/i18n.rb +33 -0
  37. data/formtastic-6.0.0/lib/formtastic/input_class_finder.rb +19 -0
  38. data/formtastic-6.0.0/lib/formtastic/inputs/base/aria.rb +26 -0
  39. data/formtastic-6.0.0/lib/formtastic/inputs/base/associations.rb +32 -0
  40. data/formtastic-6.0.0/lib/formtastic/inputs/base/choices.rb +109 -0
  41. data/formtastic-6.0.0/lib/formtastic/inputs/base/collections.rb +158 -0
  42. data/formtastic-6.0.0/lib/formtastic/inputs/base/database.rb +20 -0
  43. data/formtastic-6.0.0/lib/formtastic/inputs/base/datetime_pickerish.rb +86 -0
  44. data/formtastic-6.0.0/lib/formtastic/inputs/base/errors.rb +59 -0
  45. data/formtastic-6.0.0/lib/formtastic/inputs/base/fileish.rb +24 -0
  46. data/formtastic-6.0.0/lib/formtastic/inputs/base/hints.rb +32 -0
  47. data/formtastic-6.0.0/lib/formtastic/inputs/base/html.rb +54 -0
  48. data/formtastic-6.0.0/lib/formtastic/inputs/base/labelling.rb +53 -0
  49. data/formtastic-6.0.0/lib/formtastic/inputs/base/naming.rb +43 -0
  50. data/formtastic-6.0.0/lib/formtastic/inputs/base/numeric.rb +51 -0
  51. data/formtastic-6.0.0/lib/formtastic/inputs/base/options.rb +18 -0
  52. data/formtastic-6.0.0/lib/formtastic/inputs/base/placeholder.rb +18 -0
  53. data/formtastic-6.0.0/lib/formtastic/inputs/base/stringish.rb +39 -0
  54. data/formtastic-6.0.0/lib/formtastic/inputs/base/timeish.rb +246 -0
  55. data/formtastic-6.0.0/lib/formtastic/inputs/base/validations.rb +250 -0
  56. data/formtastic-6.0.0/lib/formtastic/inputs/base/wrapping.rb +51 -0
  57. data/formtastic-6.0.0/lib/formtastic/inputs/base.rb +79 -0
  58. data/formtastic-6.0.0/lib/formtastic/inputs/boolean_input.rb +119 -0
  59. data/formtastic-6.0.0/lib/formtastic/inputs/check_boxes_input.rb +198 -0
  60. data/formtastic-6.0.0/lib/formtastic/inputs/color_input.rb +42 -0
  61. data/formtastic-6.0.0/lib/formtastic/inputs/country_input.rb +90 -0
  62. data/formtastic-6.0.0/lib/formtastic/inputs/datalist_input.rb +42 -0
  63. data/formtastic-6.0.0/lib/formtastic/inputs/date_picker_input.rb +94 -0
  64. data/formtastic-6.0.0/lib/formtastic/inputs/date_select_input.rb +35 -0
  65. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_picker_input.rb +104 -0
  66. data/formtastic-6.0.0/lib/formtastic/inputs/datetime_select_input.rb +13 -0
  67. data/formtastic-6.0.0/lib/formtastic/inputs/email_input.rb +42 -0
  68. data/formtastic-6.0.0/lib/formtastic/inputs/file_input.rb +43 -0
  69. data/formtastic-6.0.0/lib/formtastic/inputs/hidden_input.rb +63 -0
  70. data/formtastic-6.0.0/lib/formtastic/inputs/number_input.rb +89 -0
  71. data/formtastic-6.0.0/lib/formtastic/inputs/password_input.rb +42 -0
  72. data/formtastic-6.0.0/lib/formtastic/inputs/phone_input.rb +43 -0
  73. data/formtastic-6.0.0/lib/formtastic/inputs/radio_input.rb +164 -0
  74. data/formtastic-6.0.0/lib/formtastic/inputs/range_input.rb +96 -0
  75. data/formtastic-6.0.0/lib/formtastic/inputs/search_input.rb +42 -0
  76. data/formtastic-6.0.0/lib/formtastic/inputs/select_input.rb +236 -0
  77. data/formtastic-6.0.0/lib/formtastic/inputs/string_input.rb +37 -0
  78. data/formtastic-6.0.0/lib/formtastic/inputs/text_input.rb +49 -0
  79. data/formtastic-6.0.0/lib/formtastic/inputs/time_picker_input.rb +100 -0
  80. data/formtastic-6.0.0/lib/formtastic/inputs/time_select_input.rb +39 -0
  81. data/formtastic-6.0.0/lib/formtastic/inputs/time_zone_input.rb +59 -0
  82. data/formtastic-6.0.0/lib/formtastic/inputs/url_input.rb +42 -0
  83. data/formtastic-6.0.0/lib/formtastic/inputs.rb +43 -0
  84. data/formtastic-6.0.0/lib/formtastic/localized_string.rb +18 -0
  85. data/formtastic-6.0.0/lib/formtastic/localizer.rb +151 -0
  86. data/formtastic-6.0.0/lib/formtastic/namespaced_class_finder.rb +98 -0
  87. data/formtastic-6.0.0/lib/formtastic/version.rb +4 -0
  88. data/formtastic-6.0.0/lib/formtastic.rb +48 -0
  89. data/formtastic-6.0.0/lib/generators/formtastic/form/form_generator.rb +111 -0
  90. data/formtastic-6.0.0/lib/generators/formtastic/input/input_generator.rb +47 -0
  91. data/formtastic-6.0.0/lib/generators/formtastic/install/install_generator.rb +23 -0
  92. data/formtastic-6.0.0/lib/generators/formtastic/stylesheets/stylesheets_generator.rb +15 -0
  93. data/formtastic-6.0.0/lib/generators/templates/_form.html.erb +11 -0
  94. data/formtastic-6.0.0/lib/generators/templates/_form.html.haml +8 -0
  95. data/formtastic-6.0.0/lib/generators/templates/_form.html.slim +8 -0
  96. data/formtastic-6.0.0/lib/generators/templates/formtastic.css +289 -0
  97. data/formtastic-6.0.0/lib/generators/templates/formtastic.rb +118 -0
  98. data/formtastic-6.0.0/lib/generators/templates/input.rb +19 -0
  99. data/formtastic-6.0.0/lib/locale/en.yml +10 -0
  100. data/formtastic-6.0.0/sample/basic_inputs.html +224 -0
  101. data/formtastic-6.0.0/sample/config.ru +69 -0
  102. data/formtastic-6.0.0/sample/index.html +14 -0
  103. data/formtastic-6.0.0/script/integration-template.rb +76 -0
  104. data/formtastic-6.0.0/script/integration.sh +32 -0
  105. data/formtastic-6.0.0/spec/action_class_finder_spec.rb +12 -0
  106. data/formtastic-6.0.0/spec/actions/button_action_spec.rb +63 -0
  107. data/formtastic-6.0.0/spec/actions/generic_action_spec.rb +521 -0
  108. data/formtastic-6.0.0/spec/actions/input_action_spec.rb +59 -0
  109. data/formtastic-6.0.0/spec/actions/link_action_spec.rb +92 -0
  110. data/formtastic-6.0.0/spec/builder/custom_builder_spec.rb +132 -0
  111. data/formtastic-6.0.0/spec/builder/error_proc_spec.rb +27 -0
  112. data/formtastic-6.0.0/spec/builder/semantic_fields_for_spec.rb +213 -0
  113. data/formtastic-6.0.0/spec/fast_spec_helper.rb +12 -0
  114. data/formtastic-6.0.0/spec/generators/formtastic/form/form_generator_spec.rb +132 -0
  115. data/formtastic-6.0.0/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  116. data/formtastic-6.0.0/spec/generators/formtastic/install/install_generator_spec.rb +48 -0
  117. data/formtastic-6.0.0/spec/generators/formtastic/stylesheets/stylesheets_generator_spec.rb +22 -0
  118. data/formtastic-6.0.0/spec/helpers/action_helper_spec.rb +338 -0
  119. data/formtastic-6.0.0/spec/helpers/actions_helper_spec.rb +143 -0
  120. data/formtastic-6.0.0/spec/helpers/form_helper_spec.rb +224 -0
  121. data/formtastic-6.0.0/spec/helpers/input_helper_spec.rb +991 -0
  122. data/formtastic-6.0.0/spec/helpers/inputs_helper_spec.rb +669 -0
  123. data/formtastic-6.0.0/spec/helpers/reflection_helper_spec.rb +32 -0
  124. data/formtastic-6.0.0/spec/helpers/semantic_errors_helper_spec.rb +220 -0
  125. data/formtastic-6.0.0/spec/i18n_spec.rb +210 -0
  126. data/formtastic-6.0.0/spec/input_class_finder_spec.rb +10 -0
  127. data/formtastic-6.0.0/spec/inputs/base/collections_spec.rb +119 -0
  128. data/formtastic-6.0.0/spec/inputs/base/validations_spec.rb +481 -0
  129. data/formtastic-6.0.0/spec/inputs/boolean_input_spec.rb +254 -0
  130. data/formtastic-6.0.0/spec/inputs/check_boxes_input_spec.rb +547 -0
  131. data/formtastic-6.0.0/spec/inputs/color_input_spec.rb +85 -0
  132. data/formtastic-6.0.0/spec/inputs/country_input_spec.rb +133 -0
  133. data/formtastic-6.0.0/spec/inputs/custom_input_spec.rb +51 -0
  134. data/formtastic-6.0.0/spec/inputs/datalist_input_spec.rb +61 -0
  135. data/formtastic-6.0.0/spec/inputs/date_picker_input_spec.rb +449 -0
  136. data/formtastic-6.0.0/spec/inputs/date_select_input_spec.rb +249 -0
  137. data/formtastic-6.0.0/spec/inputs/datetime_picker_input_spec.rb +490 -0
  138. data/formtastic-6.0.0/spec/inputs/datetime_select_input_spec.rb +209 -0
  139. data/formtastic-6.0.0/spec/inputs/email_input_spec.rb +85 -0
  140. data/formtastic-6.0.0/spec/inputs/file_input_spec.rb +89 -0
  141. data/formtastic-6.0.0/spec/inputs/hidden_input_spec.rb +135 -0
  142. data/formtastic-6.0.0/spec/inputs/include_blank_spec.rb +78 -0
  143. data/formtastic-6.0.0/spec/inputs/label_spec.rb +181 -0
  144. data/formtastic-6.0.0/spec/inputs/number_input_spec.rb +815 -0
  145. data/formtastic-6.0.0/spec/inputs/password_input_spec.rb +99 -0
  146. data/formtastic-6.0.0/spec/inputs/phone_input_spec.rb +85 -0
  147. data/formtastic-6.0.0/spec/inputs/placeholder_spec.rb +71 -0
  148. data/formtastic-6.0.0/spec/inputs/radio_input_spec.rb +326 -0
  149. data/formtastic-6.0.0/spec/inputs/range_input_spec.rb +505 -0
  150. data/formtastic-6.0.0/spec/inputs/readonly_spec.rb +50 -0
  151. data/formtastic-6.0.0/spec/inputs/search_input_spec.rb +84 -0
  152. data/formtastic-6.0.0/spec/inputs/select_input_spec.rb +661 -0
  153. data/formtastic-6.0.0/spec/inputs/string_input_spec.rb +326 -0
  154. data/formtastic-6.0.0/spec/inputs/text_input_spec.rb +187 -0
  155. data/formtastic-6.0.0/spec/inputs/time_picker_input_spec.rb +455 -0
  156. data/formtastic-6.0.0/spec/inputs/time_select_input_spec.rb +261 -0
  157. data/formtastic-6.0.0/spec/inputs/time_zone_input_spec.rb +143 -0
  158. data/formtastic-6.0.0/spec/inputs/url_input_spec.rb +85 -0
  159. data/formtastic-6.0.0/spec/inputs/with_options_spec.rb +43 -0
  160. data/formtastic-6.0.0/spec/localizer_spec.rb +130 -0
  161. data/formtastic-6.0.0/spec/namespaced_class_finder_spec.rb +90 -0
  162. data/formtastic-6.0.0/spec/schema.rb +22 -0
  163. data/formtastic-6.0.0/spec/spec.opts +2 -0
  164. data/formtastic-6.0.0/spec/spec_helper.rb +466 -0
  165. data/formtastic-6.0.0/spec/support/custom_macros.rb +570 -0
  166. data/formtastic-6.0.0/spec/support/deprecation.rb +7 -0
  167. data/formtastic-6.0.0/spec/support/shared_examples.rb +13 -0
  168. data/formtastic-6.0.0/spec/support/specialized_class_finder_shared_example.rb +27 -0
  169. data/formtastic-6.0.0/spec/support/test_environment.rb +46 -0
  170. data/mega-safe-tool.gemspec +11 -0
  171. metadata +209 -0
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+ module Base
5
+
6
+ attr_accessor :builder, :template, :object, :object_name, :method, :options
7
+
8
+ def initialize(builder, template, object, object_name, method, options)
9
+ @builder = builder
10
+ @template = template
11
+ @object = object
12
+ @object_name = object_name
13
+ @method = method
14
+ @options = options.dup
15
+
16
+ # Deprecate :member_label and :member_value, remove v4.0
17
+ member_deprecation_message = "passing an Array of label/value pairs like [['Justin', 2], ['Kate', 3]] into :collection directly (consider building the array in your model using Model.pluck)"
18
+ warn_deprecated_option!(:member_label, member_deprecation_message)
19
+ warn_deprecated_option!(:member_value, member_deprecation_message)
20
+ end
21
+
22
+ # Useful for deprecating options.
23
+ def warn_and_correct_option!(old_option_name, new_option_name)
24
+ if options.key?(old_option_name)
25
+ Deprecation.warn("The :#{old_option_name} option is deprecated in favour of :#{new_option_name} and will be removed from Formtastic in the next version", caller_locations(6))
26
+ options[new_option_name] = options.delete(old_option_name)
27
+ end
28
+ end
29
+
30
+ # Useful for deprecating options.
31
+ def warn_deprecated_option!(old_option_name, instructions)
32
+ if options.key?(old_option_name)
33
+ Deprecation.warn("The :#{old_option_name} option is deprecated in favour of `#{instructions}`. :#{old_option_name} will be removed in the next version", caller_locations(6))
34
+ end
35
+ end
36
+
37
+ # Useful for raising an error on previously supported option.
38
+ def removed_option!(old_option_name)
39
+ raise ArgumentError, ":#{old_option_name} is no longer available" if options.key?(old_option_name)
40
+ end
41
+
42
+ extend ActiveSupport::Autoload
43
+
44
+ autoload :DatetimePickerish
45
+ autoload :Associations
46
+ autoload :Collections
47
+ autoload :Choices
48
+ autoload :Database
49
+ autoload :Errors
50
+ autoload :Fileish
51
+ autoload :Hints
52
+ autoload :Html
53
+ autoload :Labelling
54
+ autoload :Naming
55
+ autoload :Numeric
56
+ autoload :Options
57
+ autoload :Placeholder
58
+ autoload :Stringish
59
+ autoload :Timeish
60
+ autoload :Validations
61
+ autoload :Wrapping
62
+ autoload :Aria
63
+
64
+ include Html
65
+ include Options
66
+ include Database
67
+ include Errors
68
+ include Hints
69
+ include Naming
70
+ include Validations
71
+ include Fileish
72
+ include Associations
73
+ include Labelling
74
+ include Wrapping
75
+ include Aria
76
+
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+ # Boolean inputs are used to render an input for a single checkbox, typically for attributes
5
+ # with a simple yes/no or true/false value. Boolean inputs are used by default for boolean
6
+ # database columns.
7
+ #
8
+ # @example Full form context and markup
9
+ # <%= semantic_form_for @post %>
10
+ # <%= f.inputs do %>
11
+ # <%= f.input :published, :as => :boolean %>
12
+ # <% end %>
13
+ # <% end %>
14
+ #
15
+ # <form...>
16
+ # <fieldset>
17
+ # <ol>
18
+ # <li class="boolean" id="post_published_input">
19
+ # <input type="hidden" name="post[published]" id="post_published" value="0">
20
+ # <label for="post_published">
21
+ # <input type="checkbox" name="post[published]" id="post_published" value="1">
22
+ # Published?
23
+ # </label>
24
+ # </li>
25
+ # </ol>
26
+ # </fieldset>
27
+ # </form>
28
+ #
29
+ # @example Set the values for the checked and unchecked states
30
+ # <%= f.input :published, :checked_value => "yes", :unchecked_value => "no" %>
31
+ #
32
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
33
+ class BooleanInput
34
+ include Base
35
+
36
+ def to_html
37
+ input_wrapping do
38
+ hidden_field_html <<
39
+ label_with_nested_checkbox
40
+ end
41
+ end
42
+
43
+ def hidden_field_html
44
+ template.hidden_field_tag(input_html_options[:name], unchecked_value, :id => nil, :disabled => input_html_options[:disabled] )
45
+ end
46
+
47
+ def label_with_nested_checkbox
48
+ builder.label(
49
+ method,
50
+ label_text_with_embedded_checkbox,
51
+ label_html_options
52
+ )
53
+ end
54
+
55
+ def label_html_options
56
+ {
57
+ :for => input_html_options[:id],
58
+ :class => super[:class] - ['label'] # remove 'label' class
59
+ }
60
+ end
61
+
62
+ def label_text_with_embedded_checkbox
63
+ check_box_html << +"" << label_text
64
+ end
65
+
66
+ def check_box_html
67
+ template.check_box_tag("#{object_name}[#{method}]", checked_value, checked?, input_html_options)
68
+ end
69
+
70
+ def unchecked_value
71
+ options[:unchecked_value] || '0'
72
+ end
73
+
74
+ def checked_value
75
+ options[:checked_value] || '1'
76
+ end
77
+
78
+ def responds_to_global_required?
79
+ false
80
+ end
81
+
82
+ def input_html_options
83
+ {:name => input_html_options_name}.merge(super)
84
+ end
85
+
86
+ def input_html_options_name
87
+ if builder.options.key?(:index)
88
+ "#{object_name}[#{builder.options[:index]}][#{method}]"
89
+ else
90
+ "#{object_name}[#{method}]"
91
+ end
92
+ end
93
+
94
+ def checked?
95
+ object && boolean_checked?(object.send(method), checked_value)
96
+ end
97
+
98
+ private
99
+
100
+ def boolean_checked?(value, checked_value)
101
+ case value
102
+ when TrueClass, FalseClass
103
+ value
104
+ when NilClass
105
+ false
106
+ when Integer
107
+ value == checked_value.to_i
108
+ when String
109
+ value == checked_value
110
+ when Array
111
+ value.include?(checked_value)
112
+ else
113
+ value.to_i != 0
114
+ end
115
+ end
116
+
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,198 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+
5
+ # A CheckBoxes input is used to render a series of checkboxes. This is an alternative input choice
6
+ # for `has_many` or `has_and_belongs_to_many` associations like a `Post` belonging to many
7
+ # `categories` (by default, a {SelectInput `:select`} input is used, allowing multiple selections).
8
+ #
9
+ # Within the standard `<li>` wrapper, the output is a `<fieldset>` with a `<legend>` to
10
+ # represent the "label" for the input, and an `<ol>` containing `<li>`s for each choice in
11
+ # the association. Each `<li>` choice contains a hidden `<input>` tag for the "unchecked"
12
+ # value (like Rails), and a `<label>` containing the checkbox `<input>` and the label text
13
+ # for each choice.
14
+ #
15
+ # @example Basic example with full form context
16
+ #
17
+ # <%= semantic_form_for @post do |f| %>
18
+ # <%= f.inputs do %>
19
+ # <%= f.input :categories, :as => :check_boxes %>
20
+ # <% end %>
21
+ # <% end %>
22
+ #
23
+ # <li class='check_boxes'>
24
+ # <fieldset>
25
+ # <legend class="label"><label>Categories</label></legend>
26
+ # <ol>
27
+ # <li>
28
+ # <input type="hidden" name="post[category_ids][1]" value="">
29
+ # <label for="post_category_ids_1"><input id="post_category_ids_1" name="post[category_ids][1]" type="checkbox" value="1" /> Ruby</label>
30
+ # </li>
31
+ # <li>
32
+ # <input type="hidden" name="post[category_ids][2]" value="">
33
+ # <label for="post_category_ids_2"><input id="post_category_ids_2" name="post[category_ids][2]" type="checkbox" value="2" /> Rails</label>
34
+ # </li>
35
+ # </ol>
36
+ # </fieldset>
37
+ # </li>
38
+ #
39
+ # @example `:collection` can be used to customize the choices
40
+ # <%= f.input :categories, :as => :check_boxes, :collection => @categories %>
41
+ # <%= f.input :categories, :as => :check_boxes, :collection => Category.all %>
42
+ # <%= f.input :categories, :as => :check_boxes, :collection => Category.some_named_scope %>
43
+ # <%= f.input :categories, :as => :check_boxes, :collection => Category.pluck(:label, :id) %>
44
+ # <%= f.input :categories, :as => :check_boxes, :collection => [Category.find_by_name("Ruby"), Category.find_by_name("Rails")] %>
45
+ # <%= f.input :categories, :as => :check_boxes, :collection => ["Ruby", "Rails"] %>
46
+ # <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", "ruby"], ["Rails", "rails"]] %>
47
+ # <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", "1"], ["Rails", "2"]] %>
48
+ # <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", 1], ["Rails", 2]] %>
49
+ # <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", 1, {'data-attr' => 'attr-value'}]] %>
50
+ # <%= f.input :categories, :as => :check_boxes, :collection => 1..5 %>
51
+ # <%= f.input :categories, :as => :check_boxes, :collection => [:ruby, :rails] %>
52
+ # <%= f.input :categories, :as => :check_boxes, :collection => [["Ruby", :ruby], ["Rails", :rails]] %>
53
+ # <%= f.input :categories, :as => :check_boxes, :collection => Set.new([:ruby, :rails]) %>
54
+ #
55
+ # @example `:hidden_fields` can be used to skip Rails' rendering of a hidden field before every checkbox
56
+ # <%= f.input :categories, :as => :check_boxes, :hidden_fields => false %>
57
+ #
58
+ # @example `:disabled` can be used to disable any checkboxes with a value found in the given Array
59
+ # <%= f.input :categories, :as => :check_boxes, :collection => ["a", "b"], :disabled => ["a"] %>
60
+ #
61
+ # @example `:value_as_class` can be used to add a class to the `<li>` wrapped around each choice using the checkbox value for custom styling of each choice
62
+ # <%= f.input :categories, :as => :check_boxes, :value_as_class => true %>
63
+ #
64
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
65
+ # @see Formtastic::Inputs::BooleanInput BooleanInput for a single checkbox for boolean (checked = true) inputs
66
+ #
67
+ # @todo Do/can we support the per-item HTML options like RadioInput?
68
+ class CheckBoxesInput
69
+ include Base
70
+ include Base::Collections
71
+ include Base::Choices
72
+
73
+ def initialize(*args)
74
+ super
75
+ raise Formtastic::UnsupportedEnumCollection if collection_from_enum?
76
+ end
77
+
78
+ def to_html
79
+ input_wrapping do
80
+ choices_wrapping do
81
+ legend_html <<
82
+ hidden_field_for_all <<
83
+ choices_group_wrapping do
84
+ collection.map { |choice|
85
+ choice_wrapping(choice_wrapping_html_options(choice)) do
86
+ choice_html(choice)
87
+ end
88
+ }.join("\n").html_safe
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def choice_html(choice)
95
+ template.content_tag(
96
+ :label,
97
+ checkbox_input(choice) + choice_label(choice),
98
+ label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
99
+ )
100
+ end
101
+
102
+ def hidden_field_for_all
103
+ if hidden_fields_for_every?
104
+ +''
105
+ else
106
+ options = {}
107
+ options[:class] = [method.to_s.singularize, 'default'].join('_') if value_as_class?
108
+ options[:id] = [object_name, method, 'none'].join('_')
109
+ template.hidden_field_tag(input_name, '', options)
110
+ end
111
+ end
112
+
113
+ def hidden_fields_for_every?
114
+ options[:hidden_fields]
115
+ end
116
+
117
+ def check_box_with_hidden_input(choice)
118
+ value = choice_value(choice)
119
+ builder.check_box(
120
+ association_primary_key || method,
121
+ extra_html_options(choice).merge(:id => choice_input_dom_id(choice), :name => input_name, :disabled => disabled?(value), :required => false),
122
+ value,
123
+ unchecked_value
124
+ )
125
+ end
126
+
127
+ def check_box_without_hidden_input(choice)
128
+ value = choice_value(choice)
129
+ template.check_box_tag(
130
+ input_name,
131
+ value,
132
+ checked?(value),
133
+ extra_html_options(choice).merge(:id => choice_input_dom_id(choice), :disabled => disabled?(value), :required => false)
134
+ )
135
+ end
136
+
137
+ def extra_html_options(choice)
138
+ input_html_options.merge(custom_choice_html_options(choice))
139
+ end
140
+
141
+ def checked?(value)
142
+ selected_values.include?(value)
143
+ end
144
+
145
+ def disabled?(value)
146
+ disabled_values.include?(value)
147
+ end
148
+
149
+ def selected_values
150
+ @selected_values ||= make_selected_values
151
+ end
152
+
153
+ def disabled_values
154
+ vals = options[:disabled] || []
155
+ vals = [vals] unless vals.is_a?(Array)
156
+ vals
157
+ end
158
+
159
+ def unchecked_value
160
+ options[:unchecked_value] || ''
161
+ end
162
+
163
+ def input_name
164
+ if builder.options.key?(:index)
165
+ "#{object_name}[#{builder.options[:index]}][#{association_primary_key || method}][]"
166
+ else
167
+ "#{object_name}[#{association_primary_key || method}][]"
168
+ end
169
+ end
170
+
171
+ protected
172
+
173
+ def checkbox_input(choice)
174
+ if hidden_fields_for_every?
175
+ check_box_with_hidden_input(choice)
176
+ else
177
+ check_box_without_hidden_input(choice)
178
+ end
179
+ end
180
+
181
+ def make_selected_values
182
+ if object.respond_to?(method)
183
+ selected_items = object.send(method)
184
+ # Construct an array from the return value, regardless of the return type
185
+ selected_items = [*selected_items].compact.flatten
186
+
187
+ selected = []
188
+ selected_items.map do |selected_item|
189
+ selected_item_id = selected_item.id if selected_item.respond_to? :id
190
+ item = send_or_call_or_object(value_method, selected_item) || selected_item_id
191
+ end.compact
192
+ else
193
+ []
194
+ end
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+
5
+ # Outputs a simple `<label>` with a HTML5 `<input type="color">` wrapped in the standard
6
+ # `<li>` wrapper. This is the default input choice for attributes with a name matching
7
+ # `/color/`, but can be applied to any text-like input with `:as => :color`.
8
+ #
9
+ # @example Full form context and output
10
+ #
11
+ # <%= semantic_form_for(@user) do |f| %>
12
+ # <%= f.inputs do %>
13
+ # <%= f.input :color, :as => :color %>
14
+ # <% end %>
15
+ # <% end %>
16
+ #
17
+ # <form...>
18
+ # <fieldset>
19
+ # <ol>
20
+ # <li class="color">
21
+ # <label for="user_color">Color</label>
22
+ # <input type="color" id="user_color" name="user[color]">
23
+ # </li>
24
+ # </ol>
25
+ # </fieldset>
26
+ # </form>
27
+ #
28
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
29
+ class ColorInput
30
+ include Base
31
+ include Base::Stringish
32
+ include Base::Placeholder
33
+
34
+ def to_html
35
+ input_wrapping do
36
+ label_html <<
37
+ builder.color_field(method, input_html_options)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+ # Outputs a country select input, wrapping around a regular country_select helper.
5
+ # Rails doesn't come with a `country_select` helper by default any more, so you'll need to do
6
+ # one of the following:
7
+ #
8
+ # * install the [country_select](https://github.com/countries/country_select) gem
9
+ # * install any other country_select plugin that behaves in a similar way
10
+ # * roll your own `country_select` helper with the same args and options as the Rails one
11
+ #
12
+ # By default, Formtastic includes a handful of English-speaking countries as "priority
13
+ # countries", which can be set in the `priority_countries` configuration array in the
14
+ # formtastic.rb initializer to suit your market and user base (see README for more info on
15
+ # configuration). Additionally, it is possible to set the :priority_countries on a per-input
16
+ # basis through the `:priority_countries` option. These priority countries will be passed down
17
+ # to the `country_select` helper of your choice, and may or may not be used by the helper.
18
+ #
19
+ # @example Basic example with full form context using `priority_countries` from config
20
+ #
21
+ # <%= semantic_form_for @user do |f| %>
22
+ # <%= f.inputs do %>
23
+ # <%= f.input :nationality, :as => :country %>
24
+ # <% end %>
25
+ # <% end %>
26
+ #
27
+ # <li class='country'>
28
+ # <label for="user_nationality">Country</label>
29
+ # <select id="user_nationality" name="user[nationality]">
30
+ # <option value="...">...</option>
31
+ # # ...
32
+ # </li>
33
+ #
34
+ # @example `:priority_countries` set on a specific input (country_select 1.x)
35
+ #
36
+ # <%= semantic_form_for @user do |f| %>
37
+ # <%= f.inputs do %>
38
+ # <%= f.input :nationality, :as => :country, :priority_countries => ["Australia", "New Zealand"] %>
39
+ # <% end %>
40
+ # <% end %>
41
+ #
42
+ # <li class='country'>
43
+ # <label for="user_nationality">Country</label>
44
+ # <select id="user_nationality" name="user[nationality]">
45
+ # <option value="...">...</option>
46
+ # # ...
47
+ # </li>
48
+ #
49
+ # @example `:priority_countries` set on a specific input (country_select 2.x)
50
+ #
51
+ # <%= semantic_form_for @user do |f| %>
52
+ # <%= f.inputs do %>
53
+ # <%= f.input :nationality, :as => :country, :priority_countries => ["AU", "NZ"] %>
54
+ # <% end %>
55
+ # <% end %>
56
+ #
57
+ # <li class='country'>
58
+ # <label for="user_nationality">Country</label>
59
+ # <select id="user_nationality" name="user[nationality]">
60
+ # <option value="...">...</option>
61
+ # # ...
62
+ # </li>
63
+ #
64
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
65
+ class CountryInput
66
+ include Base
67
+
68
+ CountrySelectPluginMissing = Class.new(StandardError)
69
+
70
+ def to_html
71
+ raise CountrySelectPluginMissing, "To use the :country input, please install a country_select plugin, like this one: https://github.com/countries/country_select" unless builder.respond_to?(:country_select)
72
+ input_wrapping do
73
+ label_html <<
74
+ builder.country_select(method, input_options_including_priorities, input_html_options)
75
+ end
76
+ end
77
+
78
+ def input_options_including_priorities
79
+ return input_options unless priority_countries
80
+
81
+ input_options.merge(:priority_countries => priority_countries)
82
+ end
83
+
84
+ def priority_countries
85
+ options[:priority_countries] || builder.priority_countries
86
+ end
87
+
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+ # Outputs a label and a text field, along with a datalist tag
5
+ # datalist tag provides a list of options which drives a simple autocomplete
6
+ # on the text field. This is a HTML5 feature, more info can be found at
7
+ # {https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Elements/datalist <datalist> at MDN}
8
+ # This input accepts a :collection option which takes data in all the usual formats accepted by
9
+ # {https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select options_for_select}
10
+ #
11
+ # @example Input is used as follows
12
+ # f.input :fav_book, :as => :datalist, :collection => Book.pluck(:name)
13
+ #
14
+ class DatalistInput
15
+ include Base
16
+ include Base::Stringish
17
+ include Base::Collections
18
+
19
+ def to_html
20
+ @name = input_html_options[:id].gsub(/_id$/, "")
21
+ input_wrapping do
22
+ label_html <<
23
+ builder.text_field(method, input_html_options) << # standard input
24
+ data_list_html # append new datalist element
25
+ end
26
+ end
27
+
28
+ def input_html_options
29
+ super.merge(:list => html_id_of_datalist)
30
+ end
31
+
32
+ def html_id_of_datalist
33
+ "#{@name}_datalist"
34
+ end
35
+
36
+ def data_list_html
37
+ html = builder.template.options_for_select(collection)
38
+ builder.template.content_tag(:datalist,html, { :id => html_id_of_datalist }, false)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Inputs
4
+
5
+ # Outputs a simple `<label>` with a HTML5 `<input type="date">` wrapped in the standard
6
+ # `<li>` wrapper. This is an alternative to `:date_select` for `:date`, `:time`, `:datetime`
7
+ # database columns. You can use this input with `:as => :date_picker`.
8
+ #
9
+ # *Please note:* Formtastic only provides suitable markup for a date picker, but does not supply
10
+ # any additional CSS or Javascript to render calendar-style date pickers. Browsers that support
11
+ # this input type (such as Mobile Webkit and Opera on the desktop) will render a native widget.
12
+ # Browsers that don't will default to a plain text field`<input type="text">` and can be
13
+ # poly-filled with some Javascript and a UI library of your choice.
14
+ #
15
+ # @example Full form context and output
16
+ #
17
+ # <%= semantic_form_for(@post) do |f| %>
18
+ # <%= f.inputs do %>
19
+ # <%= f.input :publish_at, :as => :date_picker %>
20
+ # <% end %>
21
+ # <% end %>
22
+ #
23
+ # <form...>
24
+ # <fieldset>
25
+ # <ol>
26
+ # <li class="string">
27
+ # <label for="post_publish_at">First name</label>
28
+ # <input type="date" id="post_publish_at" name="post[publish_at]">
29
+ # </li>
30
+ # </ol>
31
+ # </fieldset>
32
+ # </form>
33
+ #
34
+ # @example Setting the size (defaults to 10 for YYYY-MM-DD)
35
+ # <%= f.input :publish_at, :as => :date_picker, :size => 20 %>
36
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :size => 20 } %>
37
+ #
38
+ # @example Setting the maxlength (defaults to 10 for YYYY-MM-DD)
39
+ # <%= f.input :publish_at, :as => :date_picker, :maxlength => 20 %>
40
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :maxlength => 20 } %>
41
+ #
42
+ # @example Setting the value (defaults to YYYY-MM-DD for Date and Time objects, otherwise renders string)
43
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :value => "1970-01-01" } %>
44
+ #
45
+ # @example Setting the step attribute (defaults to 1)
46
+ # <%= f.input :publish_at, :as => :date_picker, :step => 7 %>
47
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :step => 7 } %>
48
+ #
49
+ # @example Setting the step attribute with a macro
50
+ # <%= f.input :publish_at, :as => :date_picker, :step => :day %>
51
+ # <%= f.input :publish_at, :as => :date_picker, :step => :week %>
52
+ # <%= f.input :publish_at, :as => :date_picker, :step => :seven_days %>
53
+ # <%= f.input :publish_at, :as => :date_picker, :step => :fortnight %>
54
+ # <%= f.input :publish_at, :as => :date_picker, :step => :two_weeks %>
55
+ # <%= f.input :publish_at, :as => :date_picker, :step => :four_weeks %>
56
+ # <%= f.input :publish_at, :as => :date_picker, :step => :thirty_days %>
57
+ #
58
+ # @example Setting the min attribute
59
+ # <%= f.input :publish_at, :as => :date_picker, :min => "2012-01-01" %>
60
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :min => "2012-01-01" } %>
61
+ #
62
+ # @example Setting the max attribute
63
+ # <%= f.input :publish_at, :as => :date_picker, :max => "2012-12-31" %>
64
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :max => "2012-12-31" } %>
65
+ #
66
+ # @example Setting the placeholder attribute
67
+ # <%= f.input :publish_at, :as => :date_picker, :placeholder => 20 %>
68
+ # <%= f.input :publish_at, :as => :date_picker, :input_html => { :placeholder => "YYYY-MM-DD" } %>
69
+ #
70
+ # @see Formtastic::Helpers::InputsHelper#input InputsHelper#input for full documentation of all possible options.
71
+ class DatePickerInput
72
+ include Base
73
+ include Base::Stringish
74
+ include Base::DatetimePickerish
75
+
76
+ def html_input_type
77
+ "date"
78
+ end
79
+
80
+ def default_size
81
+ 10
82
+ end
83
+
84
+ def value
85
+ return options[:input_html][:value] if options[:input_html] && options[:input_html].key?(:value)
86
+ val = object.send(method)
87
+ return Date.new(val.year, val.month, val.day).to_s if val.is_a?(Time)
88
+ return val if val.nil?
89
+ val.to_s
90
+ end
91
+
92
+ end
93
+ end
94
+ end