Skip to content

Instantly share code, notes, and snippets.

@sharnik
Created October 29, 2008 09:10
Show Gist options
  • Save sharnik/20660 to your computer and use it in GitHub Desktop.
Save sharnik/20660 to your computer and use it in GitHub Desktop.
class PaginationListLinkRenderer < WillPaginate::LinkRenderer
def to_html
links = @options[:page_links] ? windowed_links : []
html = links.join(@options[:separator])
@options[:container] ? @template.content_tag(:ul, html, html_attributes) : html
end
protected
def windowed_links
visible_page_numbers.map { |n| page_link_or_span(n, (n == current_page ? 'select' : nil)) }
end
def page_link_or_span(page, span_class, text = nil)
text ||= page.to_s
if page && page != current_page
page_link(page, text, :class => span_class)
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, text, attributes)
end
end
WillPaginate::ViewHelpers.pagination_options[:renderer] = 'PaginationListLinkRenderer'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment