From 8e8c6c35832e6a9d9ee09b645e9f34b3594128c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 16 Jan 2012 20:29:01 -0300 Subject: Extract TextArea --- actionpack/lib/action_view/helpers/form_helper.rb | 14 +------------- actionpack/lib/action_view/helpers/tags.rb | 1 + actionpack/lib/action_view/helpers/tags/text_area.rb | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 13 deletions(-) create mode 100644 actionpack/lib/action_view/helpers/tags/text_area.rb (limited to 'actionpack') diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 9c8966e528..837b1a8d9a 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -766,7 +766,7 @@ module ActionView # # #{@entry.body} # # def text_area(object_name, method, options = {}) - InstanceTag.new(object_name, method, self, options.delete(:object)).to_text_area_tag(options) + ActionView::Helpers::Tags::TextArea.new(object_name, method, self, options).render end # Returns a checkbox tag tailored for accessing a specified attribute (identified by +method+) on an object @@ -960,7 +960,6 @@ module ActionView DEFAULT_FIELD_OPTIONS = { "size" => 30 } DEFAULT_RADIO_OPTIONS = { } - DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 } def initialize(object_name, method_name, template_object, object = nil) @object_name, @method_name = object_name.to_s.dup, method_name.to_s.dup @@ -1010,17 +1009,6 @@ module ActionView tag("input", options) end - def to_text_area_tag(options = {}) - options = DEFAULT_TEXT_AREA_OPTIONS.merge(options.stringify_keys) - add_default_name_and_id(options) - - if size = options.delete("size") - options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split) - end - - content_tag("textarea", ERB::Util.html_escape(options.delete('value') || value_before_type_cast(object)), options) - end - def to_check_box_tag(options = {}, checked_value = "1", unchecked_value = "0") options = options.stringify_keys options["type"] = "checkbox" diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb index 5b43f43fea..76e1927b80 100644 --- a/actionpack/lib/action_view/helpers/tags.rb +++ b/actionpack/lib/action_view/helpers/tags.rb @@ -7,6 +7,7 @@ module ActionView autoload :PasswordField, 'action_view/helpers/tags/password_field' autoload :HiddenField, 'action_view/helpers/tags/hidden_field' autoload :FileField, 'action_view/helpers/tags/file_field' + autoload :TextArea, 'action_view/helpers/tags/text_area' end end end diff --git a/actionpack/lib/action_view/helpers/tags/text_area.rb b/actionpack/lib/action_view/helpers/tags/text_area.rb new file mode 100644 index 0000000000..a7db8eb437 --- /dev/null +++ b/actionpack/lib/action_view/helpers/tags/text_area.rb @@ -0,0 +1,20 @@ +module ActionView + module Helpers + module Tags + class TextArea < Base #:nodoc: + DEFAULT_TEXT_AREA_OPTIONS = { "cols" => 40, "rows" => 20 } + + def render + options = DEFAULT_TEXT_AREA_OPTIONS.merge(@options.stringify_keys) + add_default_name_and_id(options) + + if size = options.delete("size") + options["cols"], options["rows"] = size.split("x") if size.respond_to?(:split) + end + + content_tag("textarea", ERB::Util.html_escape(options.delete('value') || value_before_type_cast(object)), options) + end + end + end + end +end -- cgit v1.2.3