Skip to content

Instantly share code, notes, and snippets.

@ashaw
Created December 31, 2009 13:44
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 ashaw/266732 to your computer and use it in GitHub Desktop.
Save ashaw/266732 to your computer and use it in GitHub Desktop.
require 'will_paginate'
# patch WillPaginate to allow reverse pagination
# only do this if you're not showing the page numbers themselves
# pass option :reverse => true to reverse paginate, and don't forget to pass custom labels
class WillPaginate::LinkRenderer
def html_attributes
return @html_attributes if @html_attributes
@html_attributes = @options.except *(WillPaginate::ViewHelpers.pagination_options.keys - [:class])
@html_attributes[:class] += " #{total_pages}"
@html_attributes[:class] += " no_reverse" unless @options[:reverse]
# pagination of Post models will have the ID of "posts_pagination"
if @options[:container] and @options[:id] === true
@html_attributes[:id] = @collection.first.class.name.underscore.pluralize + '_pagination'
end
@html_attributes
end
def to_html
links = @options[:page_links] ? windowed_links : []
# previous/next buttons
if @options[:reverse] === true
links.push page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
links.unshift page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
else
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])
end
html = links.join(@options[:separator])
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment