public
Rubygem
Description: Most awesome pagination solution for Ruby
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/mislav/will_paginate.git
rethink the page URL construction mechanizm to be more bulletproof because 
people want to use custom route params for page
mislav (author)
Wed Apr 23 14:55:38 -0700 2008
commit  1fb293e6d8a2567812af869516b75285cdc3d17f
tree    36c5cfa4ec28b3071cb85c88248d8c5956b2720f
parent  4368fe36f960738398462257dca1c013916c7977
...
270
271
272
273
 
274
275
276
277
278
279
 
280
281
282
283
284
 
 
 
 
 
 
 
 
 
 
 
 
 
 
285
 
286
287
288
...
270
271
272
 
273
274
275
276
277
278
 
279
280
281
282
 
 
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
0
@@ -270,19 +270,32 @@ module WillPaginate
0
         stringified_merge @url_params, @template.params if @template.request.get?
0
         stringified_merge @url_params, @options[:params] if @options[:params]
0
         
0
- if param_name.index(/[^\w-]/)
0
+ if complex = param_name.index(/[^\w-]/)
0
           page_param = (defined?(CGIMethods) ? CGIMethods : ActionController::AbstractRequest).
0
             parse_query_parameters("#{param_name}=#{page}")
0
           
0
           stringified_merge @url_params, page_param
0
         else
0
- @url_params[param_name] = page
0
+ @url_params[param_name] = 1
0
         end
0
 
0
         url = @template.url_for(@url_params)
0
- @url_string = url.sub(%r!([?&/]#{CGI.escape param_name}[=/])#{page}!, '\1@')
0
- return url
0
+
0
+ if complex
0
+ @url_string = url.sub(%r!([?&]#{CGI.escape param_name}=)#{page}!, '\1@')
0
+ return url
0
+ else
0
+ @url_string = url
0
+ @url_params[param_name] = 2
0
+ @template.url_for(@url_params).split(//).each_with_index do |char, i|
0
+ if char == '2' and url[i, 1] == '1'
0
+ @url_string[i] = '@'
0
+ break
0
+ end
0
+ end
0
+ end
0
       end
0
+ # finally!
0
       @url_string.sub '@', page.to_s
0
     end
0
 
...
6
7
8
 
9
10
11
...
6
7
8
9
10
11
12
0
@@ -6,6 +6,7 @@ WillPaginate.enable_actionpack
0
 
0
 ActionController::Routing::Routes.draw do |map|
0
   map.connect 'dummy/page/:page', :controller => 'dummy'
0
+ map.connect 'dummy/dots/page.:page', :controller => 'dummy', :action => 'dots'
0
   map.connect ':controller/:action/:id'
0
 end
0
 
...
234
235
236
 
 
 
 
 
 
 
 
 
237
238
239
...
336
337
338
339
 
340
341
342
...
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
345
346
347
 
348
349
350
351
0
@@ -234,6 +234,15 @@ class ViewTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ def test_custom_routing_page_param_with_dot_separator
0
+ @request.symbolized_path_parameters.update :controller => 'dummy', :action => 'dots'
0
+ paginate :per_page => 2 do
0
+ assert_select 'a[href]', 6 do |links|
0
+ assert_links_match %r{/page\.(\d+)$}, links, [2, 3, 4, 5, 6, 2]
0
+ end
0
+ end
0
+ end
0
+
0
   ## internal hardcore stuff ##
0
 
0
   class LegacyCollection < WillPaginate::Collection
0
@@ -336,7 +345,7 @@ class ViewTest < Test::Unit::TestCase
0
         end
0
       end
0
 
0
- assert_equal pages, numbers, "page numbers don't match" if numbers
0
+ assert_equal numbers, pages, "page numbers don't match" if numbers
0
     end
0
 
0
     def assert_no_links_match pattern

Comments

    No one has commented yet.