public
Rubygem
Fork of mislav/will_paginate
Description: Most awesome pagination solution for Rails/Merb
Homepage: http://github.com/mislav/will_paginate/wikis
Clone URL: git://github.com/myobie/will_paginate.git
another fix with pagination and custom routing: account for that the first 
page number may be implicit
mislav (author)
Sun May 04 11:42:22 -0700 2008
commit  802d8301923e570bc43ae61320fd02b223e22e8f
tree    b04272a83f7b6590d8b366d1b926bb11663b7a03
parent  43abd3b63d7040e77e48b356da6ebe4fd5620a65
...
297
298
299
300
 
 
301
302
303
...
309
310
311
312
 
313
314
315
 
316
317
318
319
320
321
322
 
323
324
 
325
326
327
...
297
298
299
 
300
301
302
303
304
...
310
311
312
 
313
314
315
316
317
318
319
320
321
322
323
 
324
325
 
326
327
328
329
0
@@ -297,7 +297,8 @@ module WillPaginate
0
     # Returns URL params for +page_link_or_span+, taking the current GET params
0
     # and <tt>:params</tt> option into account.
0
     def url_for(page)
0
- unless @url_string
0
+ page_one = page == 1
0
+ unless @url_string and !page_one
0
         @url_params = { :escape => false }
0
         # page links should preserve GET parameters
0
         stringified_merge @url_params, @template.params if @template.request.get?
0
@@ -309,19 +310,20 @@ module WillPaginate
0
           
0
           stringified_merge @url_params, page_param
0
         else
0
- @url_params[param_name] = 1
0
+ @url_params[param_name] = page_one ? 1 : 2
0
         end
0
 
0
         url = @template.url_for(@url_params)
0
+ return url if page_one
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
+ @url_params[param_name] = 3
0
           @template.url_for(@url_params).split(//).each_with_index do |char, i|
0
- if char == '2' and url[i, 1] == '1'
0
+ if char == '3' and url[i, 1] == '2'
0
               @url_string[i] = '@'
0
               break
0
             end
...
7
8
9
 
 
 
 
10
11
12
...
79
80
81
82
 
83
84
85
...
7
8
9
10
11
12
13
14
15
16
...
83
84
85
 
86
87
88
89
0
@@ -7,6 +7,10 @@ WillPaginate.enable_actionpack
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 'ibocorp/:page', :controller => 'ibocorp',
0
+ :requirements => { :page => /\d+/ },
0
+ :defaults => { :page => 1 }
0
+
0
   map.connect ':controller/:action/:id'
0
 end
0
 
0
@@ -79,7 +83,7 @@ class WillPaginate::ViewTestCase < Test::Unit::TestCase
0
         assert_match pattern, el['href']
0
         if numbers
0
           el['href'] =~ pattern
0
- pages << $1.to_i
0
+ pages << ($1.nil?? nil : $1.to_i)
0
         end
0
       end
0
 
...
287
288
289
 
 
 
 
 
 
 
 
 
290
291
292
...
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
0
@@ -287,6 +287,15 @@ class ViewTest < WillPaginate::ViewTestCase
0
     end
0
   end
0
 
0
+ def test_custom_routing_with_first_page_hidden
0
+ @request.symbolized_path_parameters.update :controller => 'ibocorp', :action => nil
0
+ paginate :page => 2, :per_page => 2 do
0
+ assert_select 'a[href]', 7 do |links|
0
+ assert_links_match %r{/ibocorp(?:/(\d+))?$}, links, [nil, nil, 3, 4, 5, 6, 3]
0
+ end
0
+ end
0
+ end
0
+
0
   ## internal hardcore stuff ##
0
 
0
   class LegacyCollection < WillPaginate::Collection

Comments

    No one has commented yet.