Skip to content

Commit

Permalink
Move event date from helper into partial. [#10]
Browse files Browse the repository at this point in the history
  • Loading branch information
marnen committed Jan 7, 2009
1 parent 441ce64 commit 49bdcdc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 21 deletions.
14 changes: 0 additions & 14 deletions app/helpers/events_helper.rb
Expand Up @@ -10,20 +10,6 @@ def attendance_status(event, user)
end
end

# Generates an HTML date element for #Event, including hCalendar[http://microformats.org/wiki/hcalendar] annotation.
#
# Usage:
#
# <tt>@event.date = today</tt>
#
# <tt>date_element(@event) # -> something like '<abbr class="dtstart" title="20080924">24 Sep 2008</abbr>'</tt>
def date_element(event)
# generate a microformat HTML date element
ical_date = h event.date.to_formatted_s(:ical)
full_date = h event.date.to_formatted_s(:rfc822)
content_tag :abbr, full_date, :class => :dtstart, :title => ical_date
end

# Generates a delete link for #Event.
def delete_link(event)
link_to h(_("delete")), url_for(:controller => 'events', :action => 'delete', :id => event.id), :class => :delete
Expand Down
2 changes: 1 addition & 1 deletion app/views/events/_event.html.haml
Expand Up @@ -13,7 +13,7 @@
= delete_link(event)
%td
%span.uid&= ical_uid(event)
= date_element(event)
= render :partial => 'date', :locals => {:event => event}
- if User.current_user.calendars.size > 1
%td.calendar
&= event.calendar
Expand Down
4 changes: 0 additions & 4 deletions spec/helpers/events_helper_spec.rb
Expand Up @@ -29,10 +29,6 @@
helper.map_link(@event).should be_a_kind_of(String)
end

it "should generate a microformat HTML date element as a String" do
@event.date = Time.now # arbitrary value
helper.date_element(@event).should be_a_kind_of(String)
end
=begin
#Delete this example and add some real ones or delete this file
it "should include the EventsHelper" do
Expand Down
8 changes: 6 additions & 2 deletions spec/views/events/_event.html.haml_spec.rb
Expand Up @@ -128,10 +128,14 @@
response.should have_tag("#event_#{@event.id} a.ical[href=" << url << "]")
end

it "should show a date for the event in RFC 822 format, wrapped in an <abbr> of class 'dtstart' with ical-style date as the title" do
it "should show a date for the event, wrapped in an <abbr> of class 'dtstart' with ical-style date as the title" do
render_view
date = @event.date
response.should have_tag("#event_#{@event.id} abbr.dtstart[title=" << date.to_formatted_s(:ical) << "]", date.to_formatted_s(:rfc822))
response.should have_tag("#event_#{@event.id} abbr.dtstart[title=" << date.to_formatted_s(:ical) << "]") do |tag|
date.to_formatted_s(:rfc822).split(' ').each do |s|
tag.should have_tag('*', %r{#{s}})
end
end
end

it "should have an element of class 'uid' for each event, containing an iCal unique ID for the event" do
Expand Down

0 comments on commit 49bdcdc

Please sign in to comment.