Skip to content

Commit

Permalink
Merge commit 'ujh/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
qrush committed Jun 22, 2009
2 parents 414dfbe + 8379958 commit 606269b
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
27 changes: 25 additions & 2 deletions features/pagination.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,38 @@ Feature: Site pagination
As a blog's user
I want divide the posts in several pages

Scenario: Create pages
Given I have a configuration file with "paginate" set to "1"
Scenario Outline: Paginate with N posts per page
Given I have a configuration file with "paginate" set to "<num>"
And I have a _layouts directory
And I have an "index.html" file that contains "Basic Site"
And I have a _posts directory
And I have the following post:
| title | date | layout | content |
| Wargames | 3/27/2009 | default | The only winning move is not to play. |
| Wargames2 | 4/27/2009 | default | The only winning move is not to play2. |
| Wargames3 | 5/27/2009 | default | The only winning move is not to play2. |
When I run jekyll
Then the _site/page2 directory should exist
And the _site/page2/index.html file should exist

Examples:
| num |
| 1 |
| 2 |

Scenario: Correct liquid paginator replacements
Given I have a configuration file with "paginate" set to "1"
And I have a _layouts directory
And I have an "index.html" file that contains "{{ paginator.page }}"
And I have a _posts directory
And I have the following post:
| title | date | layout | content |
| Wargames | 3/27/2009 | default | The only winning move is not to play. |
| Wargames2 | 4/27/2009 | default | The only winning move is not to play2. |
When I run jekyll
Then the _site/index.html file should exist
And I should see "1" in "_site/index.html"
Then the _site/page2 directory should exist
And the _site/page2/index.html file should exist
And I should see "2" in "_site/page2/index.html"

15 changes: 15 additions & 0 deletions features/site_data.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,18 @@ Feature: Site data
When I run jekyll
Then the _site directory should exist
And I should see "Yuengling" in "_site/index.html"

Scenario: Order Posts by name when on the same date
Given I have a _posts directory
And I have an "index.html" page that contains "{% for post in site.posts %}{{ post.title }}:{{ post.previous.title}},{{ post.next.title}} {% endfor %}"
And I have the following posts:
| title | date | content |
| first | 2/26/2009 | first |
| A | 3/26/2009 | A |
| B | 3/26/2009 | B |
| C | 3/26/2009 | C |
| last | 4/26/2009 | last |
When I run jekyll
Then the _site directory should exist
And I should see "last:C, C:B,last B:A,C A:first,B first:,A" in "_site/index.html"

8 changes: 6 additions & 2 deletions lib/jekyll/post.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def initialize(site, source, dir, name)
end
end

# Spaceship is based on Post#date
# Spaceship is based on Post#date, slug
#
# Returns -1, 0, 1
def <=>(other)
self.date <=> other.date
cmp = self.date <=> other.date
if 0 == cmp
cmp = self.slug <=> other.slug
end
return cmp
end

# Extract information from the post filename
Expand Down
6 changes: 2 additions & 4 deletions lib/jekyll/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,11 @@ def filter_entries(entries)
# "next_page" => <Number> }}
def paginate_posts(file, dir)
all_posts = self.posts.sort { |a,b| b <=> a }
page = Page.new(self, self.source, dir, file)

pages = Pager.calculate_pages(all_posts, self.config['paginate'].to_i)

pages += 1
(1..pages).each do |num_page|
pager = Pager.new(self.config, num_page, all_posts, pages)

page = Page.new(self, self.source, dir, file)
page.render(self.layouts, site_payload.merge({'paginator' => pager.to_hash}))
suffix = "page#{num_page}" if num_page > 1
page.write(self.dest, suffix)
Expand Down

0 comments on commit 606269b

Please sign in to comment.