Skip to content

Commit

Permalink
added date
Browse files Browse the repository at this point in the history
  • Loading branch information
ludicast committed Mar 14, 2010
1 parent c946e60 commit d6c2a78
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
29 changes: 23 additions & 6 deletions lib/clot/date_tags.rb
Expand Up @@ -49,10 +49,27 @@ def default_end
59
end

def id_string(field_name)
if field_name && ! field_name.blank?
%{id="date_#{field_name}"}
else
%{id="date"}
end
end

def name_string(field_name)
if field_name && ! field_name.blank?
%{name="date[#{field_name}]"}
else
%{name="date"}
end
end

def render_string
field_name = @field_name || default_field_name
%{<select id="date_#{field_name}" name="date[#{field_name}]">#{@prompt_val}} + get_options(default_start, default_end, @value_string) + "</select>"
%{<select #{id_string(field_name)} #{name_string(field_name)}>#{@prompt_val}} + get_options(default_start, default_end, @value_string) + "</select>"
end

def time_method
default_field_name
end
Expand Down Expand Up @@ -180,8 +197,9 @@ def set_primary_attributes(context)
def personal_attributes(name,value)
super(name,value) || case name
when "order" then
puts "received order #{value}"
@order = value
when "discard_type" then
@field_name = ",field_name:''"
end
end

Expand All @@ -200,11 +218,10 @@ def render(context)

class SelectDate < MultiDateTag
def render_nested(context)
@year = SelectYear.new(".select_year",@time.year.to_s,[])
@month = SelectMonth.new(".select_month",@time.month.to_s,[])
@day = SelectDay.new(".select_day",@time.day.to_s,[])
@year = SelectYear.new(".select_year","#{@time.year.to_s} #{@field_name}",[])
@month = SelectMonth.new(".select_month","#{@time.month.to_s} #{@field_name}",[])
@day = SelectDay.new(".select_day","#{@time.day.to_s} #{@field_name}",[])

puts "order #{@order}"
order = @order || ['year', 'month', 'day']

data = ""
Expand Down
11 changes: 10 additions & 1 deletion spec/date_tag_spec.rb
Expand Up @@ -231,7 +231,14 @@ def get_options(from_val,to_val, hash = {})
@day_string = '<select id="date_day" name="date[day]">' + get_options(1,(time.day - 1)) + %{<option selected="selected" value="#{time.day}">#{time.day}</option>} + get_options((time.day + 1),31) + "</select>"
@tag.should parse_with_vars_to(@day_string + @month_string + @year_string, 'time' => time)
end

it "should allow discarding of type" do
time = Time.now
@tag = "{% select_date time,discard_type:true %}"
@year_string = '<select id="date" name="date">' + get_options(time.year-5,time.year - 1) + %{<option selected="selected" value="#{time.year}">#{time.year}</option>} + get_options(time.year + 1,time.year + 5) + "</select>"
@month_string = '<select id="date" name="date">' + get_options(1,time.month - 1,{:label_func => :get_month}) + %{<option selected="selected" value="#{time.month}">#{get_month time.month}</option>} + get_options(time.month + 1,12,{:label_func => :get_month}) + "</select>"
@day_string = '<select id="date" name="date">' + get_options(1,(time.day - 1)) + %{<option selected="selected" value="#{time.day}">#{time.day}</option>} + get_options((time.day + 1),31) + "</select>"
@tag.should parse_with_vars_to(@year_string + @month_string + @day_string, 'time' => time)
end
it "should set default time to current time" do
time = Time.now
@tag = "{% select_date %}"
Expand Down Expand Up @@ -259,5 +266,7 @@ def get_options(from_val,to_val, hash = {})
@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>"
@tag.should parse_to(@hour_string + @minute_string)
end


end
end

0 comments on commit d6c2a78

Please sign in to comment.