From 725ca0f4a1575e09d630f478ab4562599bb8264f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 10 Dec 2009 23:48:29 -0200 Subject: [PATCH] Terminator is not public. --- README.rdoc | 12 ++++++------ lib/simple_form.rb | 6 +----- lib/simple_form/form_builder.rb | 10 ++++++---- test/components/error_test.rb | 2 +- test/components/hint_test.rb | 2 +- test/components/input_test.rb | 2 +- test/components/label_test.rb | 2 +- 7 files changed, 17 insertions(+), 19 deletions(-) diff --git a/README.rdoc b/README.rdoc index ccd8d266..e9e82ebe 100644 --- a/README.rdoc +++ b/README.rdoc @@ -170,14 +170,14 @@ Instead of using the text and mark options from required, you can also overwrite You have a set of options available to configure SimpleForm: * component_tag => default tag used in components. by default is :span. + * components => stack of components used in form builder to create the input. You can add or remove any of this components as you need. -* terminator => the last component will call this terminator. By default it's - a lambda returning an empty string. -* collection_label_methods => all methods available to detect the label for a - collection. -* collection_value_methods => all methods available to detect the value for a - collection. + +* collection_label_methods => all methods available to detect the label for a collection. + +* collection_value_methods => all methods available to detect the value for a collection. + * wrapper_tag => wrapper tag to wrap the inputs. By default no wrapper exists. To do it so you just need to create a file inside your initializer folder and use the configurations as follows: diff --git a/lib/simple_form.rb b/lib/simple_form.rb index aa93db70..07f8cbdf 100644 --- a/lib/simple_form.rb +++ b/lib/simple_form.rb @@ -20,13 +20,9 @@ module SimpleForm SimpleForm::Components::Error ] - # The terminator sent to the last component - mattr_accessor :terminator - @@terminator = lambda { "" } - # Series of attemps to detect a default label method for collection mattr_accessor :collection_label_methods - @@collection_label_methods = [ :name, :title, :to_s ] + @@collection_label_methods = [ :to_label, :name, :title, :to_s ] # Series of attemps to detect a default value method for collection mattr_accessor :collection_value_methods diff --git a/lib/simple_form/form_builder.rb b/lib/simple_form/form_builder.rb index 3de33f88..9b73d331 100644 --- a/lib/simple_form/form_builder.rb +++ b/lib/simple_form/form_builder.rb @@ -2,6 +2,8 @@ module SimpleForm class FormBuilder < ActionView::Helpers::FormBuilder attr_reader :template, :object_name, :object, :attribute, :column, :input_type, :options + TERMINATOR = lambda { "" } + # Basic input helper, combines all components in the stack to generate input # html based on options the user define and some guesses through # database column information. By default a call to input will generate @@ -64,7 +66,7 @@ module SimpleForm def input(attribute, options={}) define_simple_form_attributes(attribute, options) - component = SimpleForm.terminator + component = TERMINATOR SimpleForm.components.reverse.each do |klass| next if @options[klass.basename] == false component = klass.new(self, component) @@ -131,7 +133,7 @@ module SimpleForm # def error(attribute, options={}) define_simple_form_attributes(attribute, :error_html => options) - SimpleForm::Components::Error.new(self, SimpleForm.terminator).call + SimpleForm::Components::Error.new(self, TERMINATOR).call end # Creates a hint tag for the given attribute. Accepts a symbol indicating @@ -147,7 +149,7 @@ module SimpleForm def hint(attribute, options={}) attribute, options[:hint] = nil, attribute if attribute.is_a?(String) define_simple_form_attributes(attribute, :hint => options.delete(:hint), :hint_html => options) - SimpleForm::Components::Hint.new(self, SimpleForm.terminator).call + SimpleForm::Components::Hint.new(self, TERMINATOR).call end # Creates a default label tag for the given attribute. You can give a label @@ -168,7 +170,7 @@ module SimpleForm options = args.extract_options! define_simple_form_attributes(attribute, :label => options.delete(:label), :label_html => options, :required => options.delete(:required)) - SimpleForm::Components::Label.new(self, SimpleForm.terminator).call + SimpleForm::Components::Label.new(self, TERMINATOR).call end private diff --git a/test/components/error_test.rb b/test/components/error_test.rb index 982517c2..6282aece 100644 --- a/test/components/error_test.rb +++ b/test/components/error_test.rb @@ -8,7 +8,7 @@ class ErrorTest < ActionView::TestCase f.input_type = type f.options = options - error = SimpleForm::Components::Error.new(f, SimpleForm.terminator) + error = SimpleForm::Components::Error.new(f, SimpleForm::FormBuilder::TERMINATOR) concat(error.call) yield error if block_given? end diff --git a/test/components/hint_test.rb b/test/components/hint_test.rb index 9b72a39b..9cc862a6 100644 --- a/test/components/hint_test.rb +++ b/test/components/hint_test.rb @@ -8,7 +8,7 @@ class ErrorTest < ActionView::TestCase f.input_type = type f.options = options - hint = SimpleForm::Components::Hint.new(f, SimpleForm.terminator) + hint = SimpleForm::Components::Hint.new(f, SimpleForm::FormBuilder::TERMINATOR) concat(hint.call) yield hint if block_given? end diff --git a/test/components/input_test.rb b/test/components/input_test.rb index 357ae468..e23ea2c9 100644 --- a/test/components/input_test.rb +++ b/test/components/input_test.rb @@ -13,7 +13,7 @@ class InputTest < ActionView::TestCase f.input_type = type f.options = options - input = SimpleForm::Components::Input.new(f, SimpleForm.terminator) + input = SimpleForm::Components::Input.new(f, SimpleForm::FormBuilder::TERMINATOR) concat(input.call) yield input if block_given? end diff --git a/test/components/label_test.rb b/test/components/label_test.rb index d2868638..14d5f45b 100644 --- a/test/components/label_test.rb +++ b/test/components/label_test.rb @@ -12,7 +12,7 @@ class LabelTest < ActionView::TestCase f.input_type = type f.options = options - label = SimpleForm::Components::Label.new(f, SimpleForm.terminator) + label = SimpleForm::Components::Label.new(f, SimpleForm::FormBuilder::TERMINATOR) concat(label.call) yield label if block_given? end