Created
April 14, 2012 19:54
-
-
Save corny/2387517 to your computer and use it in GitHub Desktop.
WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap
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
# | |
# WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap | |
# Put this content in in your config/initializers/will_paginate.rb | |
module WillPaginate | |
module ViewHelpers | |
class BootstrapLinkRenderer < LinkRenderer | |
def to_html | |
links = @options[:page_links] ? windowed_links : [] | |
# previous/next buttons | |
links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label]) | |
links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label]) | |
html = links.join(@options[:separator]) | |
html = html.html_safe if html.respond_to? :html_safe | |
html = @template.content_tag(:ul, html) | |
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html | |
end | |
def gap_marker | |
@gap_marker ||= begin | |
text = @template.will_paginate_translate(:page_gap) { '…' } | |
@template.content_tag :li, @template.link_to(text, '#'), :class => 'disabled' | |
end | |
end | |
protected | |
def page_link_or_span(page, span_class, text = nil) | |
text ||= page.to_s | |
text = text.html_safe if text.respond_to? :html_safe | |
if page and page != current_page | |
classnames = span_class && span_class.index(' ') && span_class.split(' ', 2).last | |
page_link page, text, :rel => rel_value(page), :class => classnames | |
else | |
page_span page, text, :class => span_class | |
end | |
end | |
def page_link(page, text, attributes = {}) | |
@template.content_tag :li, @template.link_to(text, url_for(page), attributes) | |
end | |
def page_span(page, text, attributes = {}) | |
@template.content_tag :li, @template.link_to(text, '#'), :class => 'disabled' | |
end | |
end | |
pagination_options[:renderer] = BootstrapLinkRenderer | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, thank you!