Last active
December 18, 2015 12:48
-
-
Save phildionne/5785087 to your computer and use it in GitHub Desktop.
WillPaginate link renderer for Twitter Bootstrap. Use in Sinatra/Padrino.
This file contains 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
module WillPaginate | |
module ViewHelpers | |
# WillPaginate link renderer for Twitter Bootstrap | |
class BoostrapLinkRenderer < WillPaginate::Sinatra::LinkRenderer | |
protected | |
def page_number(page) | |
unless page == current_page | |
tag(:li, link(page, page, :rel => rel_value(page))) | |
else | |
tag(:li, link(page, '#'), :class => 'active') | |
end | |
end | |
def next_page | |
num = @collection.current_page < total_pages && @collection.current_page + 1 | |
previous_or_next_page(num, @options[:next_label], 'next') | |
end | |
def previous_page | |
num = @collection.current_page > 1 && @collection.current_page - 1 | |
previous_or_next_page(num, @options[:previous_label], 'previous') | |
end | |
def previous_or_next_page(page, text, classname) | |
if page | |
tag(:li, link(text, page), :class => classname) | |
else | |
tag(:li, link(text, '#'), :class => classname + ' disabled') | |
end | |
end | |
def html_container(html) | |
tag(:ul, html, container_attributes) | |
end | |
end | |
end | |
end |
This file contains 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
<%= will_paginate @collection, renderer: WillPaginate::ViewHelpers::BoostrapLinkRenderer %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment