will_paginate 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of will_paginate might be problematic. Click here for more details.
- data/CHANGELOG +6 -0
- data/README.rdoc +1 -1
- data/Rakefile +4 -17
- data/lib/will_paginate/version.rb +1 -1
- data/lib/will_paginate/view_helpers.rb +14 -6
- data/test/lib/view_test_process.rb +4 -4
- data/test/view_test.rb +31 -1
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 2.2.2, released 2008-04-21
|
2
|
+
|
3
|
+
* Add support for page parameter in custom routes like "/foo/page/2"
|
4
|
+
* Change output of "page_entries_info" on single-page collection and erraneous
|
5
|
+
output with empty collection as reported by Tim Chater
|
6
|
+
|
1
7
|
== 2.2.1, released 2008-04-08
|
2
8
|
|
3
9
|
* take less risky path when monkeypatching named_scope; fix that it no longer
|
data/README.rdoc
CHANGED
@@ -114,7 +114,7 @@ contributions or just simply awesome ideas:
|
|
114
114
|
Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
|
115
115
|
Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
|
116
116
|
van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
|
117
|
-
Lourens Naudé, Rick Olson.
|
117
|
+
Lourens Naudé, Rick Olson, Russell Norris.
|
118
118
|
|
119
119
|
|
120
120
|
== Usable pagination in the UI
|
data/Rakefile
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'rake/testtask'
|
3
|
-
require 'rake/rdoctask'
|
1
|
+
require File.dirname(__FILE__) + '/lib/rake_hacks'
|
4
2
|
|
5
3
|
desc 'Default: run unit tests.'
|
6
4
|
task :default => :test
|
@@ -12,17 +10,6 @@ Rake::TestTask.new(:test) do |t|
|
|
12
10
|
t.libs << 'test'
|
13
11
|
end
|
14
12
|
|
15
|
-
# I want to specify environment variables at call time
|
16
|
-
class EnvTestTask < Rake::TestTask
|
17
|
-
attr_accessor :env
|
18
|
-
|
19
|
-
def ruby(*args)
|
20
|
-
env.each { |key, value| ENV[key] = value } if env
|
21
|
-
super
|
22
|
-
env.keys.each { |key| ENV.delete key } if env
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
13
|
for configuration in %w( sqlite3 mysql postgres )
|
27
14
|
EnvTestTask.new("test_#{configuration}") do |t|
|
28
15
|
t.pattern = 'test/finder_test.rb'
|
@@ -52,7 +39,7 @@ task :test_all do
|
|
52
39
|
end
|
53
40
|
|
54
41
|
desc 'Generate RDoc documentation for the will_paginate plugin.'
|
55
|
-
Rake::RDocTask.new(:
|
42
|
+
Rake::RDocTask.new(:doc) do |rdoc|
|
56
43
|
files = ['README.rdoc', 'LICENSE', 'CHANGELOG']
|
57
44
|
files << FileList.new('lib/**/*.rb').
|
58
45
|
exclude('lib/will_paginate/named_scope*').
|
@@ -63,8 +50,8 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
63
50
|
rdoc.main = "README.rdoc" # page to start on
|
64
51
|
rdoc.title = "will_paginate documentation"
|
65
52
|
|
66
|
-
|
67
|
-
rdoc.template =
|
53
|
+
my_template = '/home/mislav/projects/rdoc_template/mislav.rb'
|
54
|
+
rdoc.template = my_template if File.exists? my_template
|
68
55
|
|
69
56
|
rdoc.rdoc_dir = 'doc' # rdoc output folder
|
70
57
|
rdoc.options << '--inline-source'
|
@@ -132,11 +132,19 @@ module WillPaginate
|
|
132
132
|
# <%= page_entries_info @posts %>
|
133
133
|
# #-> Displaying entries 6 - 10 of 26 in total
|
134
134
|
def page_entries_info(collection)
|
135
|
-
|
136
|
-
collection.
|
137
|
-
|
138
|
-
|
139
|
-
|
135
|
+
if collection.total_pages < 2
|
136
|
+
case collection.size
|
137
|
+
when 0; 'No entries found'
|
138
|
+
when 1; 'Displaying <b>1</b> entry'
|
139
|
+
else; "Displaying <b>all #{collection.size}</b> entries"
|
140
|
+
end
|
141
|
+
else
|
142
|
+
%{Displaying entries <b>%d - %d</b> of <b>%d</b> in total} % [
|
143
|
+
collection.offset + 1,
|
144
|
+
collection.offset + collection.length,
|
145
|
+
collection.total_entries
|
146
|
+
]
|
147
|
+
end
|
140
148
|
end
|
141
149
|
|
142
150
|
def self.total_pages_for_collection(collection) #:nodoc:
|
@@ -272,7 +280,7 @@ module WillPaginate
|
|
272
280
|
end
|
273
281
|
|
274
282
|
url = @template.url_for(@url_params)
|
275
|
-
@url_string = url.sub(
|
283
|
+
@url_string = url.sub(%r!([?&/]#{CGI.escape param_name}[=/])#{page}!, '\1@')
|
276
284
|
return url
|
277
285
|
end
|
278
286
|
@url_string.sub '@', page.to_s
|
@@ -5,15 +5,19 @@ require 'will_paginate'
|
|
5
5
|
WillPaginate.enable_actionpack
|
6
6
|
|
7
7
|
ActionController::Routing::Routes.draw do |map|
|
8
|
+
map.connect 'dummy/page/:page', :controller => 'dummy'
|
8
9
|
map.connect ':controller/:action/:id'
|
9
10
|
end
|
10
11
|
|
11
12
|
ActionController::Base.perform_caching = false
|
12
13
|
|
13
14
|
class DummyRequest
|
15
|
+
attr_accessor :symbolized_path_parameters
|
16
|
+
|
14
17
|
def initialize
|
15
18
|
@get = true
|
16
19
|
@params = {}
|
20
|
+
@symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
|
17
21
|
end
|
18
22
|
|
19
23
|
def get?
|
@@ -24,10 +28,6 @@ class DummyRequest
|
|
24
28
|
@get = false
|
25
29
|
end
|
26
30
|
|
27
|
-
def symbolized_path_parameters
|
28
|
-
{ :controller => 'foo', :action => 'bar' }
|
29
|
-
end
|
30
|
-
|
31
31
|
def relative_url_root
|
32
32
|
''
|
33
33
|
end
|
data/test/view_test.rb
CHANGED
@@ -156,6 +156,19 @@ class ViewTest < Test::Unit::TestCase
|
|
156
156
|
assert_equal %{Displaying entries <b>25 - 26</b> of <b>26</b> in total},
|
157
157
|
@html_result
|
158
158
|
end
|
159
|
+
|
160
|
+
def test_page_entries_info_with_single_page_collection
|
161
|
+
@template = '<%= page_entries_info collection %>'
|
162
|
+
|
163
|
+
paginate(('a'..'d').to_a.paginate(:page => 1, :per_page => 5))
|
164
|
+
assert_equal %{Displaying <b>all 4</b> entries}, @html_result
|
165
|
+
|
166
|
+
paginate(['a'].paginate(:page => 1, :per_page => 5))
|
167
|
+
assert_equal %{Displaying <b>1</b> entry}, @html_result
|
168
|
+
|
169
|
+
paginate([].paginate(:page => 1, :per_page => 5))
|
170
|
+
assert_equal %{No entries found}, @html_result
|
171
|
+
end
|
159
172
|
|
160
173
|
## parameter handling in page links ##
|
161
174
|
|
@@ -207,6 +220,15 @@ class ViewTest < Test::Unit::TestCase
|
|
207
220
|
end
|
208
221
|
end
|
209
222
|
|
223
|
+
def test_custom_routing_page_param
|
224
|
+
@request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
|
225
|
+
paginate :per_page => 2 do
|
226
|
+
assert_select 'a[href]', 6 do |links|
|
227
|
+
assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
210
232
|
## internal hardcore stuff ##
|
211
233
|
|
212
234
|
class LegacyCollection < WillPaginate::Collection
|
@@ -294,14 +316,22 @@ class ViewTest < Test::Unit::TestCase
|
|
294
316
|
})
|
295
317
|
end
|
296
318
|
|
297
|
-
def assert_links_match pattern, links = nil
|
319
|
+
def assert_links_match pattern, links = nil, numbers = nil
|
298
320
|
links ||= assert_select 'div.pagination a[href]' do |elements|
|
299
321
|
elements
|
300
322
|
end
|
323
|
+
|
324
|
+
pages = [] if numbers
|
301
325
|
|
302
326
|
links.each do |el|
|
303
327
|
assert_match pattern, el['href']
|
328
|
+
if numbers
|
329
|
+
el['href'] =~ pattern
|
330
|
+
pages << $1.to_i
|
331
|
+
end
|
304
332
|
end
|
333
|
+
|
334
|
+
assert_equal pages, numbers, "page numbers don't match" if numbers
|
305
335
|
end
|
306
336
|
|
307
337
|
def assert_no_links_match pattern
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: will_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Mislav Marohni\xC4\x87"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-04-
|
12
|
+
date: 2008-04-21 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
requirements: []
|
93
93
|
|
94
94
|
rubyforge_project: will-paginate
|
95
|
-
rubygems_version: 1.1.
|
95
|
+
rubygems_version: 1.1.1
|
96
96
|
signing_key:
|
97
97
|
specification_version: 2
|
98
98
|
summary: Most awesome pagination solution for Rails
|