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,45 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "formtastic/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = %q{formtastic}
7
+ s.version = Formtastic::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = [%q{Justin French}]
10
+ s.email = [%q{justin@indent.com.au}]
11
+ s.homepage = %q{http://github.com/formtastic/formtastic}
12
+ s.summary = %q{A Rails form builder plugin/gem with semantically rich and accessible markup}
13
+ s.description = %q{A Rails form builder plugin/gem with semantically rich and accessible markup}
14
+ s.license = 'MIT'
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = []
19
+ s.require_paths = ["lib"]
20
+
21
+ s.rdoc_options = ["--charset=UTF-8"]
22
+ s.extra_rdoc_files = ["README.md"]
23
+
24
+ # Minimum Ruby version is probably the same as whatever the minimum Rails version currently expects.
25
+ s.required_ruby_version = '>= 3.1.0'
26
+
27
+ # Minimum Ruby Gems version also matches whatever the minimum Rails version currently expects.
28
+ s.required_rubygems_version = ">= 1.8.11"
29
+
30
+ # User dependency is really just Rails, where we want describe the minimum version we support,
31
+ # which is probably the oldest version that hasn't reached end-of-life for security updates.
32
+ s.add_dependency(%q<actionpack>, [">= 7.2.0"])
33
+
34
+ # Development dependencies (for people working on Formtastic) are different to the minimum support
35
+ # version. Instead of specifying a specific version of each, we just specify the stack, and let the
36
+ # details of which versions work with each version of rails be managed in the Appraisal.
37
+ s.add_development_dependency(%q<appraisal>)
38
+ s.add_development_dependency(%q<rspec-rails>)
39
+ s.add_development_dependency(%q<rspec-dom-testing>)
40
+ s.add_development_dependency(%q<rspec-mocks>)
41
+ s.add_development_dependency(%q<yard>)
42
+ s.add_development_dependency(%q<ammeter>)
43
+ s.add_development_dependency(%q<rake>)
44
+ s.add_development_dependency(%q<sqlite3>)
45
+ end
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", "~> 7.2.3"
6
+ gem "activesupport", "~> 7.2.3"
7
+ gem "activerecord", "~> 7.2.3"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", "~> 8.0.4"
6
+ gem "activesupport", "~> 8.0.4"
7
+ gem "activerecord", "~> 8.0.4"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", "~> 8.1.2"
6
+ gem "activesupport", "~> 8.1.2"
7
+ gem "activerecord", "~> 8.1.2"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "actionpack", git: "https://github.com/rails/rails.git", branch: "main"
6
+ gem "activesupport", git: "https://github.com/rails/rails.git", branch: "main"
7
+ gem "activerecord", git: "https://github.com/rails/rails.git", branch: "main"
8
+
9
+ gemspec path: "../"
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+
4
+ # Uses the {NamespacedClassFinder} to look up action class names.
5
+ #
6
+ # See {Formtastic::Helpers::ActionHelper#namespaced_action_class} for details.
7
+ #
8
+ class ActionClassFinder < NamespacedClassFinder
9
+
10
+ # @param builder [FormBuilder]
11
+ def initialize(builder)
12
+ super builder.action_namespaces
13
+ end
14
+
15
+ def class_name(as)
16
+ "#{super}Action"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,157 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+ module Base
5
+ include Formtastic::LocalizedString
6
+
7
+ attr_accessor :builder, :template, :object, :object_name, :method, :options
8
+
9
+ def initialize(builder, template, object, object_name, method, options)
10
+ @builder = builder
11
+ @template = template
12
+ @object = object
13
+ @object_name = object_name
14
+ @method = method
15
+ @options = options.dup
16
+
17
+ check_supported_methods!
18
+ end
19
+
20
+ def to_html
21
+ raise NotImplementedError
22
+ end
23
+
24
+ def wrapper(&block)
25
+ template.content_tag(:li,
26
+ template.capture(&block),
27
+ wrapper_html_options
28
+ )
29
+ end
30
+
31
+ def wrapper_html_options
32
+ wrapper_html_options_from_options.merge(default_wrapper_html_options)
33
+ end
34
+
35
+ def wrapper_html_options_from_options
36
+ options[:wrapper_html] || {}
37
+ end
38
+
39
+ def default_wrapper_html_options
40
+ {
41
+ :class => wrapper_class,
42
+ :id => wrapper_id
43
+ }
44
+ end
45
+
46
+ def wrapper_class
47
+ (default_wrapper_classes << wrapper_classes_from_options).join(" ")
48
+ end
49
+
50
+ def default_wrapper_classes
51
+ ["action", "#{options[:as]}_action"]
52
+ end
53
+
54
+ def wrapper_classes_from_options
55
+ classes = wrapper_html_options_from_options[:class] || []
56
+ classes = classes.split(" ") if classes.is_a? String
57
+ classes
58
+ end
59
+
60
+ def wrapper_html_options_from_options
61
+ options[:wrapper_html] || {}
62
+ end
63
+
64
+ def wrapper_id
65
+ wrapper_id_from_options || default_wrapper_id
66
+ end
67
+
68
+ def wrapper_id_from_options
69
+ wrapper_html_options_from_options[:id]
70
+ end
71
+
72
+ def default_wrapper_id
73
+ "#{object_name}_#{method}_action"
74
+ end
75
+
76
+ def supported_methods
77
+ raise NotImplementedError
78
+ end
79
+
80
+ def text
81
+ text = options[:label]
82
+ text = (localized_string(i18n_key, text, :action, :model => sanitized_object_name) ||
83
+ Formtastic::I18n.t(i18n_key, :model => sanitized_object_name)) unless text.is_a?(::String)
84
+ text
85
+ end
86
+
87
+ def button_html
88
+ default_button_html.merge(button_html_from_options || {}).merge(extra_button_html_options)
89
+ end
90
+
91
+ def button_html_from_options
92
+ options[:button_html]
93
+ end
94
+
95
+ def extra_button_html_options
96
+ {}
97
+ end
98
+
99
+ def default_button_html
100
+ { :accesskey => accesskey }
101
+ end
102
+
103
+ def accesskey
104
+ # TODO could be cleaner and separated, remember that nil is an allowed value for all of these
105
+ return options[:accesskey] if options.key?(:accesskey)
106
+ return options[:button_html][:accesskey] if options.key?(:button_html) && options[:button_html].key?(:accesskey)
107
+ # TODO might be different for cancel, etc?
108
+ return builder.default_commit_button_accesskey
109
+ end
110
+
111
+
112
+ protected
113
+
114
+ def check_supported_methods!
115
+ raise Formtastic::UnsupportedMethodForAction unless supported_methods.include?(method)
116
+ end
117
+
118
+ def i18n_key
119
+ return submit_i18n_key if method == :submit
120
+ method
121
+ end
122
+
123
+ def submit_i18n_key
124
+ if new_or_persisted_object?
125
+ key = @object.persisted? ? :update : :create
126
+ else
127
+ key = :submit
128
+ end
129
+ end
130
+
131
+ def new_or_persisted_object?
132
+ object && (object.respond_to?(:persisted?) || object.respond_to?(:new_record?))
133
+ end
134
+
135
+ def sanitized_object_name
136
+ if new_or_persisted_object?
137
+ # Deal with some complications with ActiveRecord::Base.human_name and two name models (eg UserPost)
138
+ # ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
139
+ # if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
140
+ # fall back (human_name == name.humanize) and do our own thing name.underscore.humanize ("User Post")
141
+ if object.class.model_name.respond_to?(:human)
142
+ sanitized_object_name = object.class.model_name.human
143
+ else
144
+ object_human_name = @object.class.human_name # default is UserPost => "Userpost", but i18n may do better ("User post")
145
+ crappy_human_name = @object.class.name.humanize # UserPost => "Userpost"
146
+ decent_human_name = @object.class.name.underscore.humanize # UserPost => "User post"
147
+ sanitized_object_name = (object_human_name == crappy_human_name) ? decent_human_name : object_human_name
148
+ end
149
+ else
150
+ sanitized_object_name = object_name.to_s.send(builder.label_str_method)
151
+ end
152
+ sanitized_object_name
153
+ end
154
+
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+
5
+ # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>`
6
+ # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with
7
+ # `<input type="submit">` and `<input type="reset">` by default.
8
+ #
9
+ # @example Full form context and output
10
+ #
11
+ # <%= semantic_form_for(@post) do |f| %>
12
+ # <%= f.actions do %>
13
+ # <%= f.action :reset, :as => :button %>
14
+ # <%= f.action :submit, :as => :button %>
15
+ # <% end %>
16
+ # <% end %>
17
+ #
18
+ # <form...>
19
+ # <fieldset class="actions">
20
+ # <ol>
21
+ # <li class="action button_action" id="post_reset_action">
22
+ # <button type="reset" value="Reset">
23
+ # </li>
24
+ # <li class="action button_action" id="post_submit_action">
25
+ # <button type="submit" value="Create Post">
26
+ # </li>
27
+ # </ol>
28
+ # </fieldset>
29
+ # </form>
30
+ #
31
+ # @example Specifying a label with a String
32
+ # <%= f.action :submit, :as => :button, :label => "Go" %>
33
+ #
34
+ # @example Pass HTML attributes down to the `<button>`
35
+ # <%= f.action :submit, :as => :button, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
36
+ #
37
+ # @example Access key can also be set as a top-level option
38
+ # <%= f.action :submit, :as => :button, :accesskey => 'g' %>
39
+ #
40
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
41
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
42
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
43
+ #
44
+ # @todo document i18n keys
45
+ # @todo document i18n translation with :label (?)
46
+ class ButtonAction
47
+ include Base
48
+ include Buttonish
49
+
50
+ # @see Formtastic::Helpers::ActionHelper#action
51
+ # @option *args :label [String, Symbol]
52
+ # Override the label text with a String or a symbol for an i18n translation key
53
+ #
54
+ # @option *args :button_html [Hash]
55
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
56
+ #
57
+ # @option *args :wrapper_html [Hash]
58
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
59
+
60
+ # TODO reset_action class?
61
+ def to_html
62
+ wrapper do
63
+ template.button_tag(text, button_html)
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+ module Buttonish
5
+
6
+ def supported_methods
7
+ [:submit, :reset]
8
+ end
9
+
10
+ def extra_button_html_options
11
+ {
12
+ :type => method
13
+ }
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+
5
+ # Outputs an `<input type="submit">` or `<input type="reset">` wrapped in the standard `<li>`
6
+ # wrapper. This the default for `:submit` and `:reset` actions, but `:as => :button` is also
7
+ # available as an alternative.
8
+ #
9
+ # @example The `:as` can be omitted, these are functionally equivalent
10
+ # <%= f.action :submit, :as => :input %>
11
+ # <%= f.action :submit %>
12
+ #
13
+ # @example Full form context and output
14
+ #
15
+ # <%= semantic_form_for(@post) do |f| %>
16
+ # <%= f.actions do %>
17
+ # <%= f.action :reset, :as => :input %>
18
+ # <%= f.action :submit, :as => :input %>
19
+ # <% end %>
20
+ # <% end %>
21
+ #
22
+ # <form...>
23
+ # <fieldset class="actions">
24
+ # <ol>
25
+ # <li class="action input_action" id="post_reset_action">
26
+ # <input type="reset" value="Reset">
27
+ # </li>
28
+ # <li class="action input_action" id="post_submit_action">
29
+ # <input type="submit" value="Create Post">
30
+ # </li>
31
+ # </ol>
32
+ # </fieldset>
33
+ # </form>
34
+ #
35
+ # @example Specifying a label with a String
36
+ # <%= f.action :submit, :as => :input, :label => "Go" %>
37
+ #
38
+ # @example Pass HTML attributes down to the `<input>`
39
+ # <%= f.action :submit, :as => :input, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
40
+ #
41
+ # @example Access key can also be set as a top-level option
42
+ # <%= f.action :submit, :as => :input, :accesskey => 'g' %>
43
+ #
44
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
45
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
46
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
47
+ # @todo document i18n keys
48
+ # @todo document i18n translation with :label (?)
49
+ class InputAction
50
+ include Base
51
+ include Buttonish
52
+
53
+ # @see Formtastic::Helpers::ActionHelper#action
54
+ # @option *args :label [String, Symbol]
55
+ # Override the label text with a String or a symbol for an i18n translation key
56
+ #
57
+ # @option *args :button_html [Hash]
58
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
59
+ #
60
+ # @option *args :wrapper_html [Hash]
61
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
62
+ #
63
+
64
+ def to_html
65
+ wrapper do
66
+ builder.submit(text, button_html)
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+ # Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
5
+ # The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
6
+ # browser's history), but can be altered with the `:url` option.
7
+ #
8
+ # @example The `:as` can be omitted, these are functionally equivalent
9
+ # <%= f.action :cancel, :as => :link %>
10
+ # <%= f.action :cancel %>
11
+ #
12
+ # @example Full form context and output
13
+ #
14
+ # <%= semantic_form_for(@post) do |f| %>
15
+ # <%= f.actions do %>
16
+ # <%= f.action :submit, :as => :input %>
17
+ # <%= f.action :cancel, :as => :link %>
18
+ # <% end %>
19
+ # <% end %>
20
+ #
21
+ # <form...>
22
+ # <fieldset class="actions">
23
+ # <ol>
24
+ # <li class="action input_action" id="post_submit_action">
25
+ # <input type="submit" value="Create Post">
26
+ # </li>
27
+ # <li class="action link_action" id="post_cancel_action">
28
+ # <a href="javascript:history.back()">Cancel</a>
29
+ # </li>
30
+ # </ol>
31
+ # </fieldset>
32
+ # </form>
33
+ #
34
+ # @example Modifying the URL for the link
35
+ # <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
36
+ # <%= f.action :cancel, :as => :link, :url => "/path" %>
37
+ # <%= f.action :cancel, :as => :link, :url => posts_path %>
38
+ # <%= f.action :cancel, :as => :link, :url => url_for(...) %>
39
+ # <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
40
+ #
41
+ # @example Specifying a label with a String
42
+ # <%= f.action :cancel, :as => :link, :label => "Stop" %>
43
+ #
44
+ # @example Pass HTML attributes down to the `<a>`
45
+ # <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
46
+ #
47
+ # @example Access key can also be set as a top-level option
48
+ # <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
49
+ #
50
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
51
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
52
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
53
+ #
54
+ # @todo document i18n keys
55
+ # @todo document i18n translation with :label (?)
56
+ # @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
57
+ class LinkAction
58
+ include Base
59
+
60
+ # @see Formtastic::Helpers::ActionHelper#action
61
+ # @option *args :label [String, Symbol]
62
+ # Override the label text with a String or a symbol for an i18n translation key
63
+ #
64
+ # @option *args :button_html [Hash]
65
+ # Override or add to the HTML attributes to be passed down to the `<a>` tag
66
+ #
67
+ # @option *args :wrapper_html [Hash]
68
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
69
+ #
70
+
71
+ def supported_methods
72
+ [:cancel]
73
+ end
74
+
75
+ # TODO reset_action class?
76
+ def to_html
77
+ wrapper do
78
+ template.link_to(text, url, button_html)
79
+ end
80
+ end
81
+
82
+ def url
83
+ return options[:url] if options.key?(:url)
84
+ :back
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ module Actions
4
+ extend ActiveSupport::Autoload
5
+
6
+ autoload :Base
7
+ autoload :Buttonish
8
+
9
+ eager_autoload do
10
+ autoload :InputAction
11
+ autoload :LinkAction
12
+ autoload :ButtonAction
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ require 'active_support/deprecation'
3
+
4
+ module Formtastic
5
+ Deprecation = ActiveSupport::Deprecation.new("5.0.0", "Formtastic")
6
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+ module Formtastic
3
+ class FormBuilder < ActionView::Helpers::FormBuilder
4
+
5
+ # Defines a new configurable option
6
+ # @param [Symbol] name the configuration name
7
+ # @param [Object] default the configuration default value
8
+ # @private
9
+ #
10
+ # @!macro [new] configure
11
+ # @!scope class
12
+ # @!attribute [rw] $1
13
+ # @api public
14
+ def self.configure(name, default = nil)
15
+ class_attribute(name)
16
+ self.send(:"#{name}=", default)
17
+ end
18
+
19
+ # Check {Formtastic::ActionClassFinder} to see how are inputs resolved.
20
+ configure :action_class_finder, Formtastic::ActionClassFinder
21
+ configure :action_namespaces, [::Object, ::Formtastic::Actions]
22
+ configure :all_fields_required_by_default, true
23
+ configure :collection_label_methods, %w[to_label display_name full_name name title username login value to_s]
24
+ configure :collection_value_methods, %w[id to_s]
25
+ configure :custom_namespace
26
+ configure :default_commit_button_accesskey
27
+ configure :default_error_list_class, 'errors'
28
+ configure :default_hint_class, 'inline-hints'
29
+ configure :default_inline_error_class, 'inline-errors'
30
+ configure :default_text_area_height, 20
31
+ configure :default_text_area_width
32
+ configure :default_text_field_size
33
+ configure :escape_html_entities_in_hints_and_labels, true
34
+ configure :file_metadata_suffixes, ['content_type', 'file_name', 'file_size']
35
+ configure :file_methods, [ :file?, :public_filename, :filename ]
36
+ configure :i18n_cache_lookups, true
37
+ configure :i18n_localizer, Formtastic::Localizer
38
+ configure :i18n_lookups_by_default, true
39
+ configure :include_blank_for_select_by_default, true
40
+ configure :inline_errors, :sentence
41
+ # Check {Formtastic::InputClassFinder} to see how are inputs resolved.
42
+ configure :input_class_finder, Formtastic::InputClassFinder
43
+ configure :input_namespaces, [::Object, ::Formtastic::Inputs]
44
+ configure :label_str_method, :humanize
45
+ configure :optional_string, ''
46
+ configure :perform_browser_validations, false
47
+ configure :priority_countries, ["Australia", "Canada", "United Kingdom", "United States"]
48
+ configure :priority_time_zones, []
49
+ configure :required_string, proc { %{<abbr title="#{Formtastic::I18n.t(:required)}">*</abbr>}.html_safe }
50
+ configure :semantic_errors_link_to_inputs, false
51
+ configure :skipped_columns, [:created_at, :updated_at, :created_on, :updated_on, :lock_version, :version]
52
+ configure :use_required_attribute, false
53
+
54
+ attr_reader :template
55
+
56
+ attr_reader :auto_index
57
+
58
+ include Formtastic::HtmlAttributes
59
+
60
+ include Formtastic::Helpers::InputHelper
61
+ include Formtastic::Helpers::InputsHelper
62
+ include Formtastic::Helpers::ActionHelper
63
+ include Formtastic::Helpers::ActionsHelper
64
+ include Formtastic::Helpers::ErrorsHelper
65
+
66
+ # This is a wrapper around Rails' `ActionView::Helpers::FormBuilder#fields_for`, originally
67
+ # provided to ensure that the `:builder` from `semantic_form_for` was passed down into
68
+ # the nested `fields_for`. Our supported versions of Rails no longer require us to do this,
69
+ # so this method is provided purely for backwards compatibility and DSL consistency.
70
+ #
71
+ # When constructing a `fields_for` form fragment *outside* of `semantic_form_for`, please use
72
+ # `Formtastic::Helpers::FormHelper#semantic_fields_for`.
73
+ #
74
+ # @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormBuilder.html#method-i-fields_for ActionView::Helpers::FormBuilder#fields_for
75
+ # @see https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-fields_for ActionView::Helpers::FormHelper#fields_for
76
+ # @see Formtastic::Helpers::FormHelper#semantic_fields_for
77
+ #
78
+ # @example
79
+ # <% semantic_form_for @post do |post| %>
80
+ # <% post.semantic_fields_for :author do |author| %>
81
+ # <% author.inputs :name %>
82
+ # <% end %>
83
+ # <% end %>
84
+ #
85
+ # <form ...>
86
+ # <fieldset class="inputs">
87
+ # <ol>
88
+ # <li class="string"><input type='text' name='post[author][name]' id='post_author_name' /></li>
89
+ # </ol>
90
+ # </fieldset>
91
+ # </form>
92
+ #
93
+ # @todo is there a way to test the params structure of the Rails helper we wrap to ensure forward compatibility?
94
+ def semantic_fields_for(record_or_name_or_array, *args, &block)
95
+ fields_for(record_or_name_or_array, *args, &block)
96
+ end
97
+
98
+ def initialize(object_name, object, template, options)
99
+ super
100
+
101
+ if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
102
+ self.multipart = options[:html][:multipart]
103
+ end
104
+ end
105
+
106
+ end
107
+
108
+ end
109
+