Skip to content

Instantly share code, notes, and snippets.

@eboskma
Created October 21, 2013 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eboskma/7090351 to your computer and use it in GitHub Desktop.
Save eboskma/7090351 to your computer and use it in GitHub Desktop.
Bootstrap pager renderer for will_paginate
class BootstrapPagerRenderer < WillPaginate::ActionView::LinkRenderer
protected
def gap
text = @template.will_paginate_translate(:page_gap) { "&hellip;" }
%{<li class="disabled"><a>#{text}</a></li>}
end
def next_page
num = @collection.current_page < @collection.total_pages && @collection.current_page + 1
css_class = @options[:reverse_links] ? 'previous' : 'next'
previous_or_next_page(num, @options[:next_label], css_class)
end
def previous_page
num = @collection.current_page > 1 && @collection.current_page - 1
css_class = @options[:reverse_links] ? 'next' : 'previous'
previous_or_next_page(num, @options[:previous_label], css_class)
end
def previous_or_next_page(page, text, classname)
if page
link(text, page, :class => classname)
else
link(text, "#", :class => classname + ' disabled')
end
end
def html_container(html)
tag(:ul, html, container_attributes)
end
private
def link(text, target, attributes = {})
if target.is_a? Fixnum
attributes[:rel] = rel_value(target)
target = url(target)
end
unless target == "#"
attributes[:href] = target
end
classname = attributes[:class]
attributes.delete(:classname)
tag(:li, tag(:a, text, attributes), :class => classname)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment