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
Add support for page parameter in custom routes like "/foo/page/2"
mislav (author)
Mon Apr 21 14:21:25 -0700 2008
commit  4d2da56949b66f838d932724ca40bf7f93627b1f
tree    3996261a4283ebe57c1d8a5551d717fe55847853
parent  fb38b838e32b788a1a46b395a177e098d76ffaf9
...
 
 
 
 
 
 
1
2
3
...
1
2
3
4
5
6
7
8
9
0
@@ -1,3 +1,9 @@
0
+== 2.2.2, released 2008-04-21
0
+
0
+* Add support for page parameter in custom routes like "/foo/page/2"
0
+* Change output of "page_entries_info" on single-page collection and erraneous
0
+ output with empty collection as reported by Tim Chater
0
+
0
 == 2.2.1, released 2008-04-08
0
 
0
 * take less risky path when monkeypatching named_scope; fix that it no longer
...
114
115
116
117
 
118
119
120
...
114
115
116
 
117
118
119
120
0
@@ -114,7 +114,7 @@ contributions or just simply awesome ideas:
0
 Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
0
 Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
0
 van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
0
-Lourens Naudé, Rick Olson.
0
+Lourens Naudé, Rick Olson, Russell Norris.
0
 
0
 
0
 == Usable pagination in the UI
...
280
281
282
283
 
284
285
286
...
280
281
282
 
283
284
285
286
0
@@ -280,7 +280,7 @@ module WillPaginate
0
         end
0
 
0
         url = @template.url_for(@url_params)
0
- @url_string = url.sub(/([?&]#{CGI.escape param_name}=)#{page}/, '\1@')
0
+ @url_string = url.sub(%r!([?&/]#{CGI.escape param_name}[=/])#{page}!, '\1@')
0
         return url
0
       end
0
       @url_string.sub '@', page.to_s
...
5
6
7
 
8
9
10
11
12
13
 
 
14
15
16
 
17
18
19
...
24
25
26
27
28
29
30
31
32
33
...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
...
28
29
30
 
 
 
 
31
32
33
0
@@ -5,15 +5,19 @@ require 'will_paginate'
0
 WillPaginate.enable_actionpack
0
 
0
 ActionController::Routing::Routes.draw do |map|
0
+ map.connect 'dummy/page/:page', :controller => 'dummy'
0
   map.connect ':controller/:action/:id'
0
 end
0
 
0
 ActionController::Base.perform_caching = false
0
 
0
 class DummyRequest
0
+ attr_accessor :symbolized_path_parameters
0
+
0
   def initialize
0
     @get = true
0
     @params = {}
0
+ @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
0
   end
0
   
0
   def get?
0
@@ -24,10 +28,6 @@ class DummyRequest
0
     @get = false
0
   end
0
 
0
- def symbolized_path_parameters
0
- { :controller => 'foo', :action => 'bar' }
0
- end
0
-
0
   def relative_url_root
0
     ''
0
   end
...
220
221
222
 
 
 
 
 
 
 
 
 
223
224
225
...
307
308
309
310
 
311
312
313
 
 
314
315
316
 
 
 
 
317
 
 
318
319
320
...
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
...
316
317
318
 
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
0
@@ -220,6 +220,15 @@ class ViewTest < Test::Unit::TestCase
0
     end
0
   end
0
 
0
+ def test_custom_routing_page_param
0
+ @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
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
@@ -307,14 +316,22 @@ class ViewTest < Test::Unit::TestCase
0
       })
0
     end
0
 
0
- def assert_links_match pattern, links = nil
0
+ def assert_links_match pattern, links = nil, numbers = nil
0
       links ||= assert_select 'div.pagination a[href]' do |elements|
0
         elements
0
       end
0
+
0
+ pages = [] if numbers
0
       
0
       links.each do |el|
0
         assert_match pattern, el['href']
0
+ if numbers
0
+ el['href'] =~ pattern
0
+ pages << $1.to_i
0
+ end
0
       end
0
+
0
+ assert_equal pages, numbers, "page numbers don't match" if numbers
0
     end
0
 
0
     def assert_no_links_match pattern

Comments

    No one has commented yet.