Browse files

friendlier dates in date lists

  • Loading branch information...
1 parent 76ffbcd commit 891107f6be4c589f58674fc4fb120e3738444d79 @jlapier committed Mar 2, 2012
View
5 app/models/content_page.rb
@@ -70,8 +70,9 @@ def function(function_string)
begin
self.send("#{function_name.downcase}_to_html", params_to_send)
- rescue NameError
- return "<em>Unknown function: #{function_name}</em>"
+ rescue NameError => e
+ return "<em>Unknown function: #{function_name}</em>" +
+ "<!-- #{e.inspect} -->"
rescue => e
return "<em>Error in function: #{function_name}</em>" +
"<!-- #{e.inspect} -->"
View
4 app/views/event_calendar/events/_form.html.erb
@@ -28,7 +28,7 @@
</fieldset>
</li>
<%= form.input :start_date, :required => false, :as => :string,
- :input_html => { :value => @event.start_date.to_s } %>
+ :input_html => { :value => @event.start_date.to_s(:american) } %>
<li id="event_end_time_input" class="time optional">
<input id="event_end_time_1i" type="hidden" value="<%= Date.current.year %>" name="event[end_time(1i)]">
<fieldset>
@@ -52,7 +52,7 @@
</fieldset>
</li>
<%= form.input :end_date, :required => false, :as => :string,
- :input_html => { :value => @event.end_date.to_s } %>
+ :input_html => { :value => @event.end_date.to_s(:american) } %>
<%= form.input :timezone, :as => :time_zone, :priority_zones => /^(Eastern|Central|Mountain|Pacific) Time/ %>
<%= form.input :facilitators, :hint => 'eg Sally Resonant, DSM WRRC' %>
<%= form.input :presenters, :hint => 'eg Jane Doe, DSM WRRC' %>
View
2 config/initializers/time_formats.rb
@@ -0,0 +1,2 @@
+Time::DATE_FORMATS[:american] = "%m/%d/%Y"
+Date::DATE_FORMATS[:american] = "%m/%d/%Y"
View
9 lib/html_generator.rb
@@ -44,15 +44,16 @@ def list_events_to_html(options = {})
events = events.where :event_type => options[:other_params]
end
events = events.order("start_on ASC").limit(options[:limit])
- out = "<ul>"
+ out = '<ul class="event_list_in_page">'
if events.empty?
out += "<li><em>No events were found</em></li>"
else
events.each do |event|
- date_string = event.start_on.strftime('%B %d')
+ date_string = event.start_on.strftime("%B #{ActiveSupport::Inflector.ordinalize(event.start_on.day)}")
if event.end_on and event.end_on.to_date != event.start_on.to_date
- date_string += " - " + (event.start_on.month == event.end_on.month ? event.end_on.strftime('%d') : event.end_on.strftime('%B %d'))
+ date_string += " - " + (event.start_on.month == event.end_on.month ? ActiveSupport::Inflector.ordinalize(event.end_on.day) :
+ event.end_on.strftime("%B #{ActiveSupport::Inflector.ordinalize(event.end_on.day)}"))
end
out += "<li><a href=\"/event_calendar/events/#{event.id}\">#{date_string}: #{event.name}</a></li>"
end
@@ -141,7 +142,7 @@ def link_page_to_html(options={})
page = ContentPage.find_by_name page_name
if page
- "<a href=\"/content_pages/#{page.id}\">#{page.name}</a>"
+ "<a href=\"/content_pages/#{page.to_param}\">#{page.name}</a>"
else
"<em>No page found named: #{page_name}</em>"
end

0 comments on commit 891107f

Please sign in to comment.