diff options
Diffstat (limited to 'actionpack/lib/action_view/helpers/date_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/date_helper.rb | 251 |
1 files changed, 131 insertions, 120 deletions
diff --git a/actionpack/lib/action_view/helpers/date_helper.rb b/actionpack/lib/action_view/helpers/date_helper.rb index d2ddaafcb3..4deb87180c 100644 --- a/actionpack/lib/action_view/helpers/date_helper.rb +++ b/actionpack/lib/action_view/helpers/date_helper.rb @@ -8,18 +8,18 @@ module ActionView module Helpers # = Action View Date Helpers # - # The Date Helper primarily creates select/option tags for different kinds of dates and date elements. All of the - # select-type methods share a number of common options that are as follows: + # The Date Helper primarily creates select/option tags for different kinds of dates and times or date and time + # elements. All of the select-type methods share a number of common options that are as follows: # # * <tt>:prefix</tt> - overwrites the default prefix of "date" used for the select names. So specifying "birthday" - # would give birthday[month] instead of date[month] if passed to the select_month method. + # would give birthday[month] instead of date[month] if passed to the <tt>select_month</tt> method. # * <tt>:include_blank</tt> - set to true if it should be possible to set an empty date. # * <tt>:discard_type</tt> - set to true if you want to discard the type part of the select name. If set to true, - # the select_month method would use simply "date" (which can be overwritten using <tt>:prefix</tt>) instead of - # "date[month]". + # the <tt>select_month</tt> method would use simply "date" (which can be overwritten using <tt>:prefix</tt>) instead + # of "date[month]". module DateHelper - # Reports the approximate distance in time between two Time or Date objects or integers as seconds. - # Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs + # Reports the approximate distance in time between two Time, Date or DateTime objects or integers as seconds. + # Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs. # Distances are reported based on the following table: # # 0 <-> 29 secs # => less than a minute @@ -119,7 +119,7 @@ module ActionView end end - # Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>. + # Like <tt>distance_of_time_in_words</tt>, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>. # # ==== Examples # time_ago_in_words(3.minutes.from_now) # => 3 minutes @@ -176,37 +176,37 @@ module ActionView # NOTE: Discarded selects will default to 1. So if no month select is available, January will be assumed. # # ==== Examples - # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute - # date_select("post", "written_on") + # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute. + # date_select("article", "written_on") # - # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute, + # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # # with the year in the year drop down box starting at 1995. - # date_select("post", "written_on", :start_year => 1995) + # date_select("article", "written_on", :start_year => 1995) # - # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute, + # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute, # # with the year in the year drop down box starting at 1995, numbers used for months instead of words, # # and without a day select box. - # date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true, + # date_select("article", "written_on", :start_year => 1995, :use_month_numbers => true, # :discard_day => true, :include_blank => true) # - # # Generates a date select that when POSTed is stored in the post variable, in the written_on attribute + # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute # # with the fields ordered as day, month, year rather than month, day, year. - # date_select("post", "written_on", :order => [:day, :month, :year]) + # date_select("article", "written_on", :order => [:day, :month, :year]) # # # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute # # lacking a year field. # date_select("user", "birthday", :order => [:month, :day]) # - # # Generates a date select that when POSTed is stored in the user variable, in the birthday attribute + # # Generates a date select that when POSTed is stored in the article variable, in the written_on attribute # # which is initially set to the date 3 days from the current date - # date_select("post", "written_on", :default => 3.days.from_now) + # date_select("article", "written_on", :default => 3.days.from_now) # # # Generates a date select that when POSTed is stored in the credit_card variable, in the bill_due attribute # # that will have a default day of 20. # date_select("credit_card", "bill_due", :default => { :day => 20 }) # - # # Generates a date select with custom prompts - # date_select("post", "written_on", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) + # # Generates a date select with custom prompts. + # date_select("article", "written_on", :prompt => { :day => 'Select day', :month => 'Select month', :year => 'Select year' }) # # The selects are prepared for multi-parameter assignment to an Active Record object. # @@ -222,25 +222,26 @@ module ActionView # with <tt>:ampm</tt> option. # # This method will also generate 3 input hidden tags, for the actual year, month and day unless the option - # <tt>:ignore_date</tt> is set to +true+. + # <tt>:ignore_date</tt> is set to +true+. If you set the <tt>:ignore_date</tt> to +true+, you must have a + # +date_select+ on the same method within the form otherwise an exception will be raised. # # If anything is passed in the html_options hash it will be applied to every select tag in the set. # # ==== Examples - # # Creates a time select tag that, when POSTed, will be stored in the post variable in the sunrise attribute - # time_select("post", "sunrise") + # # Creates a time select tag that, when POSTed, will be stored in the article variable in the sunrise attribute. + # time_select("article", "sunrise") # - # # Creates a time select tag with a seconds field that, when POSTed, will be stored in the post variables in + # # Creates a time select tag with a seconds field that, when POSTed, will be stored in the article variables in # # the sunrise attribute. - # time_select("post", "start_time", :include_seconds => true) + # time_select("article", "start_time", :include_seconds => true) # - # # You can set the :minute_step to 15 which will give you: 00, 15, 30 and 45. + # # You can set the <tt>:minute_step</tt> to 15 which will give you: 00, 15, 30 and 45. # time_select 'game', 'game_time', {:minute_step => 15} # - # # Creates a time select tag with a custom prompt. Use :prompt => true for generic prompts. - # time_select("post", "written_on", :prompt => {:hour => 'Choose hour', :minute => 'Choose minute', :second => 'Choose seconds'}) - # time_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours - # time_select("post", "written_on", :prompt => true) # generic prompts for all + # # Creates a time select tag with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. + # time_select("article", "written_on", :prompt => {:hour => 'Choose hour', :minute => 'Choose minute', :second => 'Choose seconds'}) + # time_select("article", "written_on", :prompt => {:hour => true}) # generic prompt for hours + # time_select("article", "written_on", :prompt => true) # generic prompts for all # # # You can set :ampm option to true which will show the hours as: 12 PM, 01 AM .. 11 PM. # time_select 'game', 'game_time', {:ampm => true} @@ -260,36 +261,36 @@ module ActionView # If anything is passed in the html_options hash it will be applied to every select tag in the set. # # ==== Examples - # # Generates a datetime select that, when POSTed, will be stored in the post variable in the written_on - # # attribute - # datetime_select("post", "written_on") + # # Generates a datetime select that, when POSTed, will be stored in the article variable in the written_on + # # attribute. + # datetime_select("article", "written_on") # # # Generates a datetime select with a year select that starts at 1995 that, when POSTed, will be stored in the - # # post variable in the written_on attribute. - # datetime_select("post", "written_on", :start_year => 1995) + # # article variable in the written_on attribute. + # datetime_select("article", "written_on", :start_year => 1995) # # # Generates a datetime select with a default value of 3 days from the current time that, when POSTed, will # # be stored in the trip variable in the departing attribute. # datetime_select("trip", "departing", :default => 3.days.from_now) # # # Generate a datetime select with hours in the AM/PM format - # datetime_select("post", "written_on", :ampm => true) + # datetime_select("article", "written_on", :ampm => true) # - # # Generates a datetime select that discards the type that, when POSTed, will be stored in the post variable + # # Generates a datetime select that discards the type that, when POSTed, will be stored in the article variable # # as the written_on attribute. - # datetime_select("post", "written_on", :discard_type => true) + # datetime_select("article", "written_on", :discard_type => true) # - # # Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts. - # datetime_select("post", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) - # datetime_select("post", "written_on", :prompt => {:hour => true}) # generic prompt for hours - # datetime_select("post", "written_on", :prompt => true) # generic prompts for all + # # Generates a datetime select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. + # datetime_select("article", "written_on", :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) + # datetime_select("article", "written_on", :prompt => {:hour => true}) # generic prompt for hours + # datetime_select("article", "written_on", :prompt => true) # generic prompts for all # # The selects are prepared for multi-parameter assignment to an Active Record object. def datetime_select(object_name, method, options = {}, html_options = {}) InstanceTag.new(object_name, method, self, options.delete(:object)).to_datetime_select_tag(options, html_options) end - # Returns a set of html select-tags (one for year, month, day, hour, and minute) pre-selected with the + # Returns a set of html select-tags (one for year, month, day, hour, minute, and second) pre-selected with the # +datetime+. It's also possible to explicitly set the order of the tags using the <tt>:order</tt> option with # an array of symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not # supply a Symbol, it will be appended onto the <tt>:order</tt> passed in. You can also add @@ -301,7 +302,7 @@ module ActionView # ==== Examples # my_date_time = Time.now + 4.days # - # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today) + # # Generates a datetime select that defaults to the datetime in my_date_time (four days after today). # select_datetime(my_date_time) # # # Generates a datetime select that defaults to today (no specified datetime) @@ -331,7 +332,7 @@ module ActionView # # prefixed with 'payday' rather than 'date' # select_datetime(my_date_time, :prefix => 'payday') # - # # Generates a datetime select with a custom prompt. Use :prompt=>true for generic prompts. + # # Generates a datetime select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. # select_datetime(my_date_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) # select_datetime(my_date_time, :prompt => {:hour => true}) # generic prompt for hours # select_datetime(my_date_time, :prompt => true) # generic prompts for all @@ -342,18 +343,18 @@ module ActionView # Returns a set of html select-tags (one for year, month, and day) pre-selected with the +date+. # It's possible to explicitly set the order of the tags using the <tt>:order</tt> option with an array of - # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. If you do not supply a Symbol, - # it will be appended onto the <tt>:order</tt> passed in. + # symbols <tt>:year</tt>, <tt>:month</tt> and <tt>:day</tt> in the desired order. + # If the array passed to the <tt>:order</tt> option does not contain all the three symbols, all tags will be hidden. # # If anything is passed in the html_options hash it will be applied to every select tag in the set. # # ==== Examples - # my_date = Time.today + 6.days + # my_date = Time.now + 6.days # - # # Generates a date select that defaults to the date in my_date (six days after today) + # # Generates a date select that defaults to the date in my_date (six days after today). # select_date(my_date) # - # # Generates a date select that defaults to today (no specified date) + # # Generates a date select that defaults to today (no specified date). # select_date() # # # Generates a date select that defaults to the date in my_date (six days after today) @@ -361,18 +362,18 @@ module ActionView # select_date(my_date, :order => [:year, :month, :day]) # # # Generates a date select that discards the type of the field and defaults to the date in - # # my_date (six days after today) + # # my_date (six days after today). # select_date(my_date, :discard_type => true) # # # Generates a date select that defaults to the date in my_date, - # # which has fields separated by '/' + # # which has fields separated by '/'. # select_date(my_date, :date_separator => '/') # # # Generates a date select that defaults to the datetime in my_date (six days after today) - # # prefixed with 'payday' rather than 'date' + # # prefixed with 'payday' rather than 'date'. # select_date(my_date, :prefix => 'payday') # - # # Generates a date select with a custom prompt. Use :prompt=>true for generic prompts. + # # Generates a date select with a custom prompt. Use <tt>:prompt => true</tt> for generic prompts. # select_date(my_date, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) # select_date(my_date, :prompt => {:hour => true}) # generic prompt for hours # select_date(my_date, :prompt => true) # generic prompts for all @@ -381,7 +382,7 @@ module ActionView DateTimeSelector.new(date, options, html_options).select_date end - # Returns a set of html select-tags (one for hour and minute) + # Returns a set of html select-tags (one for hour and minute). # You can set <tt>:time_separator</tt> key to format the output, and # the <tt>:include_seconds</tt> option to include an input for seconds. # @@ -390,28 +391,28 @@ module ActionView # ==== Examples # my_time = Time.now + 5.days + 7.hours + 3.minutes + 14.seconds # - # # Generates a time select that defaults to the time in my_time + # # Generates a time select that defaults to the time in my_time. # select_time(my_time) # - # # Generates a time select that defaults to the current time (no specified time) + # # Generates a time select that defaults to the current time (no specified time). # select_time() # # # Generates a time select that defaults to the time in my_time, - # # which has fields separated by ':' + # # which has fields separated by ':'. # select_time(my_time, :time_separator => ':') # # # Generates a time select that defaults to the time in my_time, - # # that also includes an input for seconds + # # that also includes an input for seconds. # select_time(my_time, :include_seconds => true) # # # Generates a time select that defaults to the time in my_time, that has fields - # # separated by ':' and includes an input for seconds + # # separated by ':' and includes an input for seconds. # select_time(my_time, :time_separator => ':', :include_seconds => true) # # # Generate a time select field with hours in the AM/PM format # select_time(my_time, :ampm => true) # - # # Generates a time select with a custom prompt. Use :prompt=>true for generic prompts. + # # Generates a time select with a custom prompt. Use <tt>:prompt</tt> to true for generic prompts. # select_time(my_time, :prompt => {:day => 'Choose day', :month => 'Choose month', :year => 'Choose year'}) # select_time(my_time, :prompt => {:hour => true}) # generic prompt for hours # select_time(my_time, :prompt => true) # generic prompts for all @@ -421,25 +422,25 @@ module ActionView end # Returns a select tag with options for each of the seconds 0 through 59 with the current second selected. - # The <tt>second</tt> can also be substituted for a second number. + # The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the <tt>:field_name</tt> option, 'second' by default. # # ==== Examples # my_time = Time.now + 16.minutes # - # # Generates a select field for seconds that defaults to the seconds for the time in my_time + # # Generates a select field for seconds that defaults to the seconds for the time in my_time. # select_second(my_time) # - # # Generates a select field for seconds that defaults to the number given + # # Generates a select field for seconds that defaults to the number given. # select_second(33) # # # Generates a select field for seconds that defaults to the seconds for the time in my_time - # # that is named 'interval' rather than 'second' + # # that is named 'interval' rather than 'second'. # select_second(my_time, :field_name => 'interval') # - # # Generates a select field for seconds with a custom prompt. Use :prompt=>true for a + # # Generates a select field for seconds with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. - # select_minute(14, :prompt => 'Choose seconds') + # select_second(14, :prompt => 'Choose seconds') # def select_second(datetime, options = {}, html_options = {}) DateTimeSelector.new(datetime, options, html_options).select_second @@ -447,23 +448,23 @@ module ActionView # Returns a select tag with options for each of the minutes 0 through 59 with the current minute selected. # Also can return a select tag with options by <tt>minute_step</tt> from 0 through 59 with the 00 minute - # selected. The <tt>minute</tt> can also be substituted for a minute number. + # selected. The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the <tt>:field_name</tt> option, 'minute' by default. # # ==== Examples # my_time = Time.now + 6.hours # - # # Generates a select field for minutes that defaults to the minutes for the time in my_time + # # Generates a select field for minutes that defaults to the minutes for the time in my_time. # select_minute(my_time) # - # # Generates a select field for minutes that defaults to the number given + # # Generates a select field for minutes that defaults to the number given. # select_minute(14) # # # Generates a select field for minutes that defaults to the minutes for the time in my_time - # # that is named 'stride' rather than 'second' - # select_minute(my_time, :field_name => 'stride') + # # that is named 'moment' rather than 'minute'. + # select_minute(my_time, :field_name => 'moment') # - # # Generates a select field for minutes with a custom prompt. Use :prompt=>true for a + # # Generates a select field for minutes with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. # select_minute(14, :prompt => 'Choose minutes') # @@ -472,23 +473,23 @@ module ActionView end # Returns a select tag with options for each of the hours 0 through 23 with the current hour selected. - # The <tt>hour</tt> can also be substituted for a hour number. + # The <tt>datetime</tt> can be either a +Time+ or +DateTime+ object or an integer. # Override the field name using the <tt>:field_name</tt> option, 'hour' by default. # # ==== Examples # my_time = Time.now + 6.hours # - # # Generates a select field for hours that defaults to the hour for the time in my_time + # # Generates a select field for hours that defaults to the hour for the time in my_time. # select_hour(my_time) # - # # Generates a select field for hours that defaults to the number given + # # Generates a select field for hours that defaults to the number given. # select_hour(13) # - # # Generates a select field for hours that defaults to the minutes for the time in my_time - # # that is named 'stride' rather than 'second' + # # Generates a select field for hours that defaults to the hour for the time in my_time + # # that is named 'stride' rather than 'hour'. # select_hour(my_time, :field_name => 'stride') # - # # Generates a select field for hours with a custom prompt. Use :prompt => true for a + # # Generates a select field for hours with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. # select_hour(13, :prompt => 'Choose hour') # @@ -500,23 +501,23 @@ module ActionView end # Returns a select tag with options for each of the days 1 through 31 with the current day selected. - # The <tt>date</tt> can also be substituted for a hour number. + # The <tt>date</tt> can also be substituted for a day number. # Override the field name using the <tt>:field_name</tt> option, 'day' by default. # # ==== Examples - # my_date = Time.today + 2.days + # my_date = Time.now + 2.days # - # # Generates a select field for days that defaults to the day for the date in my_date + # # Generates a select field for days that defaults to the day for the date in my_date. # select_day(my_time) # - # # Generates a select field for days that defaults to the number given + # # Generates a select field for days that defaults to the number given. # select_day(5) # # # Generates a select field for days that defaults to the day for the date in my_date - # # that is named 'due' rather than 'day' + # # that is named 'due' rather than 'day'. # select_day(my_time, :field_name => 'due') # - # # Generates a select field for days with a custom prompt. Use :prompt => true for a + # # Generates a select field for days with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. # select_day(5, :prompt => 'Choose day') # @@ -539,7 +540,7 @@ module ActionView # select_month(Date.today) # # # Generates a select field for months that defaults to the current month that - # # is named "start" rather than "month" + # # is named "start" rather than "month". # select_month(Date.today, :field_name => 'start') # # # Generates a select field for months that defaults to the current month that @@ -558,7 +559,7 @@ module ActionView # # will use keys like "Januar", "Marts." # select_month(Date.today, :use_month_names => %w(Januar Februar Marts ...)) # - # # Generates a select field for months with a custom prompt. Use :prompt => true for a + # # Generates a select field for months with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. # select_month(14, :prompt => 'Choose month') # @@ -574,22 +575,22 @@ module ActionView # # ==== Examples # # Generates a select field for years that defaults to the current year that - # # has ascending year values + # # has ascending year values. # select_year(Date.today, :start_year => 1992, :end_year => 2007) # # # Generates a select field for years that defaults to the current year that - # # is named 'birth' rather than 'year' + # # is named 'birth' rather than 'year'. # select_year(Date.today, :field_name => 'birth') # # # Generates a select field for years that defaults to the current year that - # # has descending year values + # # has descending year values. # select_year(Date.today, :start_year => 2005, :end_year => 1900) # # # Generates a select field for years that defaults to the year 2006 that - # # has ascending year values + # # has ascending year values. # select_year(2006, :start_year => 2000, :end_year => 2010) # - # # Generates a select field for years with a custom prompt. Use :prompt => true for a + # # Generates a select field for years with a custom prompt. Use <tt>:prompt => true</tt> for a # # generic prompt. # select_year(14, :prompt => 'Choose year') # @@ -620,7 +621,6 @@ module ActionView end class DateTimeSelector #:nodoc: - extend ActiveSupport::Memoizable include ActionView::Helpers::TagHelper DEFAULT_PREFIX = 'date'.freeze @@ -765,11 +765,16 @@ module ActionView if @options[:use_hidden] || @options[:discard_year] build_hidden(:year, val) else - options = {} - options[:start] = @options[:start_year] || middle_year - 5 - options[:end] = @options[:end_year] || middle_year + 5 - options[:step] = options[:start] < options[:end] ? 1 : -1 - options[:leading_zeros] = false + options = {} + options[:start] = @options[:start_year] || middle_year - 5 + options[:end] = @options[:end_year] || middle_year + 5 + options[:step] = options[:start] < options[:end] ? 1 : -1 + options[:leading_zeros] = false + options[:max_years_allowed] = @options[:max_years_allowed] || 1000 + + if (options[:end] - options[:start]).abs > options[:max_years_allowed] + raise ArgumentError, "There're too many years options to be built. Are you sure you haven't mistyped something? You can provide the :max_years_allowed parameter" + end build_options_and_select(:year, val, options) end @@ -783,21 +788,22 @@ module ActionView end # Returns translated month names, but also ensures that a custom month - # name array has a leading nil element + # name array has a leading nil element. def month_names - month_names = @options[:use_month_names] || translated_month_names - month_names.unshift(nil) if month_names.size < 13 - month_names + @month_names ||= begin + month_names = @options[:use_month_names] || translated_month_names + month_names.unshift(nil) if month_names.size < 13 + month_names + end end - memoize :month_names - # Returns translated month names + # Returns translated month names. # => [nil, "January", "February", "March", # "April", "May", "June", "July", # "August", "September", "October", # "November", "December"] # - # If :use_short_month option is set + # If <tt>:use_short_month</tt> option is set # => [nil, "Jan", "Feb", "Mar", "Apr", "May", "Jun", # "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] def translated_month_names @@ -805,13 +811,13 @@ module ActionView I18n.translate(key, :locale => @options[:locale]) end - # Lookup month name for number + # Lookup month name for number. # month_name(1) => "January" # - # If :use_month_numbers option is passed + # If <tt>:use_month_numbers</tt> option is passed # month_name(1) => 1 # - # If :add_month_numbers option is passed + # If <tt>:add_month_numbers</tt> option is passed # month_name(1) => "1 - January" def month_name(number) if @options[:use_month_numbers] @@ -824,24 +830,29 @@ module ActionView end def date_order - @options[:order] || translated_date_order + @date_order ||= @options[:order] || translated_date_order end - memoize :date_order def translated_date_order I18n.translate(:'date.order', :locale => @options[:locale]) || [] end - # Build full select tag from date type and options + # Build full select tag from date type and options. def build_options_and_select(type, selected, options = {}) build_select(type, build_options(selected, options)) end - # Build select option html from date value and options + # Build select option html from date value and options. # build_options(15, :start => 1, :end => 31) # => "<option value="1">1</option> - # <option value=\"2\">2</option> - # <option value=\"3\">3</option>..." + # <option value="2">2</option> + # <option value="3">3</option>..." + # + # If <tt>:step</tt> options is passed + # build_options(15, :start => 1, :end => 31, :step => 2) + # => "<option value="1">1</option> + # <option value="3">3</option> + # <option value="5">5</option>..." def build_options(selected, options = {}) start = options.delete(:start) || 0 stop = options.delete(:end) || 59 @@ -860,7 +871,7 @@ module ActionView (select_options.join("\n") + "\n").html_safe end - # Builds select tag from date type and html select options + # Builds select tag from date type and html select options. # build_select(:month, "<option value="1">January</option>...") # => "<select id="post_written_on_2i" name="post[written_on(2i)]"> # <option value="1">January</option>... @@ -880,7 +891,7 @@ module ActionView (content_tag(:select, select_html.html_safe, select_options) + "\n").html_safe end - # Builds a prompt option tag with supplied options or from default options + # Builds a prompt option tag with supplied options or from default options. # prompt_option_tag(:month, :prompt => 'Select month') # => "<option value="">Select month</option>" def prompt_option_tag(type, options) @@ -897,7 +908,7 @@ module ActionView prompt ? content_tag(:option, prompt, :value => '') : '' end - # Builds hidden input tag for date part and value + # Builds hidden input tag for date part and value. # build_hidden(:year, 2008) # => "<input id="post_written_on_1i" name="post[written_on(1i)]" type="hidden" value="2008" />" def build_hidden(type, value) @@ -909,7 +920,7 @@ module ActionView }.merge(@html_options.slice(:disabled))) + "\n").html_safe end - # Returns the name attribute for the input tag + # Returns the name attribute for the input tag. # => post[written_on(1i)] def input_name_from_type(type) prefix = @options[:prefix] || ActionView::Helpers::DateTimeSelector::DEFAULT_PREFIX @@ -923,7 +934,7 @@ module ActionView @options[:discard_type] ? prefix : "#{prefix}[#{field_name}]" end - # Returns the id attribute for the input tag + # Returns the id attribute for the input tag. # => "post_written_on_1i" def input_id_from_type(type) input_name_from_type(type).gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '') @@ -940,7 +951,7 @@ module ActionView select.html_safe end - # Returns the separator for a given datetime component + # Returns the separator for a given datetime component. def separator(type) case type when :year |