Remove deprecated stuff and raise an exception if any of the old methods are used. Point to the wiki page with update instructions.

This commit is contained in:
José Valim 2011-09-04 11:12:16 +02:00
parent c74243aca6
commit da5e1d82be
3 changed files with 14 additions and 126 deletions

View File

@ -110,10 +110,24 @@ module SimpleForm
mattr_accessor :cache_discovery
@@cache_discovery = !Rails.env.development?
## DEPRECATED METHODS
DEPRECATED = %w(hint_tag= hint_class= error_tag= error_class= wrapper_tag= wrapper_class= wrapper_error_class= components=)
@@deprecated = false
DEPRECATED.each do |method|
class_eval "def #{method}; @@deprecated = true; end"
end
# Default way to setup SimpleForm. Run rails generate simple_form:install
# to create a fresh initializer with all configuration values.
def self.setup
yield self
if @@deprecated
raise "[SIMPLE FORM] Your simple form initializer file is using an outdated configuration API. " <<
"Updating to the new API is easy and fast. Check for more info here: https://github.com/plataformatec/simple_form/wiki/Upgrading-to-Simple-Form-2.0"
end
end
# Builds a new wrapper using SimpleForm::Wrappers::Builder.
@ -135,88 +149,4 @@ module SimpleForm
b.use :hint, :tag => :span, :class => :hint
b.use :error, :tag => :span, :class => :error
end
## DEPRECATED METHODS SINCE 2.0
# DEPRECATED. Default tag used on hints.
mattr_accessor :hint_tag
@@hint_tag = :span
# DEPRECATED. CSS class to add to all hint tags.
mattr_accessor :hint_class
@@hint_class = :hint
# DEPRECATED. Default tag used on errors.
mattr_accessor :error_tag
@@error_tag = :span
# DEPRECATED. CSS class to add to all error tags.
mattr_accessor :error_class
@@error_class = :error
# DEPRECATED. You can wrap all inputs in a pre-defined tag. Default is a div.
mattr_accessor :wrapper_tag
@@wrapper_tag = :div
# DEPRECATED. You can define the class to use on all wrappers. Default is input.
mattr_accessor :wrapper_class
@@wrapper_class = :input
# DEPRECATED. You can define the class to add to the wrapper when the field has errors. Default is field_with_errors.
mattr_accessor :wrapper_error_class
@@wrapper_error_class = :field_with_errors
# DEPRECATED. Define components using an array.
def self.components=(array)
ActiveSupport::Deprecation.warn <<-TEXT
Setting config.components= in SimpleForm is deprecated. SimpleForm 2.0 ships with a new components syntax which is more flexible and powerful. If your components were defined as:
config.components = [ :placeholder, :maxlength, :label_input, :hint, :error ]
They can now be defined as:
config.components :tag => :div, :class => :input,
:error_class => :field_with_errors do |b|
b.use :placeholder
b.use :maxlength
b.use :label_input
b.use :hint, :tag => :span, :class => :hint
b.use :error, :tag => :span, :class => :error
end
The new components syntax also allows custom wrappers:
config.components do |b|
b.use :placeholder
b.use :maxlength
b.use :label_input
b.use :tag => :div, :class => "separator" do |ba|
ba.use :hint, :tag => :span, :class => :hint
ba.use :error, :tag => :span, :class => :error
end
end
The following methods are also deprecated: wrapper_tag, wrapper_class, wrapper_error_class, error_tag, error_class, hint_tag and hint_class.
TEXT
self.deprecated_components = array
end
def self.deprecated_components=(array) #:nodoc:
self.wrapper = Wrappers::Root.new(
array.map do |item|
case item
when :error
Wrappers::Single.new(:error, :tag => SimpleForm.error_tag, :class => SimpleForm.error_class)
when :hint
Wrappers::Single.new(:hint, :tag => SimpleForm.hint_tag, :class => SimpleForm.hint_class)
else
item
end
end,
:tag => SimpleForm.wrapper_tag,
:class => SimpleForm.wrapper_class,
:error_class => SimpleForm.wrapper_error_class
)
end
end

View File

@ -16,37 +16,6 @@ class WrapperTest < ActionView::TestCase
assert_select 'div.field_with_errors'
end
test 'wrapper should support wrapping around an specific tag' do
swap! SimpleForm, :wrapper_tag => :p do
with_form_for @user, :name
assert_select 'form p label[for=user_name]'
assert_select 'form p input#user_name.string'
end
end
test 'wrapper should add chosen error class for attribute with errors' do
swap! SimpleForm, :wrapper_error_class => "omgError" do
with_form_for @user, :name
assert_select 'div.omgError'
end
end
test 'wrapper should add chosen wrapper class' do
swap! SimpleForm, :wrapper_class => "wrapper" do
with_form_for @user, :active
assert_select 'div.wrapper'
assert_no_select 'div.input'
with_form_for @user, :name
assert_select 'div.wrapper'
assert_no_select 'div.input'
with_form_for :project, :name
assert_select 'div.wrapper'
assert_no_select 'div.input'
end
end
test 'wrapper should not have disabled class by default' do
with_form_for @user, :active
assert_no_select 'div.disabled'

View File

@ -38,17 +38,6 @@ module MiscHelpers
end
end
# Temporary hack to deal with components.
# TODO: Remove this and tests that uses this once we remove components
def swap!(*args)
swap(*args) do
SimpleForm.deprecated_components = [ :placeholder, :label_input, :hint, :error ]
yield
end
ensure
SimpleForm.deprecated_components = [ :placeholder, :label_input, :hint, :error ]
end
def custom_form_for(object, *args, &block)
simple_form_for(object, *(args << { :builder => CustomFormBuilder }), &block)
end