Created
February 4, 2013 14:31
-
-
Save spacegauch0/4707023 to your computer and use it in GitHub Desktop.
Gmail pagination style with Will Paginate
This file contains hidden or 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
| # config/initializers/gmail_will_paginate.rb | |
| # USAGE: | |
| # <%= will_paginate(@posts, :renderer => WillPaginate::Gmail) %> | |
| module WillPaginate | |
| class Gmail < ::WillPaginate::ActionView::LinkRenderer | |
| def pagination | |
| [:window, :pagination_buttons] | |
| end | |
| protected | |
| def pagination_buttons | |
| next_link = previous_or_next_page(@collection.current_page > 1 && @collection.current_page - 1, tag(:i, '', :class => 'icon-chevron-left'), 'btn btn-mini') | |
| prev_link = previous_or_next_page(@collection.current_page < @collection.total_pages && @collection.current_page + 1, tag(:i, '', :class => 'icon-chevron-right'), 'btn btn-mini') | |
| tag(:div, "#{next_link}#{prev_link}", :class => 'btn-group') | |
| end | |
| def window | |
| total_entries = @collection.total_entries | |
| base = @collection.offset | |
| high = base + @collection.per_page > total_entries ? total_entries : base + @collection.per_page | |
| tag(:span, "#{tag(:strong, base + 1)} - #{tag(:strong, high)} of #{tag(:strong, total_entries)}", :class => 'pagination-meta') | |
| end | |
| end | |
| end |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Google Bootstrap + Font Awesome + Will Paginate = Gmail pagination style
Example:
