formtastic 2.1.0 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +4 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile +1 -1
  7. data/Gemfile.lock +105 -0
  8. data/MIT-LICENSE +1 -1
  9. data/{README.textile → README.md} +204 -219
  10. data/RELEASE_PROCESS +3 -1
  11. data/Rakefile +27 -29
  12. data/app/assets/stylesheets/formtastic.css +3 -2
  13. data/bin/appraisal +8 -0
  14. data/formtastic.gemspec +11 -14
  15. data/gemfiles/rails_5.2/Gemfile +5 -0
  16. data/gemfiles/rails_6.0/Gemfile +5 -0
  17. data/gemfiles/rails_6.1/Gemfile +5 -0
  18. data/gemfiles/rails_edge/Gemfile +13 -0
  19. data/lib/formtastic/action_class_finder.rb +18 -0
  20. data/lib/formtastic/actions/button_action.rb +55 -60
  21. data/lib/formtastic/actions/input_action.rb +59 -57
  22. data/lib/formtastic/actions/link_action.rb +68 -67
  23. data/lib/formtastic/actions.rb +6 -3
  24. data/lib/formtastic/deprecation.rb +5 -0
  25. data/lib/formtastic/engine.rb +3 -1
  26. data/lib/formtastic/form_builder.rb +35 -16
  27. data/lib/formtastic/helpers/action_helper.rb +34 -28
  28. data/lib/formtastic/helpers/enum.rb +13 -0
  29. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  30. data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -12
  31. data/lib/formtastic/helpers/form_helper.rb +19 -16
  32. data/lib/formtastic/helpers/input_helper.rb +69 -97
  33. data/lib/formtastic/helpers/inputs_helper.rb +35 -25
  34. data/lib/formtastic/helpers/reflection.rb +4 -4
  35. data/lib/formtastic/helpers.rb +1 -2
  36. data/lib/formtastic/html_attributes.rb +12 -1
  37. data/lib/formtastic/i18n.rb +1 -1
  38. data/lib/formtastic/input_class_finder.rb +18 -0
  39. data/lib/formtastic/inputs/base/choices.rb +2 -2
  40. data/lib/formtastic/inputs/base/collections.rb +46 -14
  41. data/lib/formtastic/inputs/base/database.rb +7 -2
  42. data/lib/formtastic/inputs/base/datetime_pickerish.rb +85 -0
  43. data/lib/formtastic/inputs/base/errors.rb +7 -7
  44. data/lib/formtastic/inputs/base/hints.rb +2 -2
  45. data/lib/formtastic/inputs/base/html.rb +10 -9
  46. data/lib/formtastic/inputs/base/labelling.rb +5 -8
  47. data/lib/formtastic/inputs/base/naming.rb +4 -4
  48. data/lib/formtastic/inputs/base/numeric.rb +1 -1
  49. data/lib/formtastic/inputs/base/options.rb +3 -4
  50. data/lib/formtastic/inputs/base/stringish.rb +10 -2
  51. data/lib/formtastic/inputs/base/timeish.rb +34 -22
  52. data/lib/formtastic/inputs/base/validations.rb +41 -13
  53. data/lib/formtastic/inputs/base/wrapping.rb +29 -26
  54. data/lib/formtastic/inputs/base.rb +22 -15
  55. data/lib/formtastic/inputs/boolean_input.rb +26 -12
  56. data/lib/formtastic/inputs/check_boxes_input.rb +39 -31
  57. data/lib/formtastic/inputs/color_input.rb +41 -0
  58. data/lib/formtastic/inputs/country_input.rb +24 -5
  59. data/lib/formtastic/inputs/datalist_input.rb +41 -0
  60. data/lib/formtastic/inputs/date_picker_input.rb +93 -0
  61. data/lib/formtastic/inputs/{date_input.rb → date_select_input.rb} +1 -1
  62. data/lib/formtastic/inputs/datetime_picker_input.rb +103 -0
  63. data/lib/formtastic/inputs/{datetime_input.rb → datetime_select_input.rb} +1 -1
  64. data/lib/formtastic/inputs/file_input.rb +2 -2
  65. data/lib/formtastic/inputs/hidden_input.rb +2 -6
  66. data/lib/formtastic/inputs/radio_input.rb +28 -22
  67. data/lib/formtastic/inputs/select_input.rb +36 -39
  68. data/lib/formtastic/inputs/time_picker_input.rb +99 -0
  69. data/lib/formtastic/inputs/{time_input.rb → time_select_input.rb} +6 -2
  70. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  71. data/lib/formtastic/inputs.rb +32 -21
  72. data/lib/formtastic/localized_string.rb +1 -1
  73. data/lib/formtastic/localizer.rb +24 -24
  74. data/lib/formtastic/namespaced_class_finder.rb +99 -0
  75. data/lib/formtastic/version.rb +1 -1
  76. data/lib/formtastic.rb +20 -10
  77. data/lib/generators/formtastic/form/form_generator.rb +10 -4
  78. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  79. data/lib/generators/formtastic/install/install_generator.rb +5 -19
  80. data/lib/generators/templates/_form.html.slim +2 -2
  81. data/lib/generators/templates/formtastic.rb +46 -25
  82. data/lib/generators/templates/input.rb +19 -0
  83. data/sample/basic_inputs.html +23 -3
  84. data/script/integration-template.rb +74 -0
  85. data/script/integration.sh +19 -0
  86. data/spec/action_class_finder_spec.rb +12 -0
  87. data/spec/actions/button_action_spec.rb +8 -8
  88. data/spec/actions/generic_action_spec.rb +92 -56
  89. data/spec/actions/input_action_spec.rb +7 -7
  90. data/spec/actions/link_action_spec.rb +10 -10
  91. data/spec/builder/custom_builder_spec.rb +36 -20
  92. data/spec/builder/error_proc_spec.rb +4 -4
  93. data/spec/builder/semantic_fields_for_spec.rb +28 -29
  94. data/spec/fast_spec_helper.rb +12 -0
  95. data/spec/generators/formtastic/form/form_generator_spec.rb +45 -32
  96. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  97. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  98. data/spec/helpers/action_helper_spec.rb +75 -103
  99. data/spec/helpers/actions_helper_spec.rb +17 -17
  100. data/spec/helpers/form_helper_spec.rb +84 -33
  101. data/spec/helpers/input_helper_spec.rb +333 -285
  102. data/spec/helpers/inputs_helper_spec.rb +167 -121
  103. data/spec/helpers/reflection_helper_spec.rb +3 -3
  104. data/spec/helpers/semantic_errors_helper_spec.rb +23 -23
  105. data/spec/i18n_spec.rb +26 -26
  106. data/spec/input_class_finder_spec.rb +10 -0
  107. data/spec/inputs/base/collections_spec.rb +76 -0
  108. data/spec/inputs/base/validations_spec.rb +480 -0
  109. data/spec/inputs/boolean_input_spec.rb +100 -65
  110. data/spec/inputs/check_boxes_input_spec.rb +200 -101
  111. data/spec/inputs/color_input_spec.rb +85 -0
  112. data/spec/inputs/country_input_spec.rb +20 -20
  113. data/spec/inputs/custom_input_spec.rb +3 -4
  114. data/spec/inputs/datalist_input_spec.rb +61 -0
  115. data/spec/inputs/date_picker_input_spec.rb +449 -0
  116. data/spec/inputs/date_select_input_spec.rb +249 -0
  117. data/spec/inputs/datetime_picker_input_spec.rb +490 -0
  118. data/spec/inputs/datetime_select_input_spec.rb +209 -0
  119. data/spec/inputs/email_input_spec.rb +5 -5
  120. data/spec/inputs/file_input_spec.rb +6 -6
  121. data/spec/inputs/hidden_input_spec.rb +22 -35
  122. data/spec/inputs/include_blank_spec.rb +11 -11
  123. data/spec/inputs/label_spec.rb +62 -25
  124. data/spec/inputs/number_input_spec.rb +112 -112
  125. data/spec/inputs/password_input_spec.rb +5 -5
  126. data/spec/inputs/phone_input_spec.rb +5 -5
  127. data/spec/inputs/placeholder_spec.rb +6 -6
  128. data/spec/inputs/radio_input_spec.rb +99 -55
  129. data/spec/inputs/range_input_spec.rb +66 -66
  130. data/spec/inputs/readonly_spec.rb +50 -0
  131. data/spec/inputs/search_input_spec.rb +5 -5
  132. data/spec/inputs/select_input_spec.rb +170 -170
  133. data/spec/inputs/string_input_spec.rb +68 -16
  134. data/spec/inputs/text_input_spec.rb +16 -16
  135. data/spec/inputs/time_picker_input_spec.rb +455 -0
  136. data/spec/inputs/time_select_input_spec.rb +261 -0
  137. data/spec/inputs/time_zone_input_spec.rb +54 -28
  138. data/spec/inputs/url_input_spec.rb +5 -5
  139. data/spec/inputs/with_options_spec.rb +7 -7
  140. data/spec/localizer_spec.rb +39 -17
  141. data/spec/namespaced_class_finder_spec.rb +79 -0
  142. data/spec/schema.rb +21 -0
  143. data/spec/spec_helper.rb +254 -221
  144. data/spec/support/custom_macros.rb +128 -95
  145. data/spec/support/shared_examples.rb +12 -0
  146. data/spec/support/specialized_class_finder_shared_example.rb +27 -0
  147. data/spec/support/test_environment.rb +26 -10
  148. metadata +177 -238
  149. data/.travis.yml +0 -8
  150. data/Appraisals +0 -11
  151. data/CHANGELOG +0 -371
  152. data/gemfiles/rails-3.0.gemfile +0 -7
  153. data/gemfiles/rails-3.1.gemfile +0 -7
  154. data/gemfiles/rails-3.2.gemfile +0 -7
  155. data/lib/formtastic/helpers/buttons_helper.rb +0 -310
  156. data/lib/formtastic/inputs/base/grouped_collections.rb +0 -77
  157. data/lib/formtastic/util.rb +0 -25
  158. data/lib/tasks/verify_rcov.rb +0 -44
  159. data/spec/helpers/buttons_helper_spec.rb +0 -166
  160. data/spec/helpers/commit_button_helper_spec.rb +0 -530
  161. data/spec/inputs/date_input_spec.rb +0 -227
  162. data/spec/inputs/datetime_input_spec.rb +0 -185
  163. data/spec/inputs/time_input_spec.rb +0 -267
  164. data/spec/support/deferred_garbage_collection.rb +0 -21
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,28 +1,42 @@
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
- require 'tasks/verify_rcov'
7
5
 
8
6
  Bundler::GemHelper.install_tasks
9
7
 
10
8
  desc 'Default: run unit specs.'
11
- task :default => :all
9
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
10
+ task :default => :appraisal
11
+ else
12
+ task :default => :spec
13
+ end
14
+
15
+ desc 'Run the default task over all gemfiles.'
16
+ task :appraisal do
17
+ for_all_gemfiles("exec", "rake")
18
+ end
12
19
 
13
- desc 'Test formtastic with all supported Rails versions.'
14
- task :all => ["appraisal:install"] do
15
- exec('rake appraisal spec')
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
16
33
  end
17
34
 
18
35
  desc 'Generate documentation for the formtastic plugin.'
19
- Rake::RDocTask.new(:rdoc) do |rdoc|
20
- rdoc.rdoc_dir = 'rdoc'
21
- rdoc.title = 'Formtastic'
22
- rdoc.options << '--line-numbers' << '--inline-source'
23
- rdoc.rdoc_files.include('README.textile')
24
- rdoc.rdoc_files.include('lib/**/*.rb')
36
+ YARD::Rake::YardocTask.new(:yard) do |t|
37
+
25
38
  end
39
+ task doc: :yard
26
40
 
27
41
  desc 'Test the formtastic plugin.'
28
42
  RSpec::Core::RakeTask.new('spec') do |t|
@@ -38,19 +52,3 @@ desc 'Test the formtastic plugin with specdoc formatting and colors'
38
52
  RSpec::Core::RakeTask.new('specdoc') do |t|
39
53
  t.pattern = FileList['spec/**/*_spec.rb']
40
54
  end
41
-
42
- desc 'Run all examples with RCov'
43
- RSpec::Core::RakeTask.new('rcov') do |t|
44
- t.pattern = FileList['spec/**/*_spec.rb']
45
- t.rcov = true
46
- t.rcov_opts = %w(--exclude gems/*,spec/*,.bundle/*, --aggregate coverage.data)
47
- end
48
-
49
- RCov::VerifyTask.new(:verify_coverage) do |t|
50
- t.require_exact_threshold = false
51
- t.threshold = (RUBY_VERSION == "1.8.7" ? 95 : 0)
52
- end
53
-
54
- desc "Run all examples and verify coverage"
55
- task :spec_and_verify_coverage => [:rcov, :verify_coverage] do
56
- end
@@ -194,7 +194,8 @@ This stylesheet forms part of the Formtastic Rails Plugin
194
194
  width:72%;
195
195
  }
196
196
 
197
- .formtastic .stringish input[size] {
197
+ .formtastic .stringish input[size],
198
+ .formtastic .stringish input[max] {
198
199
  width:auto;
199
200
  max-width:72%;
200
201
  }
@@ -222,7 +223,7 @@ This stylesheet forms part of the Formtastic Rails Plugin
222
223
  /* BOOLEAN LABELS
223
224
  --------------------------------------------------------------------------------------------------*/
224
225
  .formtastic .boolean label {
225
- padding-left:25%;
226
+ margin-left:25%;
226
227
  display:block;
227
228
  }
228
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,32 +8,29 @@ 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
+ s.license = 'MIT'
14
15
 
15
16
  s.files = `git ls-files`.split("\n")
16
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = []
18
19
  s.require_paths = ["lib"]
19
20
 
20
21
  s.rdoc_options = ["--charset=UTF-8"]
21
- s.extra_rdoc_files = ["README.textile"]
22
+ s.extra_rdoc_files = ["README.md"]
22
23
 
24
+ s.required_ruby_version = '>= 2.4.0'
23
25
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
24
26
  s.rubygems_version = %q{1.3.6}
25
27
 
26
- s.add_dependency(%q<actionpack>, ["~> 3.0"])
28
+ s.add_dependency(%q<actionpack>, [">= 5.2.0"])
27
29
 
28
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.8.0"])
29
- s.add_development_dependency(%q<rspec_tag_matchers>, [">= 1.0.0"])
30
- s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
31
- s.add_development_dependency(%q<BlueCloth>) # for YARD
32
- s.add_development_dependency(%q<yard>, ["~> 0.6"])
33
- s.add_development_dependency(%q<rcov>, ["~> 0.9.9"])
34
- s.add_development_dependency(%q<colored>)
35
- s.add_development_dependency(%q<tzinfo>)
36
- s.add_development_dependency(%q<ammeter>, ["~> 0.2.2"])
37
- s.add_development_dependency(%q<appraisal>)
30
+ s.add_development_dependency(%q<rspec-rails>, ["~> 3.4"])
31
+ s.add_development_dependency(%q<rspec-dom-testing>, [">= 0.1.0"])
32
+ s.add_development_dependency(%q<yard>, ["~> 0.9.20"])
33
+ s.add_development_dependency(%q<ammeter>, ["~> 1.1.3"])
38
34
  s.add_development_dependency(%q<rake>)
35
+ s.add_development_dependency(%q<sqlite3>, ["~> 1.4"])
39
36
  end
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", "~> 5.2.0"
4
+
5
+ gemspec path: "../.."
@@ -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,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rails", git: "https://github.com/rails/rails.git"
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,18 @@
1
+ module Formtastic
2
+
3
+ # Uses the {NamespacedClassFinder} to look up action class names.
4
+ #
5
+ # See {Formtastic::Helpers::ActionHelper#namespaced_action_class} for details.
6
+ #
7
+ class ActionClassFinder < NamespacedClassFinder
8
+
9
+ # @param builder [FormBuilder]
10
+ def initialize(builder)
11
+ super builder.action_namespaces
12
+ end
13
+
14
+ def class_name(as)
15
+ "#{super}Action"
16
+ end
17
+ end
18
+ end
@@ -1,72 +1,67 @@
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 (?)
51
1
  module Formtastic
52
2
  module Actions
53
- class ButtonAction
3
+
4
+ # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>`
5
+ # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with
6
+ # `<input type="submit">` and `<input type="reset">` by default.
7
+ #
8
+ # @example Full form context and output
9
+ #
10
+ # <%= semantic_form_for(@post) do |f| %>
11
+ # <%= f.actions do %>
12
+ # <%= f.action :reset, :as => :button %>
13
+ # <%= f.action :submit, :as => :button %>
14
+ # <% end %>
15
+ # <% end %>
16
+ #
17
+ # <form...>
18
+ # <fieldset class="actions">
19
+ # <ol>
20
+ # <li class="action button_action" id="post_reset_action">
21
+ # <button type="reset" value="Reset">
22
+ # </li>
23
+ # <li class="action button_action" id="post_submit_action">
24
+ # <button type="submit" value="Create Post">
25
+ # </li>
26
+ # </ol>
27
+ # </fieldset>
28
+ # </form>
29
+ #
30
+ # @example Specifying a label with a String
31
+ # <%= f.action :submit, :as => :button, :label => "Go" %>
32
+ #
33
+ # @example Pass HTML attributes down to the `<button>`
34
+ # <%= f.action :submit, :as => :button, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
35
+ #
36
+ # @example Access key can also be set as a top-level option
37
+ # <%= f.action :submit, :as => :button, :accesskey => 'g' %>
38
+ #
39
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
40
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
41
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
42
+ #
43
+ # @todo document i18n keys
44
+ # @todo document i18n translation with :label (?)
45
+ class ButtonAction
54
46
  include Base
55
47
  include Buttonish
56
-
57
- # TODO absolutely horrible hack to work-around Rails < 3.1 missing button_tag, need
58
- # to figure out something more appropriate.
48
+
49
+ # @see Formtastic::Helpers::ActionHelper#action
50
+ # @option *args :label [String, Symbol]
51
+ # Override the label text with a String or a symbol for an i18n translation key
59
52
  #
53
+ # @option *args :button_html [Hash]
54
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
55
+ #
56
+ # @option *args :wrapper_html [Hash]
57
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
58
+
60
59
  # TODO reset_action class?
61
60
  def to_html
62
61
  wrapper do
63
- if template.respond_to?(:button_tag)
64
- template.button_tag(text, button_html)
65
- else
66
- template.content_tag(:button, text, button_html)
67
- end
62
+ template.button_tag(text, button_html)
68
63
  end
69
64
  end
70
65
  end
71
66
  end
72
- end
67
+ end
@@ -1,63 +1,65 @@
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 (?)
55
1
  module Formtastic
56
2
  module Actions
57
- class InputAction
3
+
4
+ # Outputs an `<input type="submit">` or `<input type="reset">` wrapped in the standard `<li>`
5
+ # wrapper. This the default for `:submit` and `:reset` actions, but `:as => :button` is also
6
+ # available as an alternative.
7
+ #
8
+ # @example The `:as` can be ommitted, these are functionally equivalent
9
+ # <%= f.action :submit, :as => :input %>
10
+ # <%= f.action :submit %>
11
+ #
12
+ # @example Full form context and output
13
+ #
14
+ # <%= semantic_form_for(@post) do |f| %>
15
+ # <%= f.actions do %>
16
+ # <%= f.action :reset, :as => :input %>
17
+ # <%= f.action :submit, :as => :input %>
18
+ # <% end %>
19
+ # <% end %>
20
+ #
21
+ # <form...>
22
+ # <fieldset class="actions">
23
+ # <ol>
24
+ # <li class="action input_action" id="post_reset_action">
25
+ # <input type="reset" value="Reset">
26
+ # </li>
27
+ # <li class="action input_action" id="post_submit_action">
28
+ # <input type="submit" value="Create Post">
29
+ # </li>
30
+ # </ol>
31
+ # </fieldset>
32
+ # </form>
33
+ #
34
+ # @example Specifying a label with a String
35
+ # <%= f.action :submit, :as => :input, :label => "Go" %>
36
+ #
37
+ # @example Pass HTML attributes down to the `<input>`
38
+ # <%= f.action :submit, :as => :input, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
39
+ #
40
+ # @example Access key can also be set as a top-level option
41
+ # <%= f.action :submit, :as => :input, :accesskey => 'g' %>
42
+ #
43
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
44
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
45
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
46
+ # @todo document i18n keys
47
+ # @todo document i18n translation with :label (?)
48
+ class InputAction
58
49
  include Base
59
50
  include Buttonish
60
-
51
+
52
+ # @see Formtastic::Helpers::ActionHelper#action
53
+ # @option *args :label [String, Symbol]
54
+ # Override the label text with a String or a symbol for an i18n translation key
55
+ #
56
+ # @option *args :button_html [Hash]
57
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
58
+ #
59
+ # @option *args :wrapper_html [Hash]
60
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
61
+ #
62
+
61
63
  def to_html
62
64
  wrapper do
63
65
  builder.submit(text, button_html)
@@ -65,4 +67,4 @@ module Formtastic
65
67
  end
66
68
  end
67
69
  end
68
- end
70
+ end
@@ -1,82 +1,83 @@
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)
63
1
  module Formtastic
64
2
  module Actions
65
- class LinkAction
66
-
3
+ # Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
4
+ # The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
5
+ # browser's history), but can be altered with the `:url` option.
6
+ #
7
+ # @example The `:as` can be ommitted, these are functionally equivalent
8
+ # <%= f.action :cancel, :as => :link %>
9
+ # <%= f.action :cancel %>
10
+ #
11
+ # @example Full form context and output
12
+ #
13
+ # <%= semantic_form_for(@post) do |f| %>
14
+ # <%= f.actions do %>
15
+ # <%= f.action :submit, :as => :input %>
16
+ # <%= f.action :cancel, :as => :link %>
17
+ # <% end %>
18
+ # <% end %>
19
+ #
20
+ # <form...>
21
+ # <fieldset class="actions">
22
+ # <ol>
23
+ # <li class="action input_action" id="post_submit_action">
24
+ # <input type="submit" value="Create Post">
25
+ # </li>
26
+ # <li class="action link_action" id="post_cancel_action">
27
+ # <a href="javascript:history.back()">Cancel</a>
28
+ # </li>
29
+ # </ol>
30
+ # </fieldset>
31
+ # </form>
32
+ #
33
+ # @example Modifying the URL for the link
34
+ # <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
35
+ # <%= f.action :cancel, :as => :link, :url => "/path" %>
36
+ # <%= f.action :cancel, :as => :link, :url => posts_path %>
37
+ # <%= f.action :cancel, :as => :link, :url => url_for(...) %>
38
+ # <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
39
+ #
40
+ # @example Specifying a label with a String
41
+ # <%= f.action :cancel, :as => :link, :label => "Stop" %>
42
+ #
43
+ # @example Pass HTML attributes down to the `<a>`
44
+ # <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
45
+ #
46
+ # @example Access key can also be set as a top-level option
47
+ # <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
48
+ #
49
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
50
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
51
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
52
+ #
53
+ # @todo document i18n keys
54
+ # @todo document i18n translation with :label (?)
55
+ # @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
56
+ class LinkAction
67
57
  include Base
68
-
58
+
59
+ # @see Formtastic::Helpers::ActionHelper#action
60
+ # @option *args :label [String, Symbol]
61
+ # Override the label text with a String or a symbol for an i18n translation key
62
+ #
63
+ # @option *args :button_html [Hash]
64
+ # Override or add to the HTML attributes to be passed down to the `<a>` tag
65
+ #
66
+ # @option *args :wrapper_html [Hash]
67
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
68
+ #
69
+
69
70
  def supported_methods
70
71
  [:cancel]
71
72
  end
72
-
73
+
73
74
  # TODO reset_action class?
74
75
  def to_html
75
76
  wrapper do
76
77
  template.link_to(text, url, button_html)
77
78
  end
78
79
  end
79
-
80
+
80
81
  def url
81
82
  return options[:url] if options.key?(:url)
82
83
  :back
@@ -4,8 +4,11 @@ module Formtastic
4
4
 
5
5
  autoload :Base
6
6
  autoload :Buttonish
7
- autoload :InputAction
8
- autoload :LinkAction
9
- autoload :ButtonAction
7
+
8
+ eager_autoload do
9
+ autoload :InputAction
10
+ autoload :LinkAction
11
+ autoload :ButtonAction
12
+ end
10
13
  end
11
14
  end
@@ -0,0 +1,5 @@
1
+ require 'active_support/deprecation'
2
+
3
+ module Formtastic
4
+ Deprecation = ActiveSupport::Deprecation
5
+ end
@@ -7,5 +7,7 @@ module Formtastic
7
7
  include Formtastic::Helpers::FormHelper
8
8
  end
9
9
  end
10
+
11
+ config.eager_load_namespaces << Formtastic
10
12
  end
11
- end
13
+ end