Created
August 25, 2011 09:49
-
-
Save s5ot/1170346 to your computer and use it in GitHub Desktop.
Custom WillPaginate Renderer Class For Bootstrap
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
class BootstrapLinkRenderer < WillPaginate::ActionView::LinkRenderer | |
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 link(text, target, attributes = {}) | |
if target.is_a? Fixnum | |
attributes[:rel] = rel_value(target) | |
target = url(target) | |
end | |
attributes[:href] = target | |
tag(:a, text, attributes) | |
end | |
def html_container(html) | |
tag(:div, tag(:ul, html), container_attributes) | |
end | |
def previous_or_next_page(page, text, classname) | |
classname = case classname | |
when 'previous_page' | |
'prev' | |
when 'next_page' | |
'next' | |
end | |
if page | |
tag(:li, link(text, page), :class => classname) | |
else | |
tag(:li, link(text, "#"), :class => classname + ' disabled') | |
end | |
end | |
end | |
WillPaginate::ViewHelpers.pagination_options[:renderer] = 'BootstrapLinkRenderer' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment