public
Rubygem
Fork of mislav/will_paginate
Description: Most awesome pagination solution for Rails
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/chriseppstein/will_paginate.git
Search Repo:
allow renderer to be a LinkRenderer instance or a class and make it easier 
to override rendering a link.
chriseppstein (author)
Mon Apr 28 19:51:54 -0700 2008
commit  84313aa4ec6d354de94d5d78ab78fbc52d3f7c17
tree    0afb3fff63d1704f1d32293f8b06ccd09005352a
parent  54bc63e86635a7b44539a2a550b726d1e4353462
...
92
93
94
95
96
 
 
 
 
 
 
 
 
 
 
 
97
98
99
...
166
167
168
 
 
 
169
170
171
172
173
...
255
256
257
258
 
259
260
 
261
262
 
 
 
 
 
 
 
 
 
263
264
265
...
92
93
94
 
 
95
96
97
98
99
100
101
102
103
104
105
106
107
108
...
175
176
177
178
179
180
181
182
183
184
185
...
267
268
269
 
270
271
 
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
0
@@ -92,8 +92,17 @@
0
       
0
       options = options.symbolize_keys.reverse_merge WillPaginate::ViewHelpers.pagination_options
0
       # create the renderer instance
0
- renderer_class = options[:renderer].to_s.constantize
0
- renderer = renderer_class.new collection, options, self
0
+ renderer = case options[:renderer]
0
+ when String, Class
0
+ renderer_class = options[:renderer].to_s.constantize
0
+ renderer_class.new collection, options, self
0
+ else
0
+ returning(options[:renderer]) do |r|
0
+ r.collection = collection
0
+ r.options = options
0
+ r.template = self
0
+ end
0
+ end
0
       # render HTML for pagination
0
       renderer.to_html
0
     end
0
@@ -166,6 +175,9 @@
0
   # This class does the heavy lifting of actually building the pagination
0
   # links. It is used by +will_paginate+ helper internally.
0
   class LinkRenderer
0
+
0
+ attr_accessor :collection, :options, :template
0
+
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
0
0
@@ -255,11 +267,20 @@
0
       classnames = Array[*span_class]
0
       
0
       if page and page != current_page
0
- @template.link_to text, url_for(page), :rel => rel_value(page), :class => classnames[1]
0
+ page_link page, text, :rel => rel_value(page), :class => classnames[1]
0
       else
0
- @template.content_tag :span, text, :class => classnames.join(' ')
0
+ page_span page, text, :class => classnames.join(' ')
0
       end
0
     end
0
+
0
+ def page_link(page, text, attributes = {})
0
+ @template.link_to text, url_for(page), attributes
0
+ end
0
+
0
+ def page_span(page, text, attributes = {})
0
+ @template.content_tag :span, text, attributes
0
+ end
0
+
0
 
0
     # Returns URL params for +page_link_or_span+, taking the current GET params
0
     # and <tt>:params</tt> option into account.

Comments

    No one has commented yet.