Permalink
Browse files

added second option

  • Loading branch information...
1 parent 697d7d1 commit 527f15a973aedd35b55ccd7f3dd227d92fd6644c @ludicast committed Mar 14, 2010
Showing with 18 additions and 5 deletions.
  1. +9 −5 lib/clot/date_tags.rb
  2. +9 −0 spec/date_tag_spec.rb
View
@@ -209,6 +209,8 @@ def personal_attributes(name,value)
@date_separator = value
when "time_separator" then
@time_separator = value
+ when "include_seconds" then
+ @include_seconds = true
when /(.*)_prompt/ then
value_string = value === true ? 'true' : "'#{value}'"
instance_variable_set("@#{$1}_prompt".to_sym,",prompt:#{value_string}")
@@ -237,7 +239,7 @@ def set_unit(unit)
def time_unit(unit)
case unit
- # when "seconds" then "sec"
+ when "second" then "sec"
when "minute" then "min"
else unit
end
@@ -265,12 +267,14 @@ def render_nested(context)
class SelectTime < MultiDateTag
def render_nested(context)
- # @hour = SelectHour.new(".select_hour",@time.hour.to_s,[])
- # @minute = SelectMinute.new(".select_minute",@time.min.to_s,[])
- ["hour", "minute"].each do |unit|
+ units = ["hour", "minute"]
+ if @include_seconds
+ units << "second"
+ end
+ units.each do |unit|
set_unit unit
end
- @hour.render(context) + @time_separator.to_s + @minute.render(context)
+ @hour.render(context) + @time_separator.to_s + @minute.render(context) + (@second ? @second.render(context) : '')
end
end
View
@@ -315,5 +315,14 @@ def get_options(from_val,to_val, hash = {})
@tag.should parse_with_vars_to(@hour_string + ":" + @minute_string, 'time' => time)
end
+ it "should allow seconds" do
+ time = Time.now
+ @tag = "{% select_time time, include_seconds:true %}"
+ @hour_string = '<select id="date_hour" name="date[hour]">' + get_options(0,(time.hour - 1)) + %{<option selected="selected" value="#{time.hour}">#{time.hour}</option>} + get_options((time.hour + 1),59) + "</select>"
+ @minute_string = '<select id="date_minute" name="date[minute]">' + get_options(0,(time.min - 1)) + %{<option selected="selected" value="#{time.min}">#{time.min}</option>} + get_options((time.min + 1),59) + "</select>"
+ @second_string = '<select id="date_second" name="date[second]">' + get_options(0,(time.sec - 1)) + %{<option selected="selected" value="#{time.sec}">#{time.sec}</option>} + get_options((time.sec + 1),59) + "</select>"
+ @tag.should parse_with_vars_to(@hour_string + @minute_string + @second_string, 'time' => time)
+ end
+
end
end

0 comments on commit 527f15a

Please sign in to comment.