just_paginate 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/just_paginate.rb +9 -5
- data/test/test_just_paginate.rb +12 -2
- metadata +3 -3
data/lib/just_paginate.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
module JustPaginate
|
3
3
|
|
4
|
-
VERSION = "0.0.
|
4
|
+
VERSION = "0.0.5"
|
5
5
|
|
6
6
|
def self.page_value(page)
|
7
7
|
if page.nil?
|
@@ -13,9 +13,13 @@ module JustPaginate
|
|
13
13
|
|
14
14
|
def self.paginate(curr_page, per_page, total_entry_count, &selection_strategy)
|
15
15
|
raise "Pagination just supplies index range, expects a selection strategy" if selection_strategy.nil?
|
16
|
-
|
16
|
+
|
17
17
|
entries = yield(index_range(curr_page, per_page, total_entry_count)) || []
|
18
|
-
return entries, total_page_number
|
18
|
+
return entries, total_page_number(total_entry_count, per_page)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.total_page_number(total_entry_count, per_page)
|
22
|
+
total_entry_count / per_page
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.index_range(curr_page, per_page, total_entry_count)
|
@@ -27,7 +31,7 @@ module JustPaginate
|
|
27
31
|
end
|
28
32
|
|
29
33
|
if end_index>total_entry_count
|
30
|
-
end_index=
|
34
|
+
end_index = total_entry_count
|
31
35
|
end
|
32
36
|
|
33
37
|
Range.new(start_index, end_index)
|
@@ -98,7 +102,7 @@ module JustPaginate
|
|
98
102
|
current = (total-max_visible)+1
|
99
103
|
end
|
100
104
|
|
101
|
-
current.upto(current+(max_visible)).each {|n| labels.push(n.to_s)}
|
105
|
+
current.upto(current+(max_visible-1)).each {|n| labels.push(n.to_s)}
|
102
106
|
|
103
107
|
if (current <= (total-max_visible))
|
104
108
|
labels.concat ["...", "#{total}", ">"]
|
data/test/test_just_paginate.rb
CHANGED
@@ -26,7 +26,14 @@ class JustPaginateTest < Test::Unit::TestCase
|
|
26
26
|
JustPaginate.index_range(7,2,4)
|
27
27
|
end
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
|
+
should "calculate correct total page count" do
|
31
|
+
assert_equal 25, JustPaginate.total_page_number(500, 20)
|
32
|
+
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
|
30
37
|
should "correctly apply the supplied selection strategy" do
|
31
38
|
ran = false
|
32
39
|
sliced_entries, page_count = JustPaginate.paginate(1, 5, 10) do |index_range|
|
@@ -53,7 +60,10 @@ class JustPaginateTest < Test::Unit::TestCase
|
|
53
60
|
assert_equal 60..79, JustPaginate.index_range(4,20,100)
|
54
61
|
assert_equal 60..79, JustPaginate.index_range(4,20,95)
|
55
62
|
assert_equal 80..99, JustPaginate.index_range(5,20,100)
|
56
|
-
assert_equal 80..
|
63
|
+
assert_equal 80..95, JustPaginate.index_range(5,20,95)
|
64
|
+
|
65
|
+
assert_equal 460..479, JustPaginate.index_range(24,20,500)
|
66
|
+
assert_equal 480..499, JustPaginate.index_range(25,20,500)
|
57
67
|
end
|
58
68
|
end
|
59
69
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just_paginate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gitorious AS
|