Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change markup to use nav; also much more complete

  • Loading branch information...
commit 8837a3004db7664738482729fd00bdc382c71267 1 parent 3e94e46
@cyx cyx authored
View
11 lib/pagination/collection.rb
@@ -73,6 +73,10 @@ def render?
def each(&block)
collection.each(&block)
end
+
+ def total_pages
+ (total / per_page.to_f).ceil
+ end
protected
def collection
@@ -80,12 +84,7 @@ def collection
end
def pages
- 1..last_page
- end
-
- def last_page
- (total / per_page.to_f).ceil
+ 1..total_pages
end
-
end
end
View
10 test/test_pagination_template.rb
@@ -33,23 +33,23 @@ def doc
should "have a ul > li.next-link with page=2" do
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
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
should "display pages 2 to 5 as links" do
(2..5).each do |page|
assert_equal 1,
- doc.search(%(div.pagination > ul > li >
+ doc.search(%(nav.pagination > nav.page-numbers > ul > li >
a[href="?page=#{page}"])).length
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
end
end
View
33 views/paginate.haml
@@ -1,19 +1,24 @@
- if items.render?
- %div.pagination
+ %nav.pagination
- if items.prev_page
- %a.prev-link{:href => ("?page=%s" % items.prev_page)}
+ %a.prev-link{:href => ("?page=%d" % items.prev_page)}
%span ← Previous
-
- %ul
- - items.displayed_pages.each do |page|
- - if items.current?(page)
- %li.active
- %span= page
- - else
- %li
- %a{:href => ("?page=%s" % page)}= page
-
+ %nav.page-numbers
+ %span.current-page
+ %span
+ %strong
+ Page
+ = items.page
+ of
+ = items.total_pages
+ %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
- %a.next-link{:href => ("?page=%s" % items.next_page)}
+ %a.next-link{:href => ("?page=%d" % items.next_page)}
%span Next →
-
Please sign in to comment.
Something went wrong with that request. Please try again.