formtastic 3.1.2 → 4.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 +52 -0
- data/Gemfile.lock +105 -0
- data/MIT-LICENSE +1 -1
- data/{README.textile → README.md} +178 -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 +10 -16
- data/gemfiles/rails_5.2/Gemfile +5 -0
- data/gemfiles/rails_6.0/Gemfile +5 -0
- data/gemfiles/rails_6.1/Gemfile +5 -0
- data/gemfiles/rails_edge/Gemfile +13 -0
- data/lib/formtastic.rb +9 -11
- data/lib/formtastic/actions.rb +6 -3
- data/lib/formtastic/deprecation.rb +1 -38
- data/lib/formtastic/engine.rb +3 -1
- data/lib/formtastic/form_builder.rb +11 -24
- data/lib/formtastic/helpers.rb +1 -1
- data/lib/formtastic/helpers/action_helper.rb +1 -48
- data/lib/formtastic/helpers/enum.rb +13 -0
- data/lib/formtastic/helpers/errors_helper.rb +2 -2
- data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
- data/lib/formtastic/helpers/form_helper.rb +1 -1
- data/lib/formtastic/helpers/input_helper.rb +23 -77
- data/lib/formtastic/helpers/inputs_helper.rb +27 -22
- data/lib/formtastic/i18n.rb +1 -1
- data/lib/formtastic/inputs.rb +32 -29
- data/lib/formtastic/inputs/base/choices.rb +1 -1
- data/lib/formtastic/inputs/base/collections.rb +43 -10
- data/lib/formtastic/inputs/base/database.rb +7 -2
- data/lib/formtastic/inputs/base/errors.rb +4 -4
- data/lib/formtastic/inputs/base/hints.rb +1 -1
- data/lib/formtastic/inputs/base/html.rb +7 -6
- data/lib/formtastic/inputs/base/naming.rb +4 -4
- data/lib/formtastic/inputs/base/options.rb +2 -3
- data/lib/formtastic/inputs/base/timeish.rb +5 -1
- data/lib/formtastic/inputs/base/validations.rb +38 -12
- data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
- data/lib/formtastic/inputs/color_input.rb +0 -1
- data/lib/formtastic/inputs/country_input.rb +3 -1
- data/lib/formtastic/inputs/radio_input.rb +20 -0
- data/lib/formtastic/inputs/select_input.rb +29 -1
- data/lib/formtastic/inputs/time_zone_input.rb +16 -6
- data/lib/formtastic/localizer.rb +20 -22
- data/lib/formtastic/namespaced_class_finder.rb +1 -1
- data/lib/formtastic/version.rb +1 -1
- data/lib/generators/formtastic/form/form_generator.rb +1 -1
- data/lib/generators/formtastic/input/input_generator.rb +46 -0
- data/lib/generators/templates/formtastic.rb +14 -13
- data/lib/generators/templates/input.rb +19 -0
- data/sample/basic_inputs.html +1 -1
- data/script/integration-template.rb +74 -0
- data/script/integration.sh +19 -0
- data/spec/action_class_finder_spec.rb +1 -1
- data/spec/actions/button_action_spec.rb +8 -8
- data/spec/actions/generic_action_spec.rb +60 -60
- data/spec/actions/input_action_spec.rb +7 -7
- data/spec/actions/link_action_spec.rb +10 -10
- data/spec/builder/custom_builder_spec.rb +37 -21
- data/spec/builder/error_proc_spec.rb +4 -4
- data/spec/builder/semantic_fields_for_spec.rb +27 -27
- data/spec/fast_spec_helper.rb +12 -0
- data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
- data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
- data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
- data/spec/helpers/action_helper_spec.rb +328 -10
- data/spec/helpers/actions_helper_spec.rb +17 -17
- data/spec/helpers/form_helper_spec.rb +37 -37
- data/spec/helpers/input_helper_spec.rb +975 -2
- data/spec/helpers/inputs_helper_spec.rb +120 -105
- data/spec/helpers/reflection_helper_spec.rb +3 -3
- data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
- data/spec/i18n_spec.rb +26 -26
- data/spec/input_class_finder_spec.rb +1 -1
- data/spec/inputs/base/collections_spec.rb +76 -0
- data/spec/inputs/base/validations_spec.rb +480 -0
- data/spec/inputs/boolean_input_spec.rb +55 -55
- data/spec/inputs/check_boxes_input_spec.rb +155 -108
- data/spec/inputs/color_input_spec.rb +51 -63
- data/spec/inputs/country_input_spec.rb +20 -20
- data/spec/inputs/custom_input_spec.rb +2 -6
- data/spec/inputs/datalist_input_spec.rb +1 -1
- data/spec/inputs/date_picker_input_spec.rb +42 -42
- data/spec/inputs/date_select_input_spec.rb +51 -37
- data/spec/inputs/datetime_picker_input_spec.rb +46 -46
- data/spec/inputs/datetime_select_input_spec.rb +53 -37
- data/spec/inputs/email_input_spec.rb +5 -5
- data/spec/inputs/file_input_spec.rb +6 -6
- data/spec/inputs/hidden_input_spec.rb +18 -18
- data/spec/inputs/include_blank_spec.rb +8 -8
- data/spec/inputs/label_spec.rb +20 -20
- data/spec/inputs/number_input_spec.rb +112 -112
- data/spec/inputs/password_input_spec.rb +5 -5
- data/spec/inputs/phone_input_spec.rb +5 -5
- data/spec/inputs/placeholder_spec.rb +5 -5
- data/spec/inputs/radio_input_spec.rb +84 -58
- data/spec/inputs/range_input_spec.rb +66 -66
- data/spec/inputs/readonly_spec.rb +50 -0
- data/spec/inputs/search_input_spec.rb +5 -5
- data/spec/inputs/select_input_spec.rb +149 -93
- data/spec/inputs/string_input_spec.rb +23 -23
- data/spec/inputs/text_input_spec.rb +16 -16
- data/spec/inputs/time_picker_input_spec.rb +43 -43
- data/spec/inputs/time_select_input_spec.rb +67 -54
- data/spec/inputs/time_zone_input_spec.rb +54 -28
- data/spec/inputs/url_input_spec.rb +5 -5
- data/spec/inputs/with_options_spec.rb +7 -7
- data/spec/localizer_spec.rb +17 -17
- data/spec/namespaced_class_finder_spec.rb +2 -2
- data/spec/schema.rb +21 -0
- data/spec/spec_helper.rb +165 -253
- data/spec/support/custom_macros.rb +72 -75
- data/spec/support/shared_examples.rb +0 -1232
- data/spec/support/test_environment.rb +23 -9
- metadata +69 -176
- data/.travis.yml +0 -29
- data/Appraisals +0 -29
- data/CHANGELOG +0 -31
- 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,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/
|
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.4.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>, [">= 5.2.0"])
|
29
29
|
|
30
|
-
s.add_development_dependency(%q<
|
31
|
-
s.add_development_dependency(%q<rspec-
|
32
|
-
s.add_development_dependency(%q<
|
33
|
-
s.add_development_dependency(%q<
|
34
|
-
s.add_development_dependency(%q<RedCloth>, ["~> 4.2"]) # for YARD Textile formatting
|
35
|
-
s.add_development_dependency(%q<yard>, ["~> 0.8"])
|
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>, ["~> 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"])
|
40
34
|
s.add_development_dependency(%q<rake>)
|
41
|
-
s.add_development_dependency(%q<
|
35
|
+
s.add_development_dependency(%q<sqlite3>, ["~> 1.4"])
|
42
36
|
end
|
@@ -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: "../.."
|
data/lib/formtastic.rb
CHANGED
@@ -4,26 +4,20 @@ require 'formtastic/engine' if defined?(::Rails)
|
|
4
4
|
module Formtastic
|
5
5
|
extend ActiveSupport::Autoload
|
6
6
|
|
7
|
-
autoload :FormBuilder
|
8
7
|
autoload :Helpers
|
9
8
|
autoload :HtmlAttributes
|
10
|
-
autoload :I18n
|
11
|
-
autoload :Inputs
|
12
|
-
autoload :Actions
|
13
9
|
autoload :LocalizedString
|
14
10
|
autoload :Localizer
|
15
|
-
autoload :Util
|
16
11
|
autoload :NamespacedClassFinder
|
17
12
|
autoload :InputClassFinder
|
18
13
|
autoload :ActionClassFinder
|
19
14
|
autoload :Deprecation
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
deprecation.warn("Support for Rails < #{Util.minimum_version_of_rails} will be dropped")
|
16
|
+
eager_autoload do
|
17
|
+
autoload :I18n
|
18
|
+
autoload :FormBuilder
|
19
|
+
autoload :Inputs
|
20
|
+
autoload :Actions
|
27
21
|
end
|
28
22
|
|
29
23
|
# @public
|
@@ -42,4 +36,8 @@ module Formtastic
|
|
42
36
|
class UnsupportedMethodForAction < ArgumentError
|
43
37
|
end
|
44
38
|
|
39
|
+
# @private
|
40
|
+
class UnsupportedEnumCollection < NameError
|
41
|
+
end
|
42
|
+
|
45
43
|
end
|
data/lib/formtastic/actions.rb
CHANGED
@@ -1,42 +1,5 @@
|
|
1
1
|
require 'active_support/deprecation'
|
2
2
|
|
3
3
|
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
|
4
|
+
Deprecation = ActiveSupport::Deprecation
|
42
5
|
end
|
data/lib/formtastic/engine.rb
CHANGED
@@ -21,7 +21,7 @@ module Formtastic
|
|
21
21
|
configure :default_text_area_width
|
22
22
|
configure :all_fields_required_by_default, true
|
23
23
|
configure :include_blank_for_select_by_default, true
|
24
|
-
configure :required_string, proc {
|
24
|
+
configure :required_string, proc { %{<abbr title="#{Formtastic::I18n.t(:required)}">*</abbr>}.html_safe }
|
25
25
|
configure :optional_string, ''
|
26
26
|
configure :inline_errors, :sentence
|
27
27
|
configure :label_str_method, :humanize
|
@@ -42,14 +42,13 @@ module Formtastic
|
|
42
42
|
configure :perform_browser_validations, false
|
43
43
|
# Check {Formtastic::InputClassFinder} to see how are inputs resolved.
|
44
44
|
configure :input_namespaces, [::Object, ::Formtastic::Inputs]
|
45
|
-
|
46
|
-
# Will be {Formtastic::InputClassFinder} by default in 4.0.
|
47
|
-
configure :input_class_finder #, Formtastic::InputClassFinder
|
45
|
+
configure :input_class_finder, Formtastic::InputClassFinder
|
48
46
|
# Check {Formtastic::ActionClassFinder} to see how are inputs resolved.
|
49
47
|
configure :action_namespaces, [::Object, ::Formtastic::Actions]
|
50
|
-
|
51
|
-
|
52
|
-
configure :
|
48
|
+
configure :action_class_finder, Formtastic::ActionClassFinder
|
49
|
+
|
50
|
+
configure :skipped_columns, [:created_at, :updated_at, :created_on, :updated_on, :lock_version, :version]
|
51
|
+
configure :priority_time_zones, []
|
53
52
|
|
54
53
|
attr_reader :template
|
55
54
|
|
@@ -65,8 +64,8 @@ module Formtastic
|
|
65
64
|
|
66
65
|
# This is a wrapper around Rails' `ActionView::Helpers::FormBuilder#fields_for`, originally
|
67
66
|
# 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.
|
67
|
+
# the nested `fields_for`. Our supported versions of Rails no longer require us to do this,
|
68
|
+
# so this method is provided purely for backwards compatibility and DSL consistency.
|
70
69
|
#
|
71
70
|
# When constructing a `fields_for` form fragment *outside* of `semantic_form_for`, please use
|
72
71
|
# `Formtastic::Helpers::FormHelper#semantic_fields_for`.
|
@@ -92,23 +91,11 @@ module Formtastic
|
|
92
91
|
#
|
93
92
|
# @todo is there a way to test the params structure of the Rails helper we wrap to ensure forward compatibility?
|
94
93
|
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)
|
94
|
+
fields_for(record_or_name_or_array, *args, &block)
|
101
95
|
end
|
102
96
|
|
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
|
97
|
+
def initialize(object_name, object, template, options)
|
98
|
+
super
|
112
99
|
|
113
100
|
if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
|
114
101
|
self.multipart = options[:html][:multipart]
|
data/lib/formtastic/helpers.rb
CHANGED
@@ -9,8 +9,8 @@ module Formtastic
|
|
9
9
|
autoload :FormHelper, 'formtastic/helpers/form_helper'
|
10
10
|
autoload :InputHelper, 'formtastic/helpers/input_helper'
|
11
11
|
autoload :InputsHelper, 'formtastic/helpers/inputs_helper'
|
12
|
-
autoload :LabelHelper, 'formtastic/helpers/label_helper'
|
13
12
|
autoload :Reflection, 'formtastic/helpers/reflection'
|
13
|
+
autoload :Enum, 'formtastic/helpers/enum'
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -2,9 +2,6 @@
|
|
2
2
|
module Formtastic
|
3
3
|
module Helpers
|
4
4
|
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
5
|
# Renders an action for the form (such as a subit/reset button, or a cancel link).
|
9
6
|
#
|
10
7
|
# Each action is wrapped in an `<li class="action">` tag with other classes added based on the
|
@@ -82,7 +79,7 @@ module Formtastic
|
|
82
79
|
options = options.dup # Allow options to be shared without being tainted by Formtastic
|
83
80
|
options[:as] ||= default_action_type(method, options)
|
84
81
|
|
85
|
-
klass =
|
82
|
+
klass = namespaced_action_class(options[:as])
|
86
83
|
|
87
84
|
klass.new(self, template, @object, @object_name, method, options).to_html
|
88
85
|
end
|
@@ -113,50 +110,6 @@ module Formtastic
|
|
113
110
|
rescue Formtastic::ActionClassFinder::NotFoundError => e
|
114
111
|
raise Formtastic::UnknownActionError, "Unable to find action #{e.message}"
|
115
112
|
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
113
|
end
|
161
114
|
end
|
162
115
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Formtastic
|
2
|
+
module Helpers
|
3
|
+
# @private
|
4
|
+
module Enum
|
5
|
+
# Returns the enum (if defined) for the given method
|
6
|
+
def enum_for(method) # @private
|
7
|
+
if @object.respond_to?(:defined_enums)
|
8
|
+
@object.defined_enums[method.to_s]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -52,7 +52,7 @@ module Formtastic
|
|
52
52
|
return nil if full_errors.blank?
|
53
53
|
html_options[:class] ||= "errors"
|
54
54
|
template.content_tag(:ul, html_options) do
|
55
|
-
|
55
|
+
full_errors.map { |error| template.content_tag(:li, error) }.join.html_safe
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -78,4 +78,4 @@ module Formtastic
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
81
|
-
end
|
81
|
+
end
|
@@ -22,7 +22,7 @@ module Formtastic
|
|
22
22
|
# f.inputs :my_little_legend, :title, :body, :author # Localized (118n) legend with I18n key => I18n.t(:my_little_legend, ...)
|
23
23
|
# f.inputs :title, :body, :author # First argument is a column => (no legend)
|
24
24
|
def field_set_and_list_wrapping(*args, &block) # @private
|
25
|
-
contents = args.
|
25
|
+
contents = args[-1].is_a?(::Hash) ? '' : args.pop.flatten
|
26
26
|
html_options = args.extract_options!
|
27
27
|
|
28
28
|
if block_given?
|
@@ -33,12 +33,15 @@ module Formtastic
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# Work-around for empty contents block
|
37
|
+
contents ||= ""
|
38
|
+
|
36
39
|
# Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
|
37
40
|
contents = contents.join if contents.respond_to?(:join)
|
38
41
|
|
39
42
|
legend = field_set_legend(html_options)
|
40
43
|
fieldset = template.content_tag(:fieldset,
|
41
|
-
|
44
|
+
legend.html_safe << template.content_tag(:ol, contents.html_safe),
|
42
45
|
html_options.except(:builder, :parent, :name)
|
43
46
|
)
|
44
47
|
|
@@ -47,8 +50,9 @@ module Formtastic
|
|
47
50
|
|
48
51
|
def field_set_legend(html_options)
|
49
52
|
legend = (html_options[:name] || '').to_s
|
50
|
-
|
51
|
-
legend
|
53
|
+
# only applying if String includes '%i' avoids argument error when $DEBUG is true
|
54
|
+
legend %= parent_child_index(html_options[:parent]) if html_options[:parent] && legend.include?('%i')
|
55
|
+
legend = template.content_tag(:legend, template.content_tag(:span, legend.html_safe)) unless legend.blank?
|
52
56
|
legend
|
53
57
|
end
|
54
58
|
|
@@ -57,20 +61,20 @@ module Formtastic
|
|
57
61
|
def parent_child_index(parent) # @private
|
58
62
|
# Could be {"post[authors_attributes]"=>0} or { :authors => 0 }
|
59
63
|
duck = parent[:builder].instance_variable_get('@nested_child_index')
|
60
|
-
|
64
|
+
|
61
65
|
# Could be symbol for the association, or a model (or an array of either, I think? TODO)
|
62
66
|
child = parent[:for]
|
63
67
|
# Pull a sybol or model out of Array (TODO: check if there's an Array)
|
64
68
|
child = child.first if child.respond_to?(:first)
|
65
69
|
# If it's an object, get a symbol from the class name
|
66
70
|
child = child.class.name.underscore.to_sym unless child.is_a?(Symbol)
|
67
|
-
|
71
|
+
|
68
72
|
key = "#{parent[:builder].object_name}[#{child}_attributes]"
|
69
73
|
|
70
|
-
# TODO: One of the tests produces a scenario where duck is "0" and the test looks for a "1"
|
74
|
+
# TODO: One of the tests produces a scenario where duck is "0" and the test looks for a "1"
|
71
75
|
# 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
|
-
|
76
|
+
return duck + 1 if duck.is_a?(Integer)
|
77
|
+
|
74
78
|
# First try to extract key from duck Hash, then try child
|
75
79
|
(duck[key] || duck[child]).to_i + 1
|
76
80
|
end
|