formtastic 3.1.2 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +1 -0
  3. data/.github/workflows/test.yml +61 -0
  4. data/.gitignore +3 -2
  5. data/CHANGELOG.md +52 -0
  6. data/Gemfile.lock +105 -0
  7. data/MIT-LICENSE +1 -1
  8. data/{README.textile → README.md} +178 -167
  9. data/RELEASE_PROCESS +3 -1
  10. data/Rakefile +20 -1
  11. data/app/assets/stylesheets/formtastic.css +1 -1
  12. data/bin/appraisal +8 -0
  13. data/formtastic.gemspec +10 -16
  14. data/gemfiles/rails_5.2/Gemfile +5 -0
  15. data/gemfiles/rails_6.0/Gemfile +5 -0
  16. data/gemfiles/rails_6.1/Gemfile +5 -0
  17. data/gemfiles/rails_edge/Gemfile +13 -0
  18. data/lib/formtastic.rb +9 -11
  19. data/lib/formtastic/actions.rb +6 -3
  20. data/lib/formtastic/deprecation.rb +1 -38
  21. data/lib/formtastic/engine.rb +3 -1
  22. data/lib/formtastic/form_builder.rb +11 -24
  23. data/lib/formtastic/helpers.rb +1 -1
  24. data/lib/formtastic/helpers/action_helper.rb +1 -48
  25. data/lib/formtastic/helpers/enum.rb +13 -0
  26. data/lib/formtastic/helpers/errors_helper.rb +2 -2
  27. data/lib/formtastic/helpers/fieldset_wrapper.rb +13 -9
  28. data/lib/formtastic/helpers/form_helper.rb +1 -1
  29. data/lib/formtastic/helpers/input_helper.rb +23 -77
  30. data/lib/formtastic/helpers/inputs_helper.rb +27 -22
  31. data/lib/formtastic/i18n.rb +1 -1
  32. data/lib/formtastic/inputs.rb +32 -29
  33. data/lib/formtastic/inputs/base/choices.rb +1 -1
  34. data/lib/formtastic/inputs/base/collections.rb +43 -10
  35. data/lib/formtastic/inputs/base/database.rb +7 -2
  36. data/lib/formtastic/inputs/base/errors.rb +4 -4
  37. data/lib/formtastic/inputs/base/hints.rb +1 -1
  38. data/lib/formtastic/inputs/base/html.rb +7 -6
  39. data/lib/formtastic/inputs/base/naming.rb +4 -4
  40. data/lib/formtastic/inputs/base/options.rb +2 -3
  41. data/lib/formtastic/inputs/base/timeish.rb +5 -1
  42. data/lib/formtastic/inputs/base/validations.rb +38 -12
  43. data/lib/formtastic/inputs/check_boxes_input.rb +13 -5
  44. data/lib/formtastic/inputs/color_input.rb +0 -1
  45. data/lib/formtastic/inputs/country_input.rb +3 -1
  46. data/lib/formtastic/inputs/radio_input.rb +20 -0
  47. data/lib/formtastic/inputs/select_input.rb +29 -1
  48. data/lib/formtastic/inputs/time_zone_input.rb +16 -6
  49. data/lib/formtastic/localizer.rb +20 -22
  50. data/lib/formtastic/namespaced_class_finder.rb +1 -1
  51. data/lib/formtastic/version.rb +1 -1
  52. data/lib/generators/formtastic/form/form_generator.rb +1 -1
  53. data/lib/generators/formtastic/input/input_generator.rb +46 -0
  54. data/lib/generators/templates/formtastic.rb +14 -13
  55. data/lib/generators/templates/input.rb +19 -0
  56. data/sample/basic_inputs.html +1 -1
  57. data/script/integration-template.rb +74 -0
  58. data/script/integration.sh +19 -0
  59. data/spec/action_class_finder_spec.rb +1 -1
  60. data/spec/actions/button_action_spec.rb +8 -8
  61. data/spec/actions/generic_action_spec.rb +60 -60
  62. data/spec/actions/input_action_spec.rb +7 -7
  63. data/spec/actions/link_action_spec.rb +10 -10
  64. data/spec/builder/custom_builder_spec.rb +37 -21
  65. data/spec/builder/error_proc_spec.rb +4 -4
  66. data/spec/builder/semantic_fields_for_spec.rb +27 -27
  67. data/spec/fast_spec_helper.rb +12 -0
  68. data/spec/generators/formtastic/form/form_generator_spec.rb +25 -25
  69. data/spec/generators/formtastic/input/input_generator_spec.rb +124 -0
  70. data/spec/generators/formtastic/install/install_generator_spec.rb +9 -9
  71. data/spec/helpers/action_helper_spec.rb +328 -10
  72. data/spec/helpers/actions_helper_spec.rb +17 -17
  73. data/spec/helpers/form_helper_spec.rb +37 -37
  74. data/spec/helpers/input_helper_spec.rb +975 -2
  75. data/spec/helpers/inputs_helper_spec.rb +120 -105
  76. data/spec/helpers/reflection_helper_spec.rb +3 -3
  77. data/spec/helpers/semantic_errors_helper_spec.rb +22 -22
  78. data/spec/i18n_spec.rb +26 -26
  79. data/spec/input_class_finder_spec.rb +1 -1
  80. data/spec/inputs/base/collections_spec.rb +76 -0
  81. data/spec/inputs/base/validations_spec.rb +480 -0
  82. data/spec/inputs/boolean_input_spec.rb +55 -55
  83. data/spec/inputs/check_boxes_input_spec.rb +155 -108
  84. data/spec/inputs/color_input_spec.rb +51 -63
  85. data/spec/inputs/country_input_spec.rb +20 -20
  86. data/spec/inputs/custom_input_spec.rb +2 -6
  87. data/spec/inputs/datalist_input_spec.rb +1 -1
  88. data/spec/inputs/date_picker_input_spec.rb +42 -42
  89. data/spec/inputs/date_select_input_spec.rb +51 -37
  90. data/spec/inputs/datetime_picker_input_spec.rb +46 -46
  91. data/spec/inputs/datetime_select_input_spec.rb +53 -37
  92. data/spec/inputs/email_input_spec.rb +5 -5
  93. data/spec/inputs/file_input_spec.rb +6 -6
  94. data/spec/inputs/hidden_input_spec.rb +18 -18
  95. data/spec/inputs/include_blank_spec.rb +8 -8
  96. data/spec/inputs/label_spec.rb +20 -20
  97. data/spec/inputs/number_input_spec.rb +112 -112
  98. data/spec/inputs/password_input_spec.rb +5 -5
  99. data/spec/inputs/phone_input_spec.rb +5 -5
  100. data/spec/inputs/placeholder_spec.rb +5 -5
  101. data/spec/inputs/radio_input_spec.rb +84 -58
  102. data/spec/inputs/range_input_spec.rb +66 -66
  103. data/spec/inputs/readonly_spec.rb +50 -0
  104. data/spec/inputs/search_input_spec.rb +5 -5
  105. data/spec/inputs/select_input_spec.rb +149 -93
  106. data/spec/inputs/string_input_spec.rb +23 -23
  107. data/spec/inputs/text_input_spec.rb +16 -16
  108. data/spec/inputs/time_picker_input_spec.rb +43 -43
  109. data/spec/inputs/time_select_input_spec.rb +67 -54
  110. data/spec/inputs/time_zone_input_spec.rb +54 -28
  111. data/spec/inputs/url_input_spec.rb +5 -5
  112. data/spec/inputs/with_options_spec.rb +7 -7
  113. data/spec/localizer_spec.rb +17 -17
  114. data/spec/namespaced_class_finder_spec.rb +2 -2
  115. data/spec/schema.rb +21 -0
  116. data/spec/spec_helper.rb +165 -253
  117. data/spec/support/custom_macros.rb +72 -75
  118. data/spec/support/shared_examples.rb +0 -1232
  119. data/spec/support/test_environment.rb +23 -9
  120. metadata +69 -176
  121. data/.travis.yml +0 -29
  122. data/Appraisals +0 -29
  123. data/CHANGELOG +0 -31
  124. data/DEPRECATIONS +0 -49
  125. data/gemfiles/rails_3.2.gemfile +0 -7
  126. data/gemfiles/rails_4.0.4.gemfile +0 -7
  127. data/gemfiles/rails_4.1.gemfile +0 -7
  128. data/gemfiles/rails_4.2.gemfile +0 -7
  129. data/gemfiles/rails_4.gemfile +0 -7
  130. data/gemfiles/rails_edge.gemfile +0 -10
  131. data/lib/formtastic/util.rb +0 -57
  132. data/spec/helpers/namespaced_action_helper_spec.rb +0 -43
  133. data/spec/helpers/namespaced_input_helper_spec.rb +0 -36
  134. data/spec/support/deferred_garbage_collection.rb +0 -21
  135. data/spec/util_spec.rb +0 -66
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,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
- padding-left:25%;
226
+ margin-left:25%;
227
227
  display:block;
228
228
  }
229
229
 
data/bin/appraisal ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+
3
+ if [ "$1" = "" ]
4
+ then
5
+ bundle exec rake appraisal
6
+ else
7
+ bundle exec rake "appraisal:$1"
8
+ fi
data/formtastic.gemspec CHANGED
@@ -8,35 +8,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
14
  s.license = 'MIT'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.executables = []
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.rdoc_options = ["--charset=UTF-8"]
22
- s.extra_rdoc_files = ["README.textile"]
22
+ s.extra_rdoc_files = ["README.md"]
23
23
 
24
- s.required_ruby_version = '>= 1.9.3'
24
+ s.required_ruby_version = '>= 2.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>, [">= 3.2.13"])
28
+ s.add_dependency(%q<actionpack>, [">= 5.2.0"])
29
29
 
30
- s.add_development_dependency(%q<nokogiri>)
31
- s.add_development_dependency(%q<rspec-rails>, ["~> 2.14"])
32
- s.add_development_dependency(%q<rspec_tag_matchers>, ["~> 1.0"])
33
- s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
34
- s.add_development_dependency(%q<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<activemodel>, [">= 3.2.13"])
35
+ s.add_development_dependency(%q<sqlite3>, ["~> 1.4"])
42
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: "../.."
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
- # @private
22
- mattr_accessor :deprecation
23
- self.deprecation = Formtastic::Deprecation.new('4.0', 'Formtastic')
24
-
25
- if defined?(::Rails) && Util.deprecated_version_of_rails?
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
@@ -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
@@ -1,42 +1,5 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
3
  module Formtastic
4
- if ActiveSupport::Deprecation.respond_to?(:new)
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
@@ -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
@@ -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 { Formtastic::Util.html_safe(%{<abbr title="#{Formtastic::I18n.t(:required)}">*</abbr>}) }
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
- # @todo enable this as default in 4.0 and remove it from configuration generator template
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
- # @todo enable this as default in 4.0 and remove it from configuration generator template
51
- # Will be {Formtastic::ActionClassFinder} by default in 4.0.
52
- configure :action_class_finder#, Formtastic::ActionClassFinder
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 3 no longer requires us to do this, so this method is
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
- # Add a :parent_builder to the args so that nested translations can be possible in Rails 3
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, block=nil)
104
- # rails 3 supported passing in the block parameter to FormBuilder
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]
@@ -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 = action_class(options[:as])
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
- Formtastic::Util.html_safe(full_errors.map { |error| template.content_tag(:li, Formtastic::Util.html_safe(error)) }.join)
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.last.is_a?(::Hash) ? '' : args.pop.flatten
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
- Formtastic::Util.html_safe(legend) << template.content_tag(:ol, Formtastic::Util.html_safe(contents)),
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
- legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
51
- legend = template.content_tag(:legend, template.content_tag(:span, Formtastic::Util.html_safe(legend))) unless legend.blank?
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?(Fixnum)
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