formtastic 3.0.0 → 5.0.0

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 (175) hide show
  1. checksums.yaml +5 -13
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +3 -2
  5. data/CHANGELOG.md +61 -0
  6. data/Gemfile.lock +140 -0
  7. data/MIT-LICENSE +1 -1
  8. data/{README.textile → README.md} +191 -168
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +24 -8
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +13 -17
  14. data/gemfiles/rails_6.0/Gemfile +5 -0
  15. data/gemfiles/rails_6.1/Gemfile +5 -0
  16. data/gemfiles/rails_7.0/Gemfile +5 -0
  17. data/gemfiles/rails_7.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +19 -0
  20. data/lib/formtastic/actions/base.rb +1 -0
  21. data/lib/formtastic/actions/button_action.rb +56 -53
  22. data/lib/formtastic/actions/buttonish.rb +1 -0
  23. data/lib/formtastic/actions/input_action.rb +60 -57
  24. data/lib/formtastic/actions/link_action.rb +69 -67
  25. data/lib/formtastic/actions.rb +7 -3
  26. data/lib/formtastic/deprecation.rb +6 -0
  27. data/lib/formtastic/engine.rb +4 -1
  28. data/lib/formtastic/form_builder.rb +32 -25
  29. data/lib/formtastic/helpers/action_helper.rb +22 -31
  30. data/lib/formtastic/helpers/actions_helper.rb +1 -0
  31. data/lib/formtastic/helpers/enum.rb +14 -0
  32. data/lib/formtastic/helpers/errors_helper.rb +3 -2
  33. data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
  34. data/lib/formtastic/helpers/file_column_detection.rb +1 -0
  35. data/lib/formtastic/helpers/form_helper.rb +4 -3
  36. data/lib/formtastic/helpers/input_helper.rb +59 -80
  37. data/lib/formtastic/helpers/inputs_helper.rb +33 -27
  38. data/lib/formtastic/helpers/reflection.rb +5 -4
  39. data/lib/formtastic/helpers.rb +2 -2
  40. data/lib/formtastic/html_attributes.rb +13 -1
  41. data/lib/formtastic/i18n.rb +2 -1
  42. data/lib/formtastic/input_class_finder.rb +19 -0
  43. data/lib/formtastic/inputs/base/associations.rb +1 -0
  44. data/lib/formtastic/inputs/base/choices.rb +4 -3
  45. data/lib/formtastic/inputs/base/collections.rb +47 -11
  46. data/lib/formtastic/inputs/base/database.rb +8 -5
  47. data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
  48. data/lib/formtastic/inputs/base/errors.rb +7 -6
  49. data/lib/formtastic/inputs/base/fileish.rb +1 -0
  50. data/lib/formtastic/inputs/base/hints.rb +2 -1
  51. data/lib/formtastic/inputs/base/html.rb +12 -10
  52. data/lib/formtastic/inputs/base/labelling.rb +3 -2
  53. data/lib/formtastic/inputs/base/naming.rb +5 -4
  54. data/lib/formtastic/inputs/base/numeric.rb +1 -0
  55. data/lib/formtastic/inputs/base/options.rb +3 -3
  56. data/lib/formtastic/inputs/base/placeholder.rb +1 -0
  57. data/lib/formtastic/inputs/base/stringish.rb +1 -0
  58. data/lib/formtastic/inputs/base/timeish.rb +9 -4
  59. data/lib/formtastic/inputs/base/validations.rb +39 -12
  60. data/lib/formtastic/inputs/base/wrapping.rb +2 -3
  61. data/lib/formtastic/inputs/base.rb +17 -12
  62. data/lib/formtastic/inputs/boolean_input.rb +2 -1
  63. data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
  64. data/lib/formtastic/inputs/color_input.rb +1 -1
  65. data/lib/formtastic/inputs/country_input.rb +4 -1
  66. data/lib/formtastic/inputs/datalist_input.rb +42 -0
  67. data/lib/formtastic/inputs/date_picker_input.rb +1 -0
  68. data/lib/formtastic/inputs/date_select_input.rb +1 -0
  69. data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
  70. data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
  71. data/lib/formtastic/inputs/email_input.rb +1 -0
  72. data/lib/formtastic/inputs/file_input.rb +3 -2
  73. data/lib/formtastic/inputs/hidden_input.rb +3 -2
  74. data/lib/formtastic/inputs/number_input.rb +1 -0
  75. data/lib/formtastic/inputs/password_input.rb +1 -0
  76. data/lib/formtastic/inputs/phone_input.rb +1 -0
  77. data/lib/formtastic/inputs/radio_input.rb +26 -21
  78. data/lib/formtastic/inputs/range_input.rb +1 -0
  79. data/lib/formtastic/inputs/search_input.rb +1 -0
  80. data/lib/formtastic/inputs/select_input.rb +32 -10
  81. data/lib/formtastic/inputs/string_input.rb +1 -0
  82. data/lib/formtastic/inputs/text_input.rb +1 -0
  83. data/lib/formtastic/inputs/time_picker_input.rb +1 -0
  84. data/lib/formtastic/inputs/time_select_input.rb +1 -0
  85. data/lib/formtastic/inputs/time_zone_input.rb +17 -6
  86. data/lib/formtastic/inputs/url_input.rb +1 -0
  87. data/lib/formtastic/inputs.rb +33 -28
  88. data/lib/formtastic/localized_string.rb +2 -1
  89. data/lib/formtastic/localizer.rb +23 -24
  90. data/lib/formtastic/namespaced_class_finder.rb +98 -0
  91. data/lib/formtastic/version.rb +2 -1
  92. data/lib/formtastic.rb +19 -14
  93. data/lib/generators/formtastic/form/form_generator.rb +8 -2
  94. data/lib/generators/formtastic/input/input_generator.rb +47 -0
  95. data/lib/generators/formtastic/install/install_generator.rb +2 -0
  96. data/lib/generators/templates/formtastic.rb +29 -7
  97. data/lib/generators/templates/input.rb +19 -0
  98. data/sample/basic_inputs.html +1 -1
  99. data/script/integration-template.rb +73 -0
  100. data/script/integration.sh +19 -0
  101. data/spec/action_class_finder_spec.rb +13 -0
  102. data/spec/actions/button_action_spec.rb +21 -20
  103. data/spec/actions/generic_action_spec.rb +134 -133
  104. data/spec/actions/input_action_spec.rb +20 -19
  105. data/spec/actions/link_action_spec.rb +30 -29
  106. data/spec/builder/custom_builder_spec.rb +39 -22
  107. data/spec/builder/error_proc_spec.rb +6 -5
  108. data/spec/builder/semantic_fields_for_spec.rb +46 -45
  109. data/spec/fast_spec_helper.rb +13 -0
  110. data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
  111. data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
  112. data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
  113. data/spec/helpers/action_helper_spec.rb +70 -97
  114. data/spec/helpers/actions_helper_spec.rb +43 -42
  115. data/spec/helpers/form_helper_spec.rb +56 -39
  116. data/spec/helpers/input_helper_spec.rb +314 -255
  117. data/spec/helpers/inputs_helper_spec.rb +217 -202
  118. data/spec/helpers/reflection_helper_spec.rb +7 -6
  119. data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
  120. data/spec/i18n_spec.rb +30 -29
  121. data/spec/input_class_finder_spec.rb +11 -0
  122. data/spec/inputs/base/collections_spec.rb +78 -0
  123. data/spec/inputs/base/validations_spec.rb +481 -0
  124. data/spec/inputs/boolean_input_spec.rb +73 -72
  125. data/spec/inputs/check_boxes_input_spec.rb +174 -123
  126. data/spec/inputs/color_input_spec.rb +53 -64
  127. data/spec/inputs/country_input_spec.rb +23 -22
  128. data/spec/inputs/custom_input_spec.rb +3 -6
  129. data/spec/inputs/datalist_input_spec.rb +62 -0
  130. data/spec/inputs/date_picker_input_spec.rb +114 -113
  131. data/spec/inputs/date_select_input_spec.rb +76 -61
  132. data/spec/inputs/datetime_picker_input_spec.rb +123 -122
  133. data/spec/inputs/datetime_select_input_spec.rb +85 -68
  134. data/spec/inputs/email_input_spec.rb +17 -16
  135. data/spec/inputs/file_input_spec.rb +18 -17
  136. data/spec/inputs/hidden_input_spec.rb +32 -31
  137. data/spec/inputs/include_blank_spec.rb +10 -9
  138. data/spec/inputs/label_spec.rb +36 -31
  139. data/spec/inputs/number_input_spec.rb +212 -211
  140. data/spec/inputs/password_input_spec.rb +17 -16
  141. data/spec/inputs/phone_input_spec.rb +17 -16
  142. data/spec/inputs/placeholder_spec.rb +18 -17
  143. data/spec/inputs/radio_input_spec.rb +92 -65
  144. data/spec/inputs/range_input_spec.rb +136 -135
  145. data/spec/inputs/readonly_spec.rb +51 -0
  146. data/spec/inputs/search_input_spec.rb +16 -15
  147. data/spec/inputs/select_input_spec.rb +209 -102
  148. data/spec/inputs/string_input_spec.rb +51 -50
  149. data/spec/inputs/text_input_spec.rb +34 -33
  150. data/spec/inputs/time_picker_input_spec.rb +115 -114
  151. data/spec/inputs/time_select_input_spec.rb +84 -70
  152. data/spec/inputs/time_zone_input_spec.rb +58 -31
  153. data/spec/inputs/url_input_spec.rb +17 -16
  154. data/spec/inputs/with_options_spec.rb +9 -8
  155. data/spec/localizer_spec.rb +18 -17
  156. data/spec/namespaced_class_finder_spec.rb +91 -0
  157. data/spec/schema.rb +22 -0
  158. data/spec/spec_helper.rb +180 -249
  159. data/spec/support/custom_macros.rb +128 -98
  160. data/spec/support/deprecation.rb +2 -1
  161. data/spec/support/shared_examples.rb +13 -0
  162. data/spec/support/specialized_class_finder_shared_example.rb +28 -0
  163. data/spec/support/test_environment.rb +25 -10
  164. metadata +95 -136
  165. data/.travis.yml +0 -28
  166. data/Appraisals +0 -25
  167. data/CHANGELOG +0 -27
  168. data/gemfiles/rails_3.2.gemfile +0 -7
  169. data/gemfiles/rails_4.0.4.gemfile +0 -7
  170. data/gemfiles/rails_4.1.gemfile +0 -7
  171. data/gemfiles/rails_4.gemfile +0 -7
  172. data/gemfiles/rails_edge.gemfile +0 -10
  173. data/lib/formtastic/util.rb +0 -53
  174. data/spec/support/deferred_garbage_collection.rb +0 -21
  175. data/spec/util_spec.rb +0 -52
data/RELEASE_PROCESS CHANGED
@@ -1,4 +1,6 @@
1
- # edit version.rb
1
+ # review and edit CHANGELOG
2
+ # review & edit README
3
+ # edit lib/formtastic/version.rb
2
4
  git ci -am "version bump" # commit changes
3
5
  git tag X.X.X # tag the new version in the code base too
4
6
  gem build formtastic.gemspec # build the gem
data/Rakefile CHANGED
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require 'bundler/setup'
3
- require 'appraisal'
4
- require 'rdoc/task'
3
+ require 'yard'
5
4
  require 'rspec/core/rake_task'
6
5
 
7
6
  Bundler::GemHelper.install_tasks
@@ -13,14 +12,31 @@ else
13
12
  task :default => :spec
14
13
  end
15
14
 
15
+ desc 'Run the default task over all gemfiles.'
16
+ task :appraisal do
17
+ for_all_gemfiles("exec", "rake")
18
+ end
19
+
20
+ namespace :appraisal do
21
+ desc 'Run `bundle install` over all gemfiles.'
22
+ task :install do
23
+ for_all_gemfiles("install")
24
+ end
25
+ end
26
+
27
+ def for_all_gemfiles(*args)
28
+ Dir.glob("gemfiles/*/Gemfile").sort.each do |gemfile|
29
+ Bundler.with_original_env do
30
+ sh({ "APPRAISAL_INITIALIZED" => "true", "BUNDLE_GEMFILE" => gemfile }, "bundle", *args)
31
+ end
32
+ end
33
+ end
34
+
16
35
  desc 'Generate documentation for the formtastic plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'Formtastic'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README.textile')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
36
+ YARD::Rake::YardocTask.new(:yard) do |t|
37
+
23
38
  end
39
+ task doc: :yard
24
40
 
25
41
  desc 'Test the formtastic plugin.'
26
42
  RSpec::Core::RakeTask.new('spec') do |t|
@@ -223,7 +223,7 @@ This stylesheet forms part of the Formtastic Rails Plugin
223
223
  /* BOOLEAN LABELS
224
224
  --------------------------------------------------------------------------------------------------*/
225
225
  .formtastic .boolean label {
226
- padding-left:25%;
226
+ margin-left:25%;
227
227
  display:block;
228
228
  }
229
229
 
data/bin/appraisal ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [ "$1" = "" ]
4
+ then
5
+ bundle exec rake appraisal
6
+ else
7
+ bundle exec rake "appraisal:$1"
8
+ fi
data/formtastic.gemspec CHANGED
@@ -8,35 +8,31 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = [%q{Justin French}]
10
10
  s.email = [%q{justin@indent.com.au}]
11
- s.homepage = %q{http://github.com/justinfrench/formtastic}
11
+ s.homepage = %q{http://github.com/formtastic/formtastic}
12
12
  s.summary = %q{A Rails form builder plugin/gem with semantically rich and accessible markup}
13
13
  s.description = %q{A Rails form builder plugin/gem with semantically rich and accessible markup}
14
14
  s.license = 'MIT'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = []
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.rdoc_options = ["--charset=UTF-8"]
22
- s.extra_rdoc_files = ["README.textile"]
22
+ s.extra_rdoc_files = ["README.md"]
23
23
 
24
- s.required_ruby_version = '>= 1.9.3'
24
+ s.required_ruby_version = '>= 2.6.0'
25
25
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
26
26
  s.rubygems_version = %q{1.3.6}
27
27
 
28
- s.add_dependency(%q<actionpack>, [">= 3.2.13"])
28
+ s.add_dependency(%q<actionpack>, [">= 6.0.0"])
29
29
 
30
- s.add_development_dependency(%q<nokogiri>, ["< 1.6.0"]) # 1.6 requires Ruby 1.9.2, drop in v3.0
31
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.14"])
32
- s.add_development_dependency(%q<rspec_tag_matchers>, ["~> 1.0"])
33
- s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
34
- s.add_development_dependency(%q<BlueCloth>, ["~> 1.0"]) # for YARD
35
- s.add_development_dependency(%q<yard>, ["~> 0.6"])
36
- s.add_development_dependency(%q<colored>, ["~> 1.2"])
37
- s.add_development_dependency(%q<tzinfo>)
38
- s.add_development_dependency(%q<ammeter>, ["0.2.5"])
39
- s.add_development_dependency(%q<appraisal>, ["~> 1.0"])
40
- s.add_development_dependency(%q<rake>, ["<= 10.1.1"]) # Anything higher requires Ruby 1.9, drop in v3.0
41
- s.add_development_dependency(%q<activemodel>, [">= 3.2.13"])
30
+ s.add_development_dependency(%q<rspec-rails>, [">= 4.0"])
31
+ s.add_development_dependency(%q<rspec-dom-testing>, [">= 0.1.0"])
32
+ s.add_development_dependency(%q<rspec-mocks>, ["~> 3.12.2"])
33
+
34
+ s.add_development_dependency(%q<yard>, ["~> 0.9.20"])
35
+ s.add_development_dependency(%q<ammeter>, ["~> 1.1.3"])
36
+ s.add_development_dependency(%q<rake>)
37
+ s.add_development_dependency(%q<sqlite3>, ["~> 1.4"])
42
38
  end
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.0.2"
4
+
5
+ gemspec path: "../.."
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 6.1.0"
4
+
5
+ gemspec path: "../.."
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 7.0.0"
4
+
5
+ gemspec path: "../.."
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 7.1.0"
4
+
5
+ gemspec path: "../.."
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", git: "https://github.com/rails/rails.git", branch: "main"
4
+ gem "rack", git: "https://github.com/rack/rack.git"
5
+ gem "i18n", git: "https://github.com/svenfuchs/i18n.git"
6
+ gem "arel", git: "https://github.com/rails/arel.git"
7
+ gem "rspec-rails", git: "https://github.com/rspec/rspec-rails.git"
8
+ gem "rspec-mocks", git: "https://github.com/rspec/rspec-mocks.git"
9
+ gem "rspec-support", git: "https://github.com/rspec/rspec-support.git"
10
+ gem "rspec-core", git: "https://github.com/rspec/rspec-core.git"
11
+ gem "rspec-expectations", git: "https://github.com/rspec/rspec-expectations.git"
12
+
13
+ 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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Formtastic
2
3
  module Actions
3
4
  module Base
@@ -1,59 +1,62 @@
1
- # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>`
2
- # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with
3
- # `<input type="submit">` and `<input type="reset">` by default.
4
- #
5
- # @example Full form context and output
6
- #
7
- # <%= semantic_form_for(@post) do |f| %>
8
- # <%= f.actions do %>
9
- # <%= f.action :reset, :as => :button %>
10
- # <%= f.action :submit, :as => :button %>
11
- # <% end %>
12
- # <% end %>
13
- #
14
- # <form...>
15
- # <fieldset class="actions">
16
- # <ol>
17
- # <li class="action button_action" id="post_reset_action">
18
- # <button type="reset" value="Reset">
19
- # </li>
20
- # <li class="action button_action" id="post_submit_action">
21
- # <button type="submit" value="Create Post">
22
- # </li>
23
- # </ol>
24
- # </fieldset>
25
- # </form>
26
- #
27
- # @example Specifying a label with a String
28
- # <%= f.action :submit, :as => :button, :label => "Go" %>
29
- #
30
- # @example Pass HTML attributes down to the `<button>`
31
- # <%= f.action :submit, :as => :button, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
32
- #
33
- # @example Access key can also be set as a top-level option
34
- # <%= f.action :submit, :as => :button, :accesskey => 'g' %>
35
- #
36
- # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
37
- # <%= f.action :submit, :as => :button, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
38
- # <%= f.action :submit, :as => :button, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
39
- #
40
- # @option *args :label [String, Symbol]
41
- # Override the label text with a String or a symbol for an i18n translation key
42
- #
43
- # @option *args :button_html [Hash]
44
- # Override or add to the HTML attributes to be passed down to the `<input>` tag
45
- #
46
- # @option *args :wrapper_html [Hash]
47
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
48
- #
49
- # @todo document i18n keys
50
- # @todo document i18n translation with :label (?)
1
+ # frozen_string_literal: true
51
2
  module Formtastic
52
3
  module Actions
53
- class ButtonAction
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
54
47
  include Base
55
48
  include Buttonish
56
-
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
+
57
60
  # TODO reset_action class?
58
61
  def to_html
59
62
  wrapper do
@@ -62,4 +65,4 @@ module Formtastic
62
65
  end
63
66
  end
64
67
  end
65
- end
68
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Formtastic
2
3
  module Actions
3
4
  module Buttonish
@@ -1,63 +1,66 @@
1
- # Outputs an `<input type="submit">` or `<input type="reset">` wrapped in the standard `<li>`
2
- # wrapper. This the default for `:submit` and `:reset` actions, but `:as => :button` is also
3
- # available as an alternative.
4
- #
5
- # @example The `:as` can be ommitted, these are functionally equivalent
6
- # <%= f.action :submit, :as => :input %>
7
- # <%= f.action :submit %>
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 => :input %>
14
- # <%= f.action :submit, :as => :input %>
15
- # <% end %>
16
- # <% end %>
17
- #
18
- # <form...>
19
- # <fieldset class="actions">
20
- # <ol>
21
- # <li class="action input_action" id="post_reset_action">
22
- # <input type="reset" value="Reset">
23
- # </li>
24
- # <li class="action input_action" id="post_submit_action">
25
- # <input 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 => :input, :label => "Go" %>
33
- #
34
- # @example Pass HTML attributes down to the `<input>`
35
- # <%= f.action :submit, :as => :input, :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 => :input, :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 => :input, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
42
- # <%= f.action :submit, :as => :input, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
43
- #
44
- # @option *args :label [String, Symbol]
45
- # Override the label text with a String or a symbol for an i18n translation key
46
- #
47
- # @option *args :button_html [Hash]
48
- # Override or add to the HTML attributes to be passed down to the `<input>` tag
49
- #
50
- # @option *args :wrapper_html [Hash]
51
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
52
- #
53
- # @todo document i18n keys
54
- # @todo document i18n translation with :label (?)
1
+ # frozen_string_literal: true
55
2
  module Formtastic
56
3
  module Actions
57
- class InputAction
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 ommitted, 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
58
50
  include Base
59
51
  include Buttonish
60
-
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
+
61
64
  def to_html
62
65
  wrapper do
63
66
  builder.submit(text, button_html)
@@ -65,4 +68,4 @@ module Formtastic
65
68
  end
66
69
  end
67
70
  end
68
- end
71
+ end
@@ -1,82 +1,84 @@
1
- # Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
2
- # The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
3
- # browser's history), but can be altered with the `:url` option.
4
- #
5
- # @example The `:as` can be ommitted, these are functionally equivalent
6
- # <%= f.action :cancel, :as => :link %>
7
- # <%= f.action :cancel %>
8
- #
9
- # @example Full form context and output
10
- #
11
- # <%= semantic_form_for(@post) do |f| %>
12
- # <%= f.actions do %>
13
- # <%= f.action :submit, :as => :input %>
14
- # <%= f.action :cancel, :as => :link %>
15
- # <% end %>
16
- # <% end %>
17
- #
18
- # <form...>
19
- # <fieldset class="actions">
20
- # <ol>
21
- # <li class="action input_action" id="post_submit_action">
22
- # <input type="submit" value="Create Post">
23
- # </li>
24
- # <li class="action link_action" id="post_cancel_action">
25
- # <a href="javascript:history.back()">Cancel</a>
26
- # </li>
27
- # </ol>
28
- # </fieldset>
29
- # </form>
30
- #
31
- # @example Modifying the URL for the link
32
- # <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
33
- # <%= f.action :cancel, :as => :link, :url => "/path" %>
34
- # <%= f.action :cancel, :as => :link, :url => posts_path %>
35
- # <%= f.action :cancel, :as => :link, :url => url_for(...) %>
36
- # <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
37
- #
38
- # @example Specifying a label with a String
39
- # <%= f.action :cancel, :as => :link, :label => "Stop" %>
40
- #
41
- # @example Pass HTML attributes down to the `<a>`
42
- # <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
43
- #
44
- # @example Access key can also be set as a top-level option
45
- # <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
46
- #
47
- # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
48
- # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
49
- # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
50
- #
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 `<a>` 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 document i18n keys
61
- # @todo document i18n translation with :label (?)
62
- # @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
1
+ # frozen_string_literal: true
63
2
  module Formtastic
64
3
  module Actions
65
- class LinkAction
66
-
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 ommitted, 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
67
58
  include Base
68
-
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
+
69
71
  def supported_methods
70
72
  [:cancel]
71
73
  end
72
-
74
+
73
75
  # TODO reset_action class?
74
76
  def to_html
75
77
  wrapper do
76
78
  template.link_to(text, url, button_html)
77
79
  end
78
80
  end
79
-
81
+
80
82
  def url
81
83
  return options[:url] if options.key?(:url)
82
84
  :back
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
1
2
  module Formtastic
2
3
  module Actions
3
4
  extend ActiveSupport::Autoload
4
5
 
5
6
  autoload :Base
6
7
  autoload :Buttonish
7
- autoload :InputAction
8
- autoload :LinkAction
9
- autoload :ButtonAction
8
+
9
+ eager_autoload do
10
+ autoload :InputAction
11
+ autoload :LinkAction
12
+ autoload :ButtonAction
13
+ end
10
14
  end
11
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
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Formtastic
2
3
  # Required for formtastic.css to be discoverable in the asset pipeline
3
4
  # @private
@@ -7,5 +8,7 @@ module Formtastic
7
8
  include Formtastic::Helpers::FormHelper
8
9
  end
9
10
  end
11
+
12
+ config.eager_load_namespaces << Formtastic
10
13
  end
11
- end
14
+ end