Skip to content

Commit

Permalink
Merge commit 'mojombo/master'
Browse files Browse the repository at this point in the history
Conflicts:
	lib/jekyll/post.rb
	lib/jekyll/site.rb
  • Loading branch information
henrik committed Apr 23, 2009
2 parents 60683ea + dd268fa commit 5f7bd00
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 5 deletions.
14 changes: 14 additions & 0 deletions features/post_data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,17 @@ Feature: Post data
When I run jekyll
Then the _site directory should exist
And I should see "Post author: Darth Vader" in "_site/2009/03/27/star-wars.html"

Scenario: Previous and next posts title
Given I have a _posts directory
And I have a _layouts directory
And I have the following posts:
| title | date | layout | author | content |
| Star Wars | 3/27/2009 | ordered | Darth Vader | Luke, I am your father. |
| Some like it hot | 4/27/2009 | ordered | Osgood | Nobody is perfect. |
| Terminator | 5/27/2009 | ordered | Arnold | Sayonara, baby |
And I have a ordered layout that contains "Previous post: {{ page.previous.title }} and next post: {{ page.next.title }}"
When I run jekyll
Then the _site directory should exist
And I should see "next post: Some like it hot" in "_site/2009/03/27/star-wars.html"
And I should see "Previous post: Some like it hot" in "_site/2009/05/27/terminator.html"
21 changes: 21 additions & 0 deletions lib/jekyll/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,33 @@ def to_liquid
"topics" => self.topics,
"categories" => self.categories,
"tags" => self.tags,
"next" => self.next,
"previous" => self.previous,
"content" => self.content }.deep_merge(self.data)
end

def inspect
"<Post: #{self.id}>"
end

def next
pos = self.site.posts.index(self)

if pos && pos < self.site.posts.length-1
self.site.posts[pos+1]
else
nil
end
end

def previous
pos = self.site.posts.index(self)
if pos && pos > 0
self.site.posts[pos-1]
else
nil
end
end
end

end
7 changes: 3 additions & 4 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,14 @@ def read_posts(dir)
end
end

self.posts.sort!

# second pass renders each post now that full site payload is available
self.posts.each do |post|
post.render(self.layouts, site_payload)
end

self.posts.sort!
self.posts.each do |post|
self.collated_posts[post.date.year][post.date.month][post.date.day].unshift(post)
end

self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} }
self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a} }
rescue Errno::ENOENT => e
Expand Down
2 changes: 1 addition & 1 deletion test/test_generated_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class TestGeneratedSite < Test::Unit::TestCase
end

should "render post.content" do
latest_post = Dir[source_dir('_posts', '*')].last
latest_post = Dir[source_dir('_posts', '*')].sort.last
post = Post.new(@site, source_dir, '', File.basename(latest_post))
post.transform
assert @index.include?(post.content)
Expand Down
26 changes: 26 additions & 0 deletions test/test_post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,32 @@ def do_render(post)
end
end

context "when in a site" do
setup do
clear_dest
stub(Jekyll).configuration { Jekyll::DEFAULTS }
@site = Site.new(Jekyll.configuration)
@site.posts = [setup_post('2008-02-02-published.textile'),
setup_post('2009-01-27-categories.textile')]
end

should "have next post" do
assert_equal(@site.posts.last, @site.posts.first.next)
end

should "have previous post" do
assert_equal(@site.posts.first, @site.posts.last.previous)
end

should "not have previous post if first" do
assert_equal(nil, @site.posts.first.previous)
end

should "not have next post if last" do
assert_equal(nil, @site.posts.last.next)
end
end

context "initializing posts" do
should "publish when published yaml is no specified" do
post = setup_post("2008-02-02-published.textile")
Expand Down

0 comments on commit 5f7bd00

Please sign in to comment.