formtastic 3.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.gitattributes +1 -0
- data/.github/workflows/test.yml +61 -0
- data/.gitignore +3 -2
- data/CHANGELOG.md +61 -0
- data/Gemfile.lock +140 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +191 -168
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +24 -8
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +13 -17
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_7.0/Gemfile +5 -0
- data/gemfiles/rails_7.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic/action_class_finder.rb +19 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +56 -53
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +60 -57
- data/lib/formtastic/actions/link_action.rb +69 -67
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +6 -0
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +32 -25
- data/lib/formtastic/helpers/action_helper.rb +22 -31
- data/lib/formtastic/helpers/actions_helper.rb +1 -0
- data/lib/formtastic/helpers/enum.rb +14 -0
- data/lib/formtastic/helpers/errors_helper.rb +3 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +16 -11
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +4 -3
- data/lib/formtastic/helpers/input_helper.rb +59 -80
- data/lib/formtastic/helpers/inputs_helper.rb +33 -27
- data/lib/formtastic/helpers/reflection.rb +5 -4
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +13 -1
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +19 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +4 -3
- data/lib/formtastic/inputs/base/collections.rb +47 -11
- data/lib/formtastic/inputs/base/database.rb +8 -5
- data/lib/formtastic/inputs/base/datetime_pickerish.rb +1 -0
- data/lib/formtastic/inputs/base/errors.rb +7 -6
- data/lib/formtastic/inputs/base/fileish.rb +1 -0
- data/lib/formtastic/inputs/base/hints.rb +2 -1
- data/lib/formtastic/inputs/base/html.rb +12 -10
- data/lib/formtastic/inputs/base/labelling.rb +3 -2
- data/lib/formtastic/inputs/base/naming.rb +5 -4
- data/lib/formtastic/inputs/base/numeric.rb +1 -0
- data/lib/formtastic/inputs/base/options.rb +3 -3
- data/lib/formtastic/inputs/base/placeholder.rb +1 -0
- data/lib/formtastic/inputs/base/stringish.rb +1 -0
- data/lib/formtastic/inputs/base/timeish.rb +9 -4
- data/lib/formtastic/inputs/base/validations.rb +39 -12
- data/lib/formtastic/inputs/base/wrapping.rb +2 -3
- data/lib/formtastic/inputs/base.rb +17 -12
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +16 -24
- data/lib/formtastic/inputs/color_input.rb +1 -1
- data/lib/formtastic/inputs/country_input.rb +4 -1
- data/lib/formtastic/inputs/datalist_input.rb +42 -0
- data/lib/formtastic/inputs/date_picker_input.rb +1 -0
- data/lib/formtastic/inputs/date_select_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_picker_input.rb +1 -0
- data/lib/formtastic/inputs/datetime_select_input.rb +1 -0
- data/lib/formtastic/inputs/email_input.rb +1 -0
- data/lib/formtastic/inputs/file_input.rb +3 -2
- data/lib/formtastic/inputs/hidden_input.rb +3 -2
- data/lib/formtastic/inputs/number_input.rb +1 -0
- data/lib/formtastic/inputs/password_input.rb +1 -0
- data/lib/formtastic/inputs/phone_input.rb +1 -0
- data/lib/formtastic/inputs/radio_input.rb +26 -21
- data/lib/formtastic/inputs/range_input.rb +1 -0
- data/lib/formtastic/inputs/search_input.rb +1 -0
- data/lib/formtastic/inputs/select_input.rb +32 -10
- data/lib/formtastic/inputs/string_input.rb +1 -0
- data/lib/formtastic/inputs/text_input.rb +1 -0
- data/lib/formtastic/inputs/time_picker_input.rb +1 -0
- data/lib/formtastic/inputs/time_select_input.rb +1 -0
- data/lib/formtastic/inputs/time_zone_input.rb +17 -6
- data/lib/formtastic/inputs/url_input.rb +1 -0
- data/lib/formtastic/inputs.rb +33 -28
- data/lib/formtastic/localized_string.rb +2 -1
- data/lib/formtastic/localizer.rb +23 -24
- data/lib/formtastic/namespaced_class_finder.rb +98 -0
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +19 -14
- data/lib/generators/formtastic/form/form_generator.rb +8 -2
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +2 -0
- data/lib/generators/templates/formtastic.rb +29 -7
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +73 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +13 -0
- data/spec/actions/button_action_spec.rb +21 -20
- data/spec/actions/generic_action_spec.rb +134 -133
- data/spec/actions/input_action_spec.rb +20 -19
- data/spec/actions/link_action_spec.rb +30 -29
- data/spec/builder/custom_builder_spec.rb +39 -22
- data/spec/builder/error_proc_spec.rb +6 -5
- data/spec/builder/semantic_fields_for_spec.rb +46 -45
- data/spec/fast_spec_helper.rb +13 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +33 -32
- data/spec/generators/formtastic/input/input_generator_spec.rb +125 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +10 -9
- data/spec/helpers/action_helper_spec.rb +70 -97
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +56 -39
- data/spec/helpers/input_helper_spec.rb +314 -255
- data/spec/helpers/inputs_helper_spec.rb +217 -202
- data/spec/helpers/reflection_helper_spec.rb +7 -6
- data/spec/helpers/semantic_errors_helper_spec.rb +26 -25
- data/spec/i18n_spec.rb +30 -29
- data/spec/input_class_finder_spec.rb +11 -0
- data/spec/inputs/base/collections_spec.rb +78 -0
- data/spec/inputs/base/validations_spec.rb +481 -0
- data/spec/inputs/boolean_input_spec.rb +73 -72
- data/spec/inputs/check_boxes_input_spec.rb +174 -123
- data/spec/inputs/color_input_spec.rb +53 -64
- data/spec/inputs/country_input_spec.rb +23 -22
- data/spec/inputs/custom_input_spec.rb +3 -6
- data/spec/inputs/datalist_input_spec.rb +62 -0
- data/spec/inputs/date_picker_input_spec.rb +114 -113
- data/spec/inputs/date_select_input_spec.rb +76 -61
- data/spec/inputs/datetime_picker_input_spec.rb +123 -122
- data/spec/inputs/datetime_select_input_spec.rb +85 -68
- data/spec/inputs/email_input_spec.rb +17 -16
- data/spec/inputs/file_input_spec.rb +18 -17
- data/spec/inputs/hidden_input_spec.rb +32 -31
- data/spec/inputs/include_blank_spec.rb +10 -9
- data/spec/inputs/label_spec.rb +36 -31
- data/spec/inputs/number_input_spec.rb +212 -211
- data/spec/inputs/password_input_spec.rb +17 -16
- data/spec/inputs/phone_input_spec.rb +17 -16
- data/spec/inputs/placeholder_spec.rb +18 -17
- data/spec/inputs/radio_input_spec.rb +92 -65
- data/spec/inputs/range_input_spec.rb +136 -135
- data/spec/inputs/readonly_spec.rb +51 -0
- data/spec/inputs/search_input_spec.rb +16 -15
- data/spec/inputs/select_input_spec.rb +209 -102
- data/spec/inputs/string_input_spec.rb +51 -50
- data/spec/inputs/text_input_spec.rb +34 -33
- data/spec/inputs/time_picker_input_spec.rb +115 -114
- data/spec/inputs/time_select_input_spec.rb +84 -70
- data/spec/inputs/time_zone_input_spec.rb +58 -31
- data/spec/inputs/url_input_spec.rb +17 -16
- data/spec/inputs/with_options_spec.rb +9 -8
- data/spec/localizer_spec.rb +18 -17
- data/spec/namespaced_class_finder_spec.rb +91 -0
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +180 -249
- data/spec/support/custom_macros.rb +128 -98
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +13 -0
- data/spec/support/specialized_class_finder_shared_example.rb +28 -0
- data/spec/support/test_environment.rb +25 -10
- metadata +95 -136
- data/.travis.yml +0 -28
- data/Appraisals +0 -25
- data/CHANGELOG +0 -27
- data/gemfiles/rails_3.2.gemfile +0 -7
- data/gemfiles/rails_4.0.4.gemfile +0 -7
- data/gemfiles/rails_4.1.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -53
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -52
data/RELEASE_PROCESS
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'bundler/setup'
|
3
|
-
require '
|
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::
|
18
|
-
|
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
|
-
|
226
|
+
margin-left:25%;
|
227
227
|
display:block;
|
228
228
|
}
|
229
229
|
|
data/bin/appraisal
ADDED
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/
|
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 =
|
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.
|
22
|
+
s.extra_rdoc_files = ["README.md"]
|
23
23
|
|
24
|
-
s.required_ruby_version = '>=
|
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>, [">=
|
28
|
+
s.add_dependency(%q<actionpack>, [">= 6.0.0"])
|
29
29
|
|
30
|
-
s.add_development_dependency(%q<
|
31
|
-
s.add_development_dependency(%q<rspec-
|
32
|
-
s.add_development_dependency(%q<
|
33
|
-
|
34
|
-
s.add_development_dependency(%q<
|
35
|
-
s.add_development_dependency(%q<
|
36
|
-
s.add_development_dependency(%q<
|
37
|
-
s.add_development_dependency(%q<
|
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,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,59 +1,62 @@
|
|
1
|
-
#
|
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
|
-
|
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,63 +1,66 @@
|
|
1
|
-
#
|
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
|
-
|
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
|
-
#
|
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
|
-
|
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
|
data/lib/formtastic/actions.rb
CHANGED
@@ -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
|
-
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
eager_autoload do
|
10
|
+
autoload :InputAction
|
11
|
+
autoload :LinkAction
|
12
|
+
autoload :ButtonAction
|
13
|
+
end
|
10
14
|
end
|
11
15
|
end
|
data/lib/formtastic/engine.rb
CHANGED
@@ -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
|