<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -49,12 +49,13 @@ module WillPaginate
     # * &lt;tt&gt;:param_name&lt;/tt&gt; -- parameter name for page number in URLs (default: &lt;tt&gt;:page&lt;/tt&gt;)
     # * &lt;tt&gt;:params&lt;/tt&gt; -- additional parameters when generating pagination links
     #   (eg. &lt;tt&gt;:controller =&gt; &quot;foo&quot;, :action =&gt; nil&lt;/tt&gt;)
-    # * &lt;tt&gt;:renderer&lt;/tt&gt; -- class name of the link renderer (default: WillPaginate::LinkRenderer)
+    # * &lt;tt&gt;:renderer&lt;/tt&gt; -- class name, class or instance of a link renderer (default:
+    #   &lt;tt&gt;WillPaginate::LinkRenderer&lt;/tt&gt;)
     # * &lt;tt&gt;:page_links&lt;/tt&gt; -- when false, only previous/next links are rendered (default: true)
     # * &lt;tt&gt;:container&lt;/tt&gt; -- toggles rendering of the DIV container for pagination links, set to
     #   false only when you are rendering your own pagination markup (default: true)
-    # * &lt;tt&gt;:id&lt;/tt&gt; -- HTML ID for the container (default: nil). Pass +true+ to have the ID automatically
-    #   generated from the class name of objects in collection: for example, paginating
+    # * &lt;tt&gt;:id&lt;/tt&gt; -- HTML ID for the container (default: nil). Pass +true+ to have the ID
+    #   automatically generated from the class name of objects in collection: for example, paginating
     #   ArticleComment models would yield an ID of &quot;article_comments_pagination&quot;.
     #
     # All options beside listed ones are passed as HTML attributes to the container
@@ -91,19 +92,18 @@ module WillPaginate
       return nil unless WillPaginate::ViewHelpers.total_pages_for_collection(collection) &gt; 1
       
       options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
-      # create the renderer instance
+      
+      # get the renderer instance
       renderer = case options[:renderer]
-      when String, Class
-        renderer_class = options[:renderer].to_s.constantize
-        renderer_class.new collection, options, self
+      when String
+        options[:renderer].to_s.constantize.new
+      when Class
+        options[:renderer].new
       else
-        returning(options[:renderer]) do |r|
-          r.collection = collection
-          r.options = options
-          r.template = self
-        end
+        options[:renderer]
       end
       # render HTML for pagination
+      renderer.prepare collection, options, self
       renderer.to_html
     end
     
@@ -179,16 +179,26 @@ module WillPaginate
   # links. It is used by +will_paginate+ helper internally.
   class LinkRenderer
 
-    attr_accessor :collection, :options, :template
-
+    # The gap in page links is represented by:
+    #
+    #   &lt;span class=&quot;gap&quot;&gt;&amp;hellip;&lt;/span&gt;
+    attr_accessor :gap_marker
+    
+    def initialize
+      @gap_marker = '&lt;span class=&quot;gap&quot;&gt;&amp;hellip;&lt;/span&gt;'
+    end
+    
     # * +collection+ is a WillPaginate::Collection instance or any other object
     #   that conforms to that API
     # * +options+ are forwarded from +will_paginate+ view helper
     # * +template+ is the reference to the template being rendered
-    def initialize(collection, options, template)
+    def prepare(collection, options, template)
       @collection = collection
       @options    = options
       @template   = template
+
+      # reset values in case we're re-using this instance
+      @total_pages = @param_name = @url_string = nil
     end
 
     # Process it! This method returns the complete HTML string which contains
@@ -197,8 +207,8 @@ module WillPaginate
     def to_html
       links = @options[:page_links] ? windowed_links : []
       # previous/next buttons
-      links.unshift page_link_or_span(@collection.previous_page, %w(disabled prev_page), @options[:prev_label])
-      links.push    page_link_or_span(@collection.next_page,     %w(disabled next_page), @options[:next_label])
+      links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:prev_label])
+      links.push    page_link_or_span(@collection.next_page,     'disabled next_page', @options[:next_label])
       
       html = links.join(@options[:separator])
       @options[:container] ? @template.content_tag(:div, html, html_attributes) : html
@@ -218,13 +228,6 @@ module WillPaginate
     
   protected
 
-    # The gap in page links is represented by:
-    #
-    #   &lt;span class=&quot;gap&quot;&gt;&amp;hellip;&lt;/span&gt;
-    def gap_marker
-      '&lt;span class=&quot;gap&quot;&gt;&amp;hellip;&lt;/span&gt;'
-    end
-    
     # Collects link items for visible page numbers.
     def windowed_links
       prev = nil
@@ -267,12 +270,12 @@ module WillPaginate
     
     def page_link_or_span(page, span_class, text = nil)
       text ||= page.to_s
-      classnames = Array[*span_class]
       
       if page and page != current_page
-        page_link page, text, :rel =&gt; rel_value(page), :class =&gt; classnames[1]
+        classnames = span_class &amp;&amp; span_class.index(' ') &amp;&amp; span_class.split(' ', 2).last
+        page_link page, text, :rel =&gt; rel_value(page), :class =&gt; classnames
       else
-        page_span page, text, :class =&gt; classnames.join(' ')
+        page_span page, text, :class =&gt; span_class
       end
     end
 
@@ -284,7 +287,6 @@ module WillPaginate
       @template.content_tag :span, text, attributes
     end
 
-
     # Returns URL params for +page_link_or_span+, taking the current GET params
     # and &lt;tt&gt;:params&lt;/tt&gt; option into account.
     def url_for(page)</diff>
      <filename>lib/will_paginate/view_helpers.rb</filename>
    </modified>
    <modified>
      <diff>@@ -2,13 +2,9 @@ require 'helper'
 require 'lib/view_test_process'
 
 class AdditionalLinkAttributesRenderer &lt; WillPaginate::LinkRenderer
-  def initialize(*arguments)
-    if arguments.size == 3
-      super(*arguments)
-      @additional_link_attributes = {:default =&gt; 'true'}
-    else
-      @additional_link_attributes = arguments.extract_options!
-    end
+  def initialize(link_attributes = nil)
+    super()
+    @additional_link_attributes = link_attributes || { :default =&gt; 'true' }
   end
 
   def page_link(page, text, attributes = {})
@@ -16,7 +12,6 @@ class AdditionalLinkAttributesRenderer &lt; WillPaginate::LinkRenderer
   end
 end
 
-
 class ViewTest &lt; WillPaginate::ViewTestCase
   
   ## basic pagination ##
@@ -60,14 +55,22 @@ class ViewTest &lt; WillPaginate::ViewTestCase
   end
 
   def test_will_paginate_using_renderer_class
-    paginate({},:renderer =&gt; AdditionalLinkAttributesRenderer) do
-      assert_select 'a[default~=true]'
+    paginate({}, :renderer =&gt; AdditionalLinkAttributesRenderer) do
+      assert_select 'a[default=true]', 3
     end
   end
 
   def test_will_paginate_using_renderer_instance
-    paginate({},:renderer =&gt; AdditionalLinkAttributesRenderer.new(:title =&gt; 'rendered')) do
-      assert_select 'a[title=rendered]'
+    renderer = WillPaginate::LinkRenderer.new
+    renderer.gap_marker = '&lt;span class=&quot;my-gap&quot;&gt;~~&lt;/span&gt;'
+    
+    paginate({ :per_page =&gt; 2 }, :inner_window =&gt; 0, :outer_window =&gt; 0, :renderer =&gt; renderer) do
+      assert_select 'span.my-gap', '~~'
+    end
+    
+    renderer = AdditionalLinkAttributesRenderer.new(:title =&gt; 'rendered')
+    paginate({}, :renderer =&gt; renderer) do
+      assert_select 'a[title=rendered]', 3
     end
   end
 </diff>
      <filename>test/view_test.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>5586e8ea4b99394baa4a60539e766aa9d2a8a8b6</id>
    </parent>
  </parents>
  <author>
    <name>Mislav Marohni&#263;</name>
    <email>mislav.marohnic@gmail.com</email>
  </author>
  <url>http://github.com/mislav/will_paginate/commit/2e45f01bd13fae007412896335d266983e11ec03</url>
  <id>2e45f01bd13fae007412896335d266983e11ec03</id>
  <committed-date>2008-04-29T12:59:28-07:00</committed-date>
  <authored-date>2008-04-29T12:59:28-07:00</authored-date>
  <message>CHANGED LinkRenderer to receive collection, options and reference to view template NOT in constructor, but with the #prepare method.
This is a step towards supporting passing of LinkRenderer (or subclass) instances that may be preconfigured in some way.</message>
  <tree>a5d917a1ff32f6f5e558bf0480d2f696f14e4e9b</tree>
  <committer>
    <name>Mislav Marohni&#263;</name>
    <email>mislav.marohnic@gmail.com</email>
  </committer>
</commit>
