Skip to content

Instantly share code, notes, and snippets.

@spacegauch0
Created February 4, 2013 14:31
Show Gist options
  • Select an option

  • Save spacegauch0/4707023 to your computer and use it in GitHub Desktop.

Select an option

Save spacegauch0/4707023 to your computer and use it in GitHub Desktop.
Gmail pagination style with Will Paginate
# 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
@spacegauch0
Copy link
Author

Google Bootstrap + Font Awesome + Will Paginate = Gmail pagination style

Example:
Example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment