From b69e449c512d68b54af3d15cdf2d92181c2817d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20Mendon=C3=A7a=20Fran=C3=A7a?= Date: Mon, 16 Jan 2012 23:55:48 -0300 Subject: Extract TimeSelect --- actionpack/lib/action_view/helpers/active_model_helper.rb | 2 +- actionpack/lib/action_view/helpers/date_helper.rb | 6 +----- actionpack/lib/action_view/helpers/tags.rb | 1 + actionpack/lib/action_view/helpers/tags/date_select.rb | 6 +++++- actionpack/lib/action_view/helpers/tags/time_select.rb | 8 ++++++++ 5 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 actionpack/lib/action_view/helpers/tags/time_select.rb (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/active_model_helper.rb b/actionpack/lib/action_view/helpers/active_model_helper.rb index 06137f6be6..cb801e50c4 100644 --- a/actionpack/lib/action_view/helpers/active_model_helper.rb +++ b/actionpack/lib/action_view/helpers/active_model_helper.rb @@ -16,7 +16,7 @@ module ActionView end end - %w(content_tag to_datetime_select_tag to_time_select_tag).each do |meth| + %w(content_tag to_datetime_select_tag).each do |meth| module_eval "def #{meth}(*) error_wrapping(super) end", __FILE__, __LINE__ end diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index d1d802de53..fb80996dfa 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -251,7 +251,7 @@ module ActionView # Note: If the day is not included as an option but the month is, the day will be set to the 1st to ensure that # all month choices are valid. def time_select(object_name, method, options = {}, html_options = {}) - InstanceTag.new(object_name, method, self, options.delete(:object)).to_time_select_tag(options, html_options) + ActionView::Helpers::Tags::TimeSelect.new(object_name, method, self, options, html_options).render end # Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a @@ -975,10 +975,6 @@ module ActionView end module DateHelperInstanceTag - def to_time_select_tag(options = {}, html_options = {}) - datetime_selector(options, html_options).select_time.html_safe - end - def to_datetime_select_tag(options = {}, html_options = {}) datetime_selector(options, html_options).select_datetime.html_safe end diff --git a/actionpack/lib/action_view/helpers/tags.rb b/actionpack/lib/action_view/helpers/tags.rb index b81c515c49..cc8af5f417 100644 --- a/actionpack/lib/action_view/helpers/tags.rb +++ b/actionpack/lib/action_view/helpers/tags.rb @@ -21,6 +21,7 @@ module ActionView autoload :GroupedCollectionSelect, 'action_view/helpers/tags/grouped_collection_select' autoload :TimeZoneSelect, 'action_view/helpers/tags/time_zone_select' autoload :DateSelect, 'action_view/helpers/tags/date_select' + autoload :TimeSelect, 'action_view/helpers/tags/time_select' end end end diff --git a/actionpack/lib/action_view/helpers/tags/date_select.rb b/actionpack/lib/action_view/helpers/tags/date_select.rb index 2f2681bf65..5912598ca1 100644 --- a/actionpack/lib/action_view/helpers/tags/date_select.rb +++ b/actionpack/lib/action_view/helpers/tags/date_select.rb @@ -9,11 +9,15 @@ module ActionView end def render - error_wrapping(datetime_selector(@options, @html_options).select_date.html_safe) + error_wrapping(datetime_selector(@options, @html_options).send("select_#{select_type}").html_safe) end private + def select_type + self.class.name.split("::").last.sub("Select", "").downcase + end + def datetime_selector(options, html_options) datetime = value(object) || default_datetime(options) @auto_index ||= nil diff --git a/actionpack/lib/action_view/helpers/tags/time_select.rb b/actionpack/lib/action_view/helpers/tags/time_select.rb new file mode 100644 index 0000000000..9e97deb706 --- /dev/null +++ b/actionpack/lib/action_view/helpers/tags/time_select.rb @@ -0,0 +1,8 @@ +module ActionView + module Helpers + module Tags + class TimeSelect < DateSelect #:nodoc: + end + end + end +end -- cgit v1.2.3