0
@@ -5,7 +5,7 @@ module ActionView
0
# The Date Helper primarily creates select/option tags for different kinds of dates and date elements. All of the select-type methods
0
# share a number of common options that are as follows:
0
- # * <tt>:prefix</tt> - overwrites the default prefix of "date" used for the select names. So specifying "birthday" would give
0
+ # * <tt>:prefix</tt> - overwrites the default prefix of "date" used for the select names. So specifying "birthday" would give
0
# birthday[month] instead of date[month] if passed to the select_month method.
0
# * <tt>:include_blank</tt> - set to true if it should be possible to set an empty date.
0
# * <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
0
@@ -13,11 +13,11 @@ module ActionView
0
DEFAULT_PREFIX = "date" unless const_defined?("DEFAULT_PREFIX")
0
- # Reports the approximate distance in time between to Time objects. For example, if the distance is 47 minutes, it'll return
0
+ # Reports the approximate distance in time between to Time objects. For example, if the distance is 47 minutes, it'll return
0
# "about 1 hour". See the source for the complete wording list.
0
def distance_of_time_in_words(from_time, to_time)
0
distance_in_minutes = ((to_time - from_time) / 60).round
0
case distance_in_minutes
0
when 0 then "less than a minute"
0
@@ -28,7 +28,7 @@ module ActionView
0
else "#{(distance_in_minutes / 1440).round} days"
0
# Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
0
def distance_of_time_in_words_to_now(from_time)
0
distance_of_time_in_words(from_time, Time.now)
0
@@ -48,7 +48,7 @@ module ActionView
0
# date_select("post", "written_on")
0
# date_select("post", "written_on", :start_year => 1995)
0
- # date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
0
+ # date_select("post", "written_on", :start_year => 1995, :use_month_numbers => true,
0
# :discard_day => true, :include_blank => true)
0
# date_select("post", "written_on", :order => [:day, :month, :year])
0
# date_select("user", "birthday", :order => [:month, :day])
0
@@ -107,7 +107,7 @@ module ActionView
0
minute_options << ((datetime.kind_of?(Fixnum) ? datetime : datetime.min) == minute ?
0
- "<option selected=\"selected\">#{leading_zero_on_single_digits(minute)}</option>\n" :
0
+ "<option selected=\"selected\">#{leading_zero_on_single_digits(minute)}</option>\n" :
0
"<option>#{leading_zero_on_single_digits(minute)}</option>\n"
0
@@ -122,7 +122,7 @@ module ActionView
0
hour_options << ((datetime.kind_of?(Fixnum) ? datetime : datetime.hour) == hour ?
0
- "<option selected=\"selected\">#{leading_zero_on_single_digits(hour)}</option>\n" :
0
+ "<option selected=\"selected\">#{leading_zero_on_single_digits(hour)}</option>\n" :
0
"<option>#{leading_zero_on_single_digits(hour)}</option>\n"
0
@@ -137,18 +137,18 @@ module ActionView
0
day_options << ((date.kind_of?(Fixnum) ? date : date.day) == day ?
0
- "<option selected=\"selected\">#{day}</option>\n" :
0
+ "<option selected=\"selected\">#{day}</option>\n" :
0
"<option>#{day}</option>\n"
0
select_html("day", day_options, options[:prefix], options[:include_blank], options[:discard_type])
0
# Returns a select tag with options for each of the months January through December with the current month selected.
0
# The month names are presented as keys (what's shown to the user) and the month numbers (1-12) are used as values
0
# (what's submitted to the server). It's also possible to use month numbers for the presentation instead of names --
0
- # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names,
0
+ # set the <tt>:use_month_numbers</tt> key in +options+ to true for this to happen. If you want both numbers and names,
0
# set the <tt>:add_month_numbers</tt> key in +options+ to true. Examples:
0
# select_month(Date.today) # Will use keys like "January", "March"
0
@@ -158,7 +158,7 @@ module ActionView
0
1.upto(12) do |month_number|
0
- month_name = if options[:use_month_numbers]
0
+ month_name = if options[:use_month_numbers]
0
elsif options[:add_month_numbers]
0
month_number.to_s + " - " + Date::MONTHNAMES[month_number]
0
@@ -167,16 +167,16 @@ module ActionView
0
month_options << ((date.kind_of?(Fixnum) ? date : date.month) == month_number ?
0
- %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
0
+ %(<option value="#{month_number}" selected="selected">#{month_name}</option>\n) :
0
%(<option value="#{month_number}">#{month_name}</option>\n)
0
select_html("month", month_options, options[:prefix], options[:include_blank], options[:discard_type])
0
# Returns a select tag with options for each of the five years on each side of the current, which is selected. The five year radius
0
- # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. The <tt>date</tt> can also be substituted
0
+ # can be changed using the <tt>:start_year</tt> and <tt>:end_year</tt> keys in the +options+. The <tt>date</tt> can also be substituted
0
# for a year given as a number. Example:
0
# select_year(Date.today, :start_year => 1992, :end_year => 2007)
0
@@ -187,14 +187,14 @@ module ActionView
0
(options[:start_year] || default_start_year).upto(options[:end_year] || default_end_year) do |year|
0
year_options << ((date.kind_of?(Fixnum) ? date : date.year) == year ?
0
- "<option selected=\"selected\">#{year}</option>\n" :
0
+ "<option selected=\"selected\">#{year}</option>\n" :
0
"<option>#{year}</option>\n"
0
select_html("year", year_options, options[:prefix], options[:include_blank], options[:discard_type])
0
def select_html(type, options, prefix = nil, include_blank = false, discard_type = false)
0
select_html = %(<select name="#{prefix || DEFAULT_PREFIX})
0
@@ -206,7 +206,7 @@ module ActionView
0
def leading_zero_on_single_digits(number)
0
number > 9 ? number : "0#{number}"
0
@@ -217,32 +217,32 @@ module ActionView
0
def to_date_select_tag(options = {})
0
defaults = { :discard_type => true }
0
- options = defaults.merge(options)
0
- options_with_prefix = Proc.new { |position| options.update({ :prefix => "#{@object_name}[#{@method_name}(#{position}i)]" }) }
0
+ options = defaults.merge(options)
0
+ options_with_prefix = Proc.new { |position| options.merge(:prefix => "#{@object_name}[#{@method_name}(#{position}i)]") }
0
date = options[:include_blank] ? (value || 0) : (value || Date.today)
0
options[:order] = [:month, :year, :day] if options[:month_before_year] # For backwards compatibility
0
options[:order] ||= [:year, :month, :day]
0
position = {:year => 1, :month => 2, :day => 3}
0
discard[:year] = true if options[:discard_year]
0
discard[:month] = true if options[:discard_month]
0
discard[:day] = true if options[:discard_day] or options[:discard_month]
0
options[:order].each do |param|
0
date_select << self.send("select_#{param}", date, options_with_prefix.call(position[param])) unless discard[param]
0
def to_datetime_select_tag(options = {})
0
defaults = { :discard_type => true }
0
- options = defaults.merge(options)
0
- options_with_prefix = Proc.new { |position| options.update({ :prefix => "#{@object_name}[#{@method_name}(#{position}i)]" }) }
0
+ options = defaults.merge(options)
0
+ options_with_prefix = Proc.new { |position| options.merge(:prefix => "#{@object_name}[#{@method_name}(#{position}i)]") }
0
datetime = options[:include_blank] ? (value || 0) : (value || Time.now)
0
datetime_select = select_year(datetime, options_with_prefix.call(1))
0
@@ -250,7 +250,7 @@ module ActionView
0
datetime_select << select_day(datetime, options_with_prefix.call(3)) unless options[:discard_day] || options[:discard_month]
0
datetime_select << " — " + select_hour(datetime, options_with_prefix.call(4)) unless options[:discard_hour]
0
datetime_select << " : " + select_minute(datetime, options_with_prefix.call(5)) unless options[:discard_minute] || options[:discard_hour]