forked from karmi/marley
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Redpath
committed
Jan 22, 2009
1 parent
6eb0100
commit 3817dcd
Showing
5 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Marley | ||
|
||
class Archive | ||
def initialize(posts) | ||
@posts = posts | ||
end | ||
|
||
def posts_indexed_by_month_and_year | ||
@posts.inject({}) do |index, post| | ||
(index[post.month_and_year] ||= []) << post | ||
index | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require File.join(File.dirname(__FILE__), 'test_helper') | ||
require 'archive' | ||
require 'post' | ||
|
||
class ArchiveTest < Test::Unit::TestCase | ||
|
||
context "An archive of posts" do | ||
setup do | ||
@post_one = Marley::Post.new('post-one', 'body', {:published_on => '05 Jan 2009'}) | ||
@post_two = Marley::Post.new('post-two', 'body', {:published_on => '01 Jan 2009'}) | ||
@post_three = Marley::Post.new('post-thr', 'body', {:published_on => '14 Dec 2008'}) | ||
@post_four = Marley::Post.new('post-for', 'body', {:published_on => '22 Nov 2008'}) | ||
|
||
@archive = Marley::Archive.new([@post_one, @post_two, @post_three, @post_four]) | ||
end | ||
|
||
should "return posts as a hash indexed by month and year" do | ||
expected = { | ||
[1, 2009] => [@post_one, @post_two], | ||
[12, 2008] => [@post_three], | ||
[11, 2008] => [@post_four] | ||
} | ||
assert_equal expected, @archive.posts_indexed_by_month_and_year | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<% @posts.map { |post| post.month_and_year }.uniq.each do |(month, year)| %> | ||
<h2><%= Date::MONTHNAMES[month] %> <%= year %></h2> | ||
|
||
<ul> | ||
<% @posts_index[[month, year]].each do |post| %> | ||
<li><a href="<%= permalink(post) %>"><%= post.title %></a></li> | ||
<% end %> | ||
</ul> | ||
<% end %> |