0
@@ -49,12 +49,13 @@ module WillPaginate
0
# * <tt>:param_name</tt> -- parameter name for page number in URLs (default: <tt>:page</tt>)
0
# * <tt>:params</tt> -- additional parameters when generating pagination links
0
# (eg. <tt>:controller => "foo", :action => nil</tt>)
0
- # * <tt>:renderer</tt> -- class name of the link renderer (default: WillPaginate::LinkRenderer)
0
+ # * <tt>:renderer</tt> -- class name, class or instance of a link renderer (default:
0
+ # <tt>WillPaginate::LinkRenderer</tt>)
0
# * <tt>:page_links</tt> -- when false, only previous/next links are rendered (default: true)
0
# * <tt>:container</tt> -- toggles rendering of the DIV container for pagination links, set to
0
# false only when you are rendering your own pagination markup (default: true)
0
- # * <tt>:id</tt> -- HTML ID for the container (default: nil). Pass +true+ to have the ID automatically
0
- # generated from the class name of objects in collection: for example, paginating
0
+ # * <tt>:id</tt> -- HTML ID for the container (default: nil). Pass +true+ to have the ID
0
+ # automatically generated from the class name of objects in collection: for example, paginating
0
# ArticleComment models would yield an ID of "article_comments_pagination".
0
# All options beside listed ones are passed as HTML attributes to the container
0
@@ -91,19 +92,18 @@ module WillPaginate
0
return nil unless WillPaginate::ViewHelpers.total_pages_for_collection(collection) > 1
0
options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
0
- # create the renderer instance
0
+ # get the renderer instance
0
renderer = case options[:renderer]
0
- renderer_class = options[:renderer].to_s.constantize
0
- renderer_class.new collection, options, self
0
+ options[:renderer].to_s.constantize.new
0
+ options[:renderer].new
0
- returning(options[:renderer]) do |r|
0
- r.collection = collection
0
# render HTML for pagination
0
+ renderer.prepare collection, options, self
0
@@ -179,16 +179,26 @@ module WillPaginate
0
# links. It is used by +will_paginate+ helper internally.
0
- attr_accessor :collection, :options, :template
0
+ # The gap in page links is represented by:
0
+ # <span class="gap">…</span>
0
+ attr_accessor :gap_marker
0
+ @gap_marker = '<span class="gap">…</span>'
0
# * +collection+ is a WillPaginate::Collection instance or any other object
0
# that conforms to that API
0
# * +options+ are forwarded from +will_paginate+ view helper
0
# * +template+ is the reference to the template being rendered
0
- def initialize(collection, options, template)
0
+ def prepare(collection, options, template)
0
@collection = collection
0
+ # reset values in case we're re-using this instance
0
+ @total_pages = @param_name = @url_string = nil
0
# Process it! This method returns the complete HTML string which contains
0
@@ -197,8 +207,8 @@ module WillPaginate
0
links = @options[:page_links] ? windowed_links : []
0
# previous/next buttons
0
- links.unshift page_link_or_span(@collection.previous_page, %w(disabled prev_page), @options[:prev_label])
0
- links.push page_link_or_span(@collection.next_page, %w(disabled next_page), @options[:next_label])
0
+ links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:prev_label])
0
+ links.push page_link_or_span(@collection.next_page, 'disabled next_page', @options[:next_label])
0
html = links.join(@options[:separator])
0
@options[:container] ? @template.content_tag(:div, html, html_attributes) : html
0
@@ -218,13 +228,6 @@ module WillPaginate
0
- # The gap in page links is represented by:
0
- # <span class="gap">…</span>
0
- '<span class="gap">…</span>'
0
# Collects link items for visible page numbers.
0
@@ -267,12 +270,12 @@ module WillPaginate
0
def page_link_or_span(page, span_class, text = nil)
0
- classnames = Array[*span_class]
0
if page and page != current_page
0
- page_link page, text, :rel => rel_value(page), :class => classnames[1]
0
+ classnames = span_class && span_class.index(' ') && span_class.split(' ', 2).last
0
+ page_link page, text, :rel => rel_value(page), :class => classnames
0
- page_span page, text, :class => classnames.join(' ')
0
+ page_span page, text, :class => span_class
0
@@ -284,7 +287,6 @@ module WillPaginate
0
@template.content_tag :span, text, attributes
0
# Returns URL params for +page_link_or_span+, taking the current GET params
0
# and <tt>:params</tt> option into account.
Comments
very nice. Thank you for taking my change to the next level.