paginator 1.0.9 → 1.1.0
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.
- data/History.txt +5 -0
- data/README.txt +2 -2
- data/lib/paginator.rb +24 -22
- data/test/test_paginator.rb +5 -2
- metadata +11 -8
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 1.1.0 / 2007-10-12
|
2
|
+
|
3
|
+
* Paginator now mixes in Enumerable (supporting inject, etc, on pages)
|
4
|
+
* Page now mixes in Enumerable (supporting inject, etc, on items)
|
5
|
+
|
1
6
|
== 1.0.9 / 2007-02-17
|
2
7
|
|
3
8
|
* Modified Pager#number_of_pages to support mathn's monkeypatching of Fixnum#/
|
data/README.txt
CHANGED
@@ -30,7 +30,7 @@ You could, of course, just pass in the number of items per page directly to the
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# In your view
|
33
|
-
<% @page.
|
33
|
+
<% @page.each do |foo| %>
|
34
34
|
<%# Show something for each item %>
|
35
35
|
<% end %>
|
36
36
|
<%= @page.number %>
|
@@ -62,7 +62,7 @@ No special instructions.
|
|
62
62
|
|
63
63
|
(The MIT License)
|
64
64
|
|
65
|
-
Copyright (c) 2006 Bruce Williams (http://codefluency.com)
|
65
|
+
Copyright (c) 2006-2007 Bruce Williams (http://codefluency.com)
|
66
66
|
|
67
67
|
Permission is hereby granted, free of charge, to any person obtaining
|
68
68
|
a copy of this software and associated documentation files (the
|
data/lib/paginator.rb
CHANGED
@@ -2,7 +2,9 @@ require 'forwardable'
|
|
2
2
|
|
3
3
|
class Paginator
|
4
4
|
|
5
|
-
VERSION = '1.0
|
5
|
+
VERSION = '1.1.0'
|
6
|
+
|
7
|
+
include Enumerable
|
6
8
|
|
7
9
|
class ArgumentError < ::ArgumentError; end
|
8
10
|
class MissingCountError < ArgumentError; end
|
@@ -42,17 +44,9 @@ class Paginator
|
|
42
44
|
page number_of_pages
|
43
45
|
end
|
44
46
|
|
45
|
-
# Iterate through pages
|
46
47
|
def each
|
47
|
-
each_with_index do |item, index|
|
48
|
-
yield item
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# Iterate through pages with indices
|
53
|
-
def each_with_index
|
54
48
|
1.upto(number_of_pages) do |number|
|
55
|
-
yield
|
49
|
+
yield page(number)
|
56
50
|
end
|
57
51
|
end
|
58
52
|
|
@@ -73,11 +67,7 @@ class Paginator
|
|
73
67
|
# of the page in the paginator
|
74
68
|
class Page
|
75
69
|
|
76
|
-
|
77
|
-
def_delegator :@pager, :first, :first
|
78
|
-
def_delegator :@pager, :last, :last
|
79
|
-
def_delegator :items, :each
|
80
|
-
def_delegator :items, :each_with_index
|
70
|
+
include Enumerable
|
81
71
|
|
82
72
|
attr_reader :number, :pager
|
83
73
|
|
@@ -98,10 +88,10 @@ class Paginator
|
|
98
88
|
@number > 1
|
99
89
|
end
|
100
90
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
91
|
+
# # Get previous page (if possible)
|
92
|
+
def prev
|
93
|
+
@pager.page(@number - 1) if prev?
|
94
|
+
end
|
105
95
|
|
106
96
|
# Checks to see if there's a page after this one
|
107
97
|
def next?
|
@@ -109,9 +99,9 @@ class Paginator
|
|
109
99
|
end
|
110
100
|
|
111
101
|
# Get next page (if possible)
|
112
|
-
|
113
|
-
|
114
|
-
|
102
|
+
def next
|
103
|
+
@pager.page(@number + 1) if next?
|
104
|
+
end
|
115
105
|
|
116
106
|
# The "item number" of the first item on this page
|
117
107
|
def first_item_number
|
@@ -131,6 +121,18 @@ class Paginator
|
|
131
121
|
@pager == other.pager && self.number == other.number
|
132
122
|
end
|
133
123
|
|
124
|
+
def each(&block)
|
125
|
+
items.each(&block)
|
126
|
+
end
|
127
|
+
|
128
|
+
def method_missing(meth, *args, &block) #:nodoc:
|
129
|
+
if @pager.respond_to?(meth)
|
130
|
+
@pager.__send__(meth, *args, &block)
|
131
|
+
else
|
132
|
+
super
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
134
136
|
end
|
135
137
|
|
136
138
|
end
|
data/test/test_paginator.rb
CHANGED
@@ -60,12 +60,16 @@ class PaginatorTest < Test::Unit::TestCase
|
|
60
60
|
assert !@pager.first.prev
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
63
|
+
def test_page_enumerable
|
64
64
|
@pager.each do |page|
|
65
65
|
assert page
|
66
66
|
page.each do |item|
|
67
67
|
assert item
|
68
68
|
end
|
69
|
+
page.each_with_index do |item, index|
|
70
|
+
assert_equal page.items[index], item
|
71
|
+
end
|
72
|
+
assert_equal page.items, page.inject([]) {|list, item| list << item }
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
@@ -120,7 +124,6 @@ class PaginatorTest < Test::Unit::TestCase
|
|
120
124
|
assert_equal 10, page.first_item_number
|
121
125
|
assert_equal 11, page.last_item_number
|
122
126
|
end
|
123
|
-
|
124
127
|
|
125
128
|
end
|
126
129
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.4
|
3
3
|
specification_version: 1
|
4
4
|
name: paginator
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0
|
7
|
-
date: 2007-
|
6
|
+
version: 1.1.0
|
7
|
+
date: 2007-08-12 00:00:00 -05:00
|
8
8
|
summary: A generic paginator object for use in any Ruby program
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -38,10 +38,13 @@ files:
|
|
38
38
|
- test/test_paginator.rb
|
39
39
|
test_files:
|
40
40
|
- test/test_paginator.rb
|
41
|
-
rdoc_options:
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.txt
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
45
48
|
executables:
|
46
49
|
- paginator
|
47
50
|
extensions: []
|
@@ -56,5 +59,5 @@ dependencies:
|
|
56
59
|
requirements:
|
57
60
|
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
59
|
-
version: 1.1
|
62
|
+
version: 1.2.1
|
60
63
|
version:
|