lib/action_view/helpers/date_helper.rb in actionpack-2.3.18 vs lib/action_view/helpers/date_helper.rb in actionpack-3.0.0.beta

- old
+ new

@@ -1,8 +1,7 @@ require "date" require 'action_view/helpers/tag_helper' -require 'active_support/core_ext/hash/slice' module ActionView module 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: @@ -117,33 +116,33 @@ end alias_method :distance_of_time_in_words_to_now, :time_ago_in_words # Returns a set of select tags (one for year, month, and day) pre-selected for accessing a specified date-based - # attribute (identified by +method+) on an object assigned to the template (identified by +object+). You can - # the output in the +options+ hash. + # attribute (identified by +method+) on an object assigned to the template (identified by +object+). # + # # ==== Options # * <tt>:use_month_numbers</tt> - Set to true if you want to use month numbers rather than month names (e.g. # "2" instead of "February"). - # * <tt>:use_short_month</tt> - Set to true if you want to use the abbreviated month name instead of the full - # name (e.g. "Feb" instead of "February"). - # * <tt>:add_month_number</tt> - Set to true if you want to show both, the month's number and name (e.g. + # * <tt>:use_short_month</tt> - Set to true if you want to use abbreviated month names instead of full + # month names (e.g. "Feb" instead of "February"). + # * <tt>:add_month_numbers</tt> - Set to true if you want to use both month numbers and month names (e.g. # "2 - February" instead of "February"). # * <tt>:use_month_names</tt> - Set to an array with 12 month names if you want to customize month names. - # Note: You can also use Rails' new i18n functionality for this. + # Note: You can also use Rails' i18n functionality for this. # * <tt>:date_separator</tt> - Specifies a string to separate the date fields. Default is "" (i.e. nothing). # * <tt>:start_year</tt> - Set the start year for the year select. Default is <tt>Time.now.year - 5</tt>. # * <tt>:end_year</tt> - Set the end year for the year select. Default is <tt>Time.now.year + 5</tt>. # * <tt>:discard_day</tt> - Set to true if you don't want to show a day select. This includes the day # as a hidden field instead of showing a select field. Also note that this implicitly sets the day to be the # first of the given month in order to not create invalid dates like 31 February. # * <tt>:discard_month</tt> - Set to true if you don't want to show a month select. This includes the month # as a hidden field instead of showing a select field. Also note that this implicitly sets :discard_day to true. # * <tt>:discard_year</tt> - Set to true if you don't want to show a year select. This includes the year # as a hidden field instead of showing a select field. - # * <tt>:order</tt> - Set to an array containing <tt>:day</tt>, <tt>:month</tt> and <tt>:year</tt> do + # * <tt>:order</tt> - Set to an array containing <tt>:day</tt>, <tt>:month</tt> and <tt>:year</tt> to # customize the order in which the select fields are shown. If you leave out any of the symbols, the respective # select will not be shown (like when you set <tt>:discard_xxx => true</tt>. Defaults to the order defined in # the respective locale (e.g. [:year, :month, :day] in the en locale that ships with Rails). # * <tt>:include_blank</tt> - Include a blank option in every select field so it's possible to set empty # dates. @@ -243,11 +242,11 @@ InstanceTag.new(object_name, method, self, options.delete(:object)).to_time_select_tag(options, html_options) end # Returns a set of select tags (one for year, month, day, hour, and minute) pre-selected for accessing a # specified datetime-based attribute (identified by +method+) on an object assigned to the template (identified - # by +object+). Examples: + # by +object+). # # 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 @@ -814,11 +813,11 @@ value = leading_zeros ? sprintf("%02d", i) : i tag_options = { :value => value } tag_options[:selected] = "selected" if selected == i select_options << content_tag(:option, value, tag_options) end - (select_options.join("\n") + "\n").html_safe + select_options.join("\n") + "\n" end # 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)]"> @@ -832,13 +831,13 @@ select_options.merge!(:disabled => 'disabled') if @options[:disabled] select_html = "\n" select_html << content_tag(:option, '', :value => '') + "\n" if @options[:include_blank] select_html << prompt_option_tag(type, @options[:prompt]) + "\n" if @options[:prompt] - select_html << select_options_as_html + select_html << select_options_as_html.to_s - (content_tag(:select, select_html.html_safe, select_options) + "\n").html_safe + (content_tag(:select, select_html, select_options) + "\n").html_safe end # Builds a prompt option tag with supplied options or from default options # prompt_option_tag(:month, :prompt => 'Select month') # => "<option value="">Select month</option>" @@ -864,11 +863,11 @@ (tag(:input, { :type => "hidden", :id => input_id_from_type(type), :name => input_name_from_type(type), :value => value - }.merge(@html_options.slice(:disabled))) + "\n").html_safe + }) + "\n").html_safe end # Returns the name attribute for the input tag # => post[written_on(1i)] def input_name_from_type(type) @@ -906,11 +905,11 @@ when :month, :day @options[:date_separator] when :hour (@options[:discard_year] && @options[:discard_day]) ? "" : @options[:datetime_separator] when :minute - @options[:discard_minute] ? "" : @options[:time_separator] + @options[:time_separator] when :second @options[:include_seconds] ? @options[:time_separator] : "" end end end @@ -934,10 +933,10 @@ options = options.dup options[:field_name] = @method_name options[:include_position] = true options[:prefix] ||= @object_name - options[:index] = @auto_index if defined?(@auto_index) && @auto_index && !options.has_key?(:index) + options[:index] = @auto_index if @auto_index && !options.has_key?(:index) options[:datetime_separator] ||= ' &mdash; ' options[:time_separator] ||= ' : ' DateTimeSelector.new(datetime, options.merge(:tag => true), html_options) end