Skip to content

Commit

Permalink
removed deprecated options :value, :hint_class, :error_class, :group_…
Browse files Browse the repository at this point in the history
…by, :group_label, :find_options
  • Loading branch information
justinfrench committed Jun 6, 2012
1 parent f68d4c8 commit 9a78fa3
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 257 deletions.
12 changes: 6 additions & 6 deletions lib/formtastic/inputs/base.rb
Expand Up @@ -12,12 +12,12 @@ def initialize(builder, template, object, object_name, method, options)
@method = method @method = method
@options = options.dup @options = options.dup


warn_deprecated_option!(:value, ":input_html => { :value => '...'}") removed_option!(:value)
warn_deprecated_option!(:hint_class, "default_hint_class configuration") removed_option!(:hint_class)
warn_deprecated_option!(:error_class, "default_error_class configuration") removed_option!(:error_class)
warn_deprecated_option!(:group_by, ":collection option with a HTML string generated by Rails' grouped_options_for_select()") removed_option!(:group_by)
warn_deprecated_option!(:group_label, ":collection option with a HTML string generated by Rails' grouped_options_for_select()") removed_option!(:group_label)
warn_deprecated_option!(:find_options, "YourModel.find(...)") removed_option!(:find_options)
end end


# Usefull for deprecating options. # Usefull for deprecating options.
Expand Down
9 changes: 1 addition & 8 deletions lib/formtastic/inputs/base/collections.rb
Expand Up @@ -78,18 +78,11 @@ def collection_from_association
) if reflection.options[:polymorphic] == true ) if reflection.options[:polymorphic] == true
end end


find_options_from_options = options[:find_options] || {}
conditions_from_options = find_options_from_options[:conditions] || {}
conditions_from_reflection = (reflection.respond_to?(:options) && reflection.options[:conditions]) || {} conditions_from_reflection = (reflection.respond_to?(:options) && reflection.options[:conditions]) || {}
conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc) conditions_from_reflection = conditions_from_reflection.call if conditions_from_reflection.is_a?(Proc)


scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection} scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
if conditions_from_options.any? reflection.klass.scoped(scope_conditions).where({})
reflection.klass.scoped(scope_conditions).where(conditions_from_options)
else
find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
reflection.klass.scoped(scope_conditions).where(find_options_from_options)
end
end end
end end


Expand Down
9 changes: 3 additions & 6 deletions lib/formtastic/inputs/base/errors.rb
Expand Up @@ -8,22 +8,19 @@ def error_html
end end


def error_sentence_html def error_sentence_html
error_class = options[:error_class] || builder.default_inline_error_class template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => builder.default_inline_error_class)
template.content_tag(:p, Formtastic::Util.html_safe(errors.to_sentence.html_safe), :class => error_class)
end end


def error_list_html def error_list_html
error_class = options[:error_class] || builder.default_error_list_class
list_elements = [] list_elements = []
errors.each do |error| errors.each do |error|
list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe)) list_elements << template.content_tag(:li, Formtastic::Util.html_safe(error.html_safe))
end end
template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => error_class) template.content_tag(:ul, Formtastic::Util.html_safe(list_elements.join("\n")), :class => builder.default_error_list_class)
end end


def error_first_html def error_first_html
error_class = options[:error_class] || builder.default_inline_error_class template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => builder.default_inline_error_class)
template.content_tag(:p, Formtastic::Util.html_safe(errors.first.untaint), :class => error_class)
end end


def error_none_html def error_none_html
Expand Down
77 changes: 0 additions & 77 deletions lib/formtastic/inputs/base/grouped_collections.rb

This file was deleted.

2 changes: 1 addition & 1 deletion lib/formtastic/inputs/base/hints.rb
Expand Up @@ -8,7 +8,7 @@ def hint_html
template.content_tag( template.content_tag(
:p, :p,
Formtastic::Util.html_safe(hint_text), Formtastic::Util.html_safe(hint_text),
:class => (options[:hint_class] || builder.default_hint_class) :class => builder.default_hint_class
) )
end end
end end
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/base/options.rb
Expand Up @@ -8,7 +8,7 @@ def input_options
end end


def formtastic_options def formtastic_options
[:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class] [:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :class]
end end


end end
Expand Down
6 changes: 1 addition & 5 deletions lib/formtastic/inputs/hidden_input.rb
Expand Up @@ -31,12 +31,8 @@ module Inputs
class HiddenInput class HiddenInput
include Base include Base


# Override to include :value set directly from options hash. The :value set in :input_html
# hash will be preferred over :value set directly in the options.
#
# @deprecated :value option
def input_html_options def input_html_options
options.slice(:value).merge(super).merge(:required => nil).merge(:autofocus => nil) super.merge(:required => nil).merge(:autofocus => nil)
end end


def to_html def to_html
Expand Down
16 changes: 1 addition & 15 deletions lib/formtastic/inputs/select_input.rb
Expand Up @@ -140,33 +140,19 @@ module Inputs
class SelectInput class SelectInput
include Base include Base
include Base::Collections include Base::Collections
include Base::GroupedCollections


def to_html def to_html
input_wrapping do input_wrapping do
hidden_input << hidden_input <<
label_html << label_html <<
(options[:group_by] ? grouped_select_html : select_html) select_html
end end
end end


def select_html def select_html
builder.select(input_name, collection, input_options, input_html_options) builder.select(input_name, collection, input_options, input_html_options)
end end


def grouped_select_html
builder.grouped_collection_select(
input_name,
grouped_collection,
group_association,
group_label_method,
value_method,
label_method,
input_options,
input_html_options
)
end

def include_blank def include_blank
options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default) options.key?(:include_blank) ? options[:include_blank] : (single? && builder.include_blank_for_select_by_default)
end end
Expand Down
31 changes: 1 addition & 30 deletions spec/helpers/input_helper_spec.rb
Expand Up @@ -665,17 +665,7 @@ def length_should_be_required(options)
output_buffer.should have_tag("form li p.inline-hints", hint_text) output_buffer.should have_tag("form li p.inline-hints", hint_text)
end end


it 'should have a custom hint class if I ask for one' do it 'should use the configured hint class' do
with_deprecation_silenced do
hint_text = "this is the title of the post"
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => hint_text, :hint_class => 'custom-hint-class'))
end)
output_buffer.should have_tag("form li p.custom-hint-class", hint_text)
end
end

it 'should have a custom hint class defaulted for all forms' do
hint_text = "this is the title of the post" hint_text = "this is the title of the post"
Formtastic::FormBuilder.default_hint_class = "custom-hint-class" Formtastic::FormBuilder.default_hint_class = "custom-hint-class"
concat(semantic_form_for(@new_post) do |builder| concat(semantic_form_for(@new_post) do |builder|
Expand Down Expand Up @@ -720,25 +710,6 @@ def length_should_be_required(options)
end end
end end


it 'should render a hint paragraph containing a localized hint (I18n) with a custom hint class if i ask for one' do
with_config :i18n_lookups_by_default, false do
::I18n.backend.store_translations :en,
:formtastic => {
:hints => {
:post => {
:title => @localized_hint_text
}
}
}
with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:title, :hint => true, :hint_class => 'custom-hint-class'))
end)
end
output_buffer.should have_tag('form li p.custom-hint-class', @localized_hint_text)
end
end

it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do it 'should render a hint paragraph containing an optional localized hint (I18n) if first is not set' do
with_config :i18n_lookups_by_default, false do with_config :i18n_lookups_by_default, false do
concat(semantic_form_for(@new_post) do |builder| concat(semantic_form_for(@new_post) do |builder|
Expand Down
12 changes: 3 additions & 9 deletions spec/inputs/hidden_input_spec.rb
Expand Up @@ -12,10 +12,9 @@
with_deprecation_silenced do with_deprecation_silenced do
concat(semantic_form_for(@new_post) do |builder| concat(semantic_form_for(@new_post) do |builder|
concat(builder.input(:secret, :as => :hidden)) concat(builder.input(:secret, :as => :hidden))
concat(builder.input(:author_id, :as => :hidden, :value => 99))
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true})) concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'})) concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"})) concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
end) end)
end end
end end
Expand All @@ -35,10 +34,6 @@
output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]") output_buffer.should have_tag("form li input#post_secret[@type=\"hidden\"][@value=\"1\"]")
end end


it "should pass any explicitly specified value - using :value" do
output_buffer.should have_tag("form li input#post_author_id[@type=\"hidden\"][@value=\"99\"]")
end

# Handle Formtastic :input_html options for consistency. # Handle Formtastic :input_html options for consistency.
it "should pass any explicitly specified value - using :input_html options" do it "should pass any explicitly specified value - using :input_html options" do
output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]") output_buffer.should have_tag("form li input#post_published[@type=\"hidden\"][@value=\"true\"]")
Expand Down Expand Up @@ -83,15 +78,14 @@
with_deprecation_silenced do with_deprecation_silenced do
concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder| concat(semantic_form_for(@new_post, :namespace => 'context2') do |builder|
concat(builder.input(:secret, :as => :hidden)) concat(builder.input(:secret, :as => :hidden))
concat(builder.input(:author_id, :as => :hidden, :value => 99))
concat(builder.input(:published, :as => :hidden, :input_html => {:value => true})) concat(builder.input(:published, :as => :hidden, :input_html => {:value => true}))
concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'})) concat(builder.input(:reviewer, :as => :hidden, :input_html => {:class => 'new_post_reviewer', :id => 'new_post_reviewer'}))
concat(builder.input(:author, :as => :hidden, :value => 'direct_value', :input_html => {:value => "formtastic_value"})) concat(builder.input(:author, :as => :hidden, :input_html => {:value => "formtastic_value"}))
end) end)
end end
end end


attributes_to_check = [:secret, :author_id, :published, :reviewer] attributes_to_check = [:secret, :published, :reviewer]
attributes_to_check.each do |a| attributes_to_check.each do |a|
it_should_have_input_wrapper_with_id("context2_post_#{a}_input") it_should_have_input_wrapper_with_id("context2_post_#{a}_input")
end end
Expand Down

0 comments on commit 9a78fa3

Please sign in to comment.