Fixed rendering of Recently Revised
This commit is contained in:
parent
f8b3e2b11d
commit
e44d16aef9
4 changed files with 26 additions and 17 deletions
|
@ -122,6 +122,11 @@ class WikiController < ApplicationController
|
|||
def recently_revised
|
||||
parse_category
|
||||
@pages_by_revision = @pages_in_category.by_revision
|
||||
@pages_by_day = Hash.new { |h, day| h[day] = [] }
|
||||
@pages_by_revision.each do |page|
|
||||
day = Date.new(page.revised_at.year, page.revised_at.month, page.revised_at.day)
|
||||
@pages_by_day[day] << page
|
||||
end
|
||||
end
|
||||
|
||||
def rss_with_content
|
||||
|
|
|
@ -79,12 +79,10 @@ module ApplicationHelper
|
|||
|
||||
def format_date(date, include_time = true)
|
||||
# Must use DateTime because Time doesn't support %e on at least some platforms
|
||||
date_time = DateTime.new(date.year, date.mon, date.day, date.hour, date.min,
|
||||
date.sec)
|
||||
if include_time
|
||||
return date_time.strftime("%B %e, %Y %H:%M:%S")
|
||||
DateTime.new(date.year, date.mon, date.day, date.hour, date.min, date.sec).strftime("%B %e, %Y %H:%M:%S")
|
||||
else
|
||||
return date_time.strftime("%B %e, %Y")
|
||||
DateTime.new(date.year, date.mon, date.day).strftime("%B %e, %Y")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,17 +2,10 @@
|
|||
|
||||
<%= categories_menu %>
|
||||
|
||||
<% unless @pages_by_revision.empty? %>
|
||||
<% revision_date = @pages_by_revision.first.revised_at %>
|
||||
<h3><%= format_date(revision_date, include_time = false) %></h3>
|
||||
<% @pages_by_day.keys.sort.reverse.each do |day| %>
|
||||
<h3><%= format_date(day, include_time = false) %></h3>
|
||||
<ul>
|
||||
<% for page in @pages_by_revision %>
|
||||
<% if page.revised_at < revision_date %>
|
||||
<% revision_date = page.revised_at %>
|
||||
</ul>
|
||||
<h3><%= format_date(revision_date, include_time = false) %></h3>
|
||||
<ul>
|
||||
<% end %>
|
||||
<% for page in @pages_by_day[day] %>
|
||||
<li>
|
||||
<%= link_to_existing_page page %>
|
||||
<div class="byline" style="margin-bottom: 0px">
|
||||
|
@ -24,4 +17,3 @@
|
|||
<% end %>
|
||||
</ul>
|
||||
<% end %>
|
||||
|
|
@ -220,7 +220,9 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
assert_equal ['animals', 'trees'], r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word),
|
||||
@oak, pages(:smart_engine), pages(:that_way)],
|
||||
r.template_objects['pages_in_category']
|
||||
end
|
||||
|
||||
|
||||
|
@ -298,7 +300,19 @@ class WikiControllerTest < Test::Unit::TestCase
|
|||
|
||||
assert_equal %w(animals trees), r.template_objects['categories']
|
||||
assert_nil r.template_objects['category']
|
||||
assert_equal [@elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word), @oak, pages(:smart_engine), pages(:that_way)], r.template_objects['pages_in_category']
|
||||
all_pages = @elephant, pages(:first_page), @home, pages(:my_way), pages(:no_wiki_word),
|
||||
@oak, pages(:smart_engine), pages(:that_way)
|
||||
assert_equal all_pages, r.template_objects['pages_in_category']
|
||||
|
||||
pages_by_day = r.template_objects['pages_by_day']
|
||||
assert_not_nil pages_by_day
|
||||
pages_by_day_size = pages_by_day.keys.inject(0) { |sum, day| sum + pages_by_day[day].size }
|
||||
assert_equal all_pages.size, pages_by_day_size
|
||||
all_pages.each do |page|
|
||||
day = Date.new(page.revised_at.year, page.revised_at.month, page.revised_at.day)
|
||||
assert pages_by_day[day].include?(page)
|
||||
end
|
||||
|
||||
assert_equal 'the web', r.template_objects['set_name']
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue