Skip to content

Commit

Permalink
Change markup to use nav; also much more complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyril David committed Jun 10, 2010
1 parent 3e94e46 commit 8837a30
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
11 changes: 5 additions & 6 deletions lib/pagination/collection.rb
Expand Up @@ -73,19 +73,18 @@ def render?
def each(&block) def each(&block)
collection.each(&block) collection.each(&block)
end end

def total_pages
(total / per_page.to_f).ceil
end


protected protected
def collection def collection
raise Unimplemented, "You must implement collection" raise Unimplemented, "You must implement collection"
end end


def pages def pages
1..last_page 1..total_pages
end

def last_page
(total / per_page.to_f).ceil
end end

end end
end end
10 changes: 5 additions & 5 deletions test/test_pagination_template.rb
Expand Up @@ -33,23 +33,23 @@ def doc


should "have a ul > li.next-link with page=2" do should "have a ul > li.next-link with page=2" do
assert_equal 1, assert_equal 1,
doc.search('div.pagination > a.next-link[href="?page=2"]').length doc.search('nav.pagination > a.next-link[href="?page=2"]').length
end end


should "display the first page as the current page" do should "display the first page as the current page" do
assert_equal 1, doc.search('div.pagination > ul > li > span').length assert_equal 1, doc.search('nav.pagination > nav.page-numbers > ul > li > span').length


assert_equal '1', doc.search('div.pagination > ul > li > span').text assert_equal '1', doc.search('nav.pagination > nav.page-numbers > ul > li > span').text
end end


should "display pages 2 to 5 as links" do should "display pages 2 to 5 as links" do
(2..5).each do |page| (2..5).each do |page|
assert_equal 1, assert_equal 1,
doc.search(%(div.pagination > ul > li > doc.search(%(nav.pagination > nav.page-numbers > ul > li >
a[href="?page=#{page}"])).length a[href="?page=#{page}"])).length


assert_equal page.to_s, assert_equal page.to_s,
doc.search(%(div.pagination > ul > li > doc.search(%(nav.pagination > nav.page-numbers > ul > li >
a[href="?page=#{page}"])).text a[href="?page=#{page}"])).text
end end
end end
Expand Down
33 changes: 19 additions & 14 deletions views/paginate.haml
@@ -1,19 +1,24 @@
- if items.render? - if items.render?
%div.pagination %nav.pagination
- if items.prev_page - if items.prev_page
%a.prev-link{:href => ("?page=%s" % items.prev_page)} %a.prev-link{:href => ("?page=%d" % items.prev_page)}
%span ← Previous %span ← Previous

%nav.page-numbers
%ul %span.current-page
- items.displayed_pages.each do |page| %span
- if items.current?(page) %strong
%li.active Page
%span= page = items.page
- else of
%li = items.total_pages
%a{:href => ("?page=%s" % page)}= page %ul

- items.displayed_pages.each do |page|
- if items.current?(page)
%li.active
%span= page
- else
%li
%a{:href => ("?page=%d" % page)}= page
- if items.next_page - if items.next_page
%a.next-link{:href => ("?page=%s" % items.next_page)} %a.next-link{:href => ("?page=%d" % items.next_page)}
%span Next → %span Next →

0 comments on commit 8837a30

Please sign in to comment.