formtastic 3.1.3 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- 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} +183 -167
- data/RELEASE_PROCESS +3 -1
- data/Rakefile +20 -1
- data/app/assets/stylesheets/formtastic.css +1 -1
- data/bin/appraisal +8 -0
- data/formtastic.gemspec +12 -16
- 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 +1 -0
- data/lib/formtastic/actions/base.rb +1 -0
- data/lib/formtastic/actions/button_action.rb +1 -0
- data/lib/formtastic/actions/buttonish.rb +1 -0
- data/lib/formtastic/actions/input_action.rb +1 -0
- data/lib/formtastic/actions/link_action.rb +1 -0
- data/lib/formtastic/actions.rb +7 -3
- data/lib/formtastic/deprecation.rb +2 -38
- data/lib/formtastic/engine.rb +4 -1
- data/lib/formtastic/form_builder.rb +12 -24
- data/lib/formtastic/helpers/action_helper.rb +2 -48
- 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 +14 -9
- data/lib/formtastic/helpers/file_column_detection.rb +1 -0
- data/lib/formtastic/helpers/form_helper.rb +2 -1
- data/lib/formtastic/helpers/input_helper.rb +20 -76
- data/lib/formtastic/helpers/inputs_helper.rb +29 -23
- data/lib/formtastic/helpers/reflection.rb +1 -0
- data/lib/formtastic/helpers.rb +2 -2
- data/lib/formtastic/html_attributes.rb +1 -0
- data/lib/formtastic/i18n.rb +2 -1
- data/lib/formtastic/input_class_finder.rb +1 -0
- data/lib/formtastic/inputs/base/associations.rb +1 -0
- data/lib/formtastic/inputs/base/choices.rb +3 -2
- data/lib/formtastic/inputs/base/collections.rb +46 -10
- data/lib/formtastic/inputs/base/database.rb +5 -7
- 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 +9 -7
- 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 +1 -0
- data/lib/formtastic/inputs/base.rb +3 -2
- data/lib/formtastic/inputs/boolean_input.rb +2 -1
- data/lib/formtastic/inputs/check_boxes_input.rb +15 -6
- 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 +1 -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 +1 -0
- 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 +21 -0
- 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 +30 -1
- 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 -29
- data/lib/formtastic/localized_string.rb +1 -0
- data/lib/formtastic/localizer.rb +21 -22
- data/lib/formtastic/namespaced_class_finder.rb +8 -9
- data/lib/formtastic/version.rb +2 -1
- data/lib/formtastic.rb +10 -11
- data/lib/generators/formtastic/form/form_generator.rb +2 -1
- data/lib/generators/formtastic/input/input_generator.rb +47 -0
- data/lib/generators/formtastic/install/install_generator.rb +1 -0
- data/lib/generators/templates/formtastic.rb +15 -13
- 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 +2 -1
- 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 +329 -10
- data/spec/helpers/actions_helper_spec.rb +43 -42
- data/spec/helpers/form_helper_spec.rb +45 -38
- data/spec/helpers/input_helper_spec.rb +976 -2
- 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 +2 -1
- 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 +169 -121
- 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 +3 -2
- 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 +26 -25
- 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 +18 -6
- data/spec/schema.rb +22 -0
- data/spec/spec_helper.rb +172 -260
- data/spec/support/custom_macros.rb +74 -76
- data/spec/support/deprecation.rb +2 -1
- data/spec/support/shared_examples.rb +2 -1233
- data/spec/support/specialized_class_finder_shared_example.rb +1 -0
- data/spec/support/test_environment.rb +24 -9
- metadata +78 -170
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -39
- data/DEPRECATIONS +0 -49
- 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.2.gemfile +0 -7
- data/gemfiles/rails_4.gemfile +0 -7
- data/gemfiles/rails_edge.gemfile +0 -10
- data/lib/formtastic/util.rb +0 -57
- data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
- data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
- data/spec/support/deferred_garbage_collection.rb +0 -21
- data/spec/util_spec.rb +0 -66
data/RELEASE_PROCESS
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'bundler/setup'
|
3
|
-
require 'appraisal'
|
4
3
|
require 'yard'
|
5
4
|
require 'rspec/core/rake_task'
|
6
5
|
|
@@ -13,6 +12,26 @@ 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
36
|
YARD::Rake::YardocTask.new(:yard) do |t|
|
18
37
|
|
@@ -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<colored>, ["~> 1.2"])
|
37
|
-
s.add_development_dependency(%q<tzinfo>)
|
38
|
-
s.add_development_dependency(%q<ammeter>, ["1.1.1"])
|
39
|
-
s.add_development_dependency(%q<appraisal>, ["~> 1.0"])
|
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"])
|
40
36
|
s.add_development_dependency(%q<rake>)
|
41
|
-
s.add_development_dependency(%q<
|
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: "../.."
|
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
|
@@ -1,42 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
require 'active_support/deprecation'
|
2
3
|
|
3
4
|
module Formtastic
|
4
|
-
|
5
|
-
Deprecation = ActiveSupport::Deprecation
|
6
|
-
else
|
7
|
-
require 'forwardable'
|
8
|
-
|
9
|
-
# @private
|
10
|
-
# @todo remove this branch and file when support for rails 3.2 is dropped
|
11
|
-
class Deprecation
|
12
|
-
mattr_accessor :deprecation
|
13
|
-
self.deprecation = ActiveSupport::Deprecation.dup
|
14
|
-
|
15
|
-
extend Forwardable
|
16
|
-
methods = deprecation.methods - deprecation.class.methods
|
17
|
-
def_delegators :deprecation, *methods
|
18
|
-
|
19
|
-
def initialize(version, _library)
|
20
|
-
deprecation.silenced = false
|
21
|
-
deprecation.deprecation_horizon = version
|
22
|
-
end
|
23
|
-
|
24
|
-
def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil)
|
25
|
-
caller_backtrace ||= caller(2)
|
26
|
-
|
27
|
-
deprecated_method_warning(deprecated_method_name, message).tap do |msg|
|
28
|
-
warn(msg, caller_backtrace)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
def deprecated_method_warning(method_name, message = nil)
|
33
|
-
warning = "#{method_name} is deprecated and will be removed from Formtastic #{deprecation_horizon}"
|
34
|
-
case message
|
35
|
-
when Symbol then "#{warning} (use #{message} instead)"
|
36
|
-
when String then "#{warning} (#{message})"
|
37
|
-
else warning
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
5
|
+
Deprecation = ActiveSupport::Deprecation.new("5.0.0", "Formtastic")
|
42
6
|
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
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Formtastic
|
2
3
|
class FormBuilder < ActionView::Helpers::FormBuilder
|
3
4
|
|
@@ -21,7 +22,7 @@ module Formtastic
|
|
21
22
|
configure :default_text_area_width
|
22
23
|
configure :all_fields_required_by_default, true
|
23
24
|
configure :include_blank_for_select_by_default, true
|
24
|
-
configure :required_string, proc {
|
25
|
+
configure :required_string, proc { %{<abbr title="#{Formtastic::I18n.t(:required)}">*</abbr>}.html_safe }
|
25
26
|
configure :optional_string, ''
|
26
27
|
configure :inline_errors, :sentence
|
27
28
|
configure :label_str_method, :humanize
|
@@ -42,14 +43,13 @@ module Formtastic
|
|
42
43
|
configure :perform_browser_validations, false
|
43
44
|
# Check {Formtastic::InputClassFinder} to see how are inputs resolved.
|
44
45
|
configure :input_namespaces, [::Object, ::Formtastic::Inputs]
|
45
|
-
|
46
|
-
# Will be {Formtastic::InputClassFinder} by default in 4.0.
|
47
|
-
configure :input_class_finder #, Formtastic::InputClassFinder
|
46
|
+
configure :input_class_finder, Formtastic::InputClassFinder
|
48
47
|
# Check {Formtastic::ActionClassFinder} to see how are inputs resolved.
|
49
48
|
configure :action_namespaces, [::Object, ::Formtastic::Actions]
|
50
|
-
|
51
|
-
|
52
|
-
configure :
|
49
|
+
configure :action_class_finder, Formtastic::ActionClassFinder
|
50
|
+
|
51
|
+
configure :skipped_columns, [:created_at, :updated_at, :created_on, :updated_on, :lock_version, :version]
|
52
|
+
configure :priority_time_zones, []
|
53
53
|
|
54
54
|
attr_reader :template
|
55
55
|
|
@@ -65,8 +65,8 @@ module Formtastic
|
|
65
65
|
|
66
66
|
# This is a wrapper around Rails' `ActionView::Helpers::FormBuilder#fields_for`, originally
|
67
67
|
# provided to ensure that the `:builder` from `semantic_form_for` was passed down into
|
68
|
-
# the nested `fields_for`. Rails
|
69
|
-
# provided purely for backwards compatibility and DSL consistency.
|
68
|
+
# the nested `fields_for`. Our supported versions of Rails no longer require us to do this,
|
69
|
+
# so this method is provided purely for backwards compatibility and DSL consistency.
|
70
70
|
#
|
71
71
|
# When constructing a `fields_for` form fragment *outside* of `semantic_form_for`, please use
|
72
72
|
# `Formtastic::Helpers::FormHelper#semantic_fields_for`.
|
@@ -92,23 +92,11 @@ module Formtastic
|
|
92
92
|
#
|
93
93
|
# @todo is there a way to test the params structure of the Rails helper we wrap to ensure forward compatibility?
|
94
94
|
def semantic_fields_for(record_or_name_or_array, *args, &block)
|
95
|
-
|
96
|
-
options = args.extract_options!
|
97
|
-
options[:parent_builder] ||= self
|
98
|
-
|
99
|
-
# Wrap the Rails helper
|
100
|
-
fields_for(record_or_name_or_array, *(args << options), &block)
|
95
|
+
fields_for(record_or_name_or_array, *args, &block)
|
101
96
|
end
|
102
97
|
|
103
|
-
def initialize(object_name, object, template, options
|
104
|
-
|
105
|
-
# rails 4.0 deprecated the block parameter and does nothing with it
|
106
|
-
# rails 4.1 removes the parameter completely
|
107
|
-
if Util.rails3? || Util.rails4_0?
|
108
|
-
super
|
109
|
-
else # Must be rails4_1 or greater
|
110
|
-
super object_name, object, template, options
|
111
|
-
end
|
98
|
+
def initialize(object_name, object, template, options)
|
99
|
+
super
|
112
100
|
|
113
101
|
if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
|
114
102
|
self.multipart = options[:html][:multipart]
|
@@ -1,10 +1,8 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
+
# frozen_string_literal: true
|
2
3
|
module Formtastic
|
3
4
|
module Helpers
|
4
5
|
module ActionHelper
|
5
|
-
ACTION_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.action_class_finder instead (upgrade guide on wiki: http://bit.ly/1F9QtKc )'.freeze
|
6
|
-
private_constant(:ACTION_CLASS_DEPRECATION)
|
7
|
-
|
8
6
|
# Renders an action for the form (such as a subit/reset button, or a cancel link).
|
9
7
|
#
|
10
8
|
# Each action is wrapped in an `<li class="action">` tag with other classes added based on the
|
@@ -82,7 +80,7 @@ module Formtastic
|
|
82
80
|
options = options.dup # Allow options to be shared without being tainted by Formtastic
|
83
81
|
options[:as] ||= default_action_type(method, options)
|
84
82
|
|
85
|
-
klass =
|
83
|
+
klass = namespaced_action_class(options[:as])
|
86
84
|
|
87
85
|
klass.new(self, template, @object, @object_name, method, options).to_html
|
88
86
|
end
|
@@ -113,50 +111,6 @@ module Formtastic
|
|
113
111
|
rescue Formtastic::ActionClassFinder::NotFoundError => e
|
114
112
|
raise Formtastic::UnknownActionError, "Unable to find action #{e.message}"
|
115
113
|
end
|
116
|
-
|
117
|
-
# @api private
|
118
|
-
# @deprecated Use {#namespaced_action_class} instead.
|
119
|
-
def action_class(as)
|
120
|
-
return namespaced_action_class(as) if action_class_finder
|
121
|
-
|
122
|
-
action_class_deprecation_warning(__method__)
|
123
|
-
|
124
|
-
@input_classes_cache ||= {}
|
125
|
-
@input_classes_cache[as] ||= begin
|
126
|
-
begin
|
127
|
-
begin
|
128
|
-
custom_action_class_name(as).constantize
|
129
|
-
rescue NameError
|
130
|
-
standard_action_class_name(as).constantize
|
131
|
-
end
|
132
|
-
rescue NameError
|
133
|
-
raise Formtastic::UnknownActionError, "Unable to find action #{as}"
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# @api private
|
139
|
-
# @deprecated Use {Formtastic::ActionClassFinder#class_name} instead.
|
140
|
-
# :as => :button # => ButtonAction
|
141
|
-
def custom_action_class_name(as)
|
142
|
-
action_class_deprecation_warning(__method__)
|
143
|
-
"#{as.to_s.camelize}Action"
|
144
|
-
end
|
145
|
-
|
146
|
-
# @api private
|
147
|
-
# @deprecated Use {Formtastic::ActionClassFinder#class_name} instead.
|
148
|
-
# :as => :button # => Formtastic::Actions::ButtonAction
|
149
|
-
def standard_action_class_name(as)
|
150
|
-
action_class_deprecation_warning(__method__)
|
151
|
-
"Formtastic::Actions::#{as.to_s.camelize}Action"
|
152
|
-
end
|
153
|
-
|
154
|
-
private
|
155
|
-
|
156
|
-
def action_class_deprecation_warning(method)
|
157
|
-
@action_class_deprecation_warned ||=
|
158
|
-
Formtastic.deprecation.deprecation_warning(method, ACTION_CLASS_DEPRECATION, caller(2))
|
159
|
-
end
|
160
114
|
end
|
161
115
|
end
|
162
116
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Formtastic
|
3
|
+
module Helpers
|
4
|
+
# @private
|
5
|
+
module Enum
|
6
|
+
# Returns the enum (if defined) for the given method
|
7
|
+
def enum_for(method) # @private
|
8
|
+
if @object.respond_to?(:defined_enums)
|
9
|
+
@object.defined_enums[method.to_s]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Formtastic
|
2
3
|
module Helpers
|
3
4
|
module ErrorsHelper
|
@@ -52,7 +53,7 @@ module Formtastic
|
|
52
53
|
return nil if full_errors.blank?
|
53
54
|
html_options[:class] ||= "errors"
|
54
55
|
template.content_tag(:ul, html_options) do
|
55
|
-
|
56
|
+
full_errors.map { |error| template.content_tag(:li, error) }.join.html_safe
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -78,4 +79,4 @@ module Formtastic
|
|
78
79
|
end
|
79
80
|
end
|
80
81
|
end
|
81
|
-
end
|
82
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Formtastic
|
2
3
|
module Helpers
|
3
4
|
# @private
|
@@ -22,7 +23,7 @@ module Formtastic
|
|
22
23
|
# f.inputs :my_little_legend, :title, :body, :author # Localized (118n) legend with I18n key => I18n.t(:my_little_legend, ...)
|
23
24
|
# f.inputs :title, :body, :author # First argument is a column => (no legend)
|
24
25
|
def field_set_and_list_wrapping(*args, &block) # @private
|
25
|
-
contents = args.
|
26
|
+
contents = args[-1].is_a?(::Hash) ? '' : args.pop.flatten
|
26
27
|
html_options = args.extract_options!
|
27
28
|
|
28
29
|
if block_given?
|
@@ -33,12 +34,15 @@ module Formtastic
|
|
33
34
|
end
|
34
35
|
end
|
35
36
|
|
37
|
+
# Work-around for empty contents block
|
38
|
+
contents ||= ""
|
39
|
+
|
36
40
|
# Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
|
37
41
|
contents = contents.join if contents.respond_to?(:join)
|
38
42
|
|
39
43
|
legend = field_set_legend(html_options)
|
40
44
|
fieldset = template.content_tag(:fieldset,
|
41
|
-
|
45
|
+
legend.html_safe << template.content_tag(:ol, contents.html_safe),
|
42
46
|
html_options.except(:builder, :parent, :name)
|
43
47
|
)
|
44
48
|
|
@@ -47,8 +51,9 @@ module Formtastic
|
|
47
51
|
|
48
52
|
def field_set_legend(html_options)
|
49
53
|
legend = (html_options[:name] || '').to_s
|
50
|
-
|
51
|
-
legend
|
54
|
+
# only applying if String includes '%i' avoids argument error when $DEBUG is true
|
55
|
+
legend %= parent_child_index(html_options[:parent]) if html_options[:parent] && legend.include?('%i')
|
56
|
+
legend = template.content_tag(:legend, template.content_tag(:span, legend.html_safe)) unless legend.blank?
|
52
57
|
legend
|
53
58
|
end
|
54
59
|
|
@@ -57,20 +62,20 @@ module Formtastic
|
|
57
62
|
def parent_child_index(parent) # @private
|
58
63
|
# Could be {"post[authors_attributes]"=>0} or { :authors => 0 }
|
59
64
|
duck = parent[:builder].instance_variable_get('@nested_child_index')
|
60
|
-
|
65
|
+
|
61
66
|
# Could be symbol for the association, or a model (or an array of either, I think? TODO)
|
62
67
|
child = parent[:for]
|
63
68
|
# Pull a sybol or model out of Array (TODO: check if there's an Array)
|
64
69
|
child = child.first if child.respond_to?(:first)
|
65
70
|
# If it's an object, get a symbol from the class name
|
66
71
|
child = child.class.name.underscore.to_sym unless child.is_a?(Symbol)
|
67
|
-
|
72
|
+
|
68
73
|
key = "#{parent[:builder].object_name}[#{child}_attributes]"
|
69
74
|
|
70
|
-
# TODO: One of the tests produces a scenario where duck is "0" and the test looks for a "1"
|
75
|
+
# TODO: One of the tests produces a scenario where duck is "0" and the test looks for a "1"
|
71
76
|
# in the legend, so if we have a number, return it with a +1 until we can verify this scenario.
|
72
|
-
return duck + 1 if duck.is_a?(
|
73
|
-
|
77
|
+
return duck + 1 if duck.is_a?(Integer)
|
78
|
+
|
74
79
|
# First try to extract key from duck Hash, then try child
|
75
80
|
(duck[key] || duck[child]).to_i + 1
|
76
81
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module Formtastic
|
2
3
|
module Helpers
|
3
4
|
|
@@ -163,7 +164,7 @@ module Formtastic
|
|
163
164
|
class_names << @@default_form_class
|
164
165
|
model_class_name = case record_or_name_or_array
|
165
166
|
when String, Symbol then record_or_name_or_array.to_s # :post => "post"
|
166
|
-
when Array then options[:as] || singularizer.call(record_or_name_or_array.
|
167
|
+
when Array then options[:as] || singularizer.call(record_or_name_or_array[-1].class) # [@post, @comment] # => "comment"
|
167
168
|
else options[:as] || singularizer.call(record_or_name_or_array.class) # @post => "post"
|
168
169
|
end
|
169
170
|
class_names << @@default_form_model_class_proc.call(model_class_name)
|