pagination 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/pagination.gemspec +2 -2
- data/test/test_pagination_template.rb +51 -21
- data/views/paginate.erb +28 -0
- data/views/paginate.haml +14 -19
- metadata +23 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
data/pagination.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{pagination}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.4"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Cyril David"]
|
@@ -42,7 +42,7 @@ Gem::Specification.new do |s|
|
|
42
42
|
s.homepage = %q{http://github.com/sinefunc/pagination}
|
43
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
44
44
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = %q{1.3.
|
45
|
+
s.rubygems_version = %q{1.3.6}
|
46
46
|
s.summary = %q{A simplistic pagination library}
|
47
47
|
s.test_files = [
|
48
48
|
"test/helper.rb",
|
@@ -9,16 +9,17 @@ class TestPaginationTemplate < Test::Unit::TestCase
|
|
9
9
|
@dataset = ['one', 'two', 'three', 'four', 'five']
|
10
10
|
@items = Pagination.paginate(@dataset, :per_page => 1, :page => 1)
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
|
+
def doc
|
14
|
+
Nokogiri(@render.call)
|
15
|
+
end
|
16
|
+
|
13
17
|
describe "haml rendering option" do
|
14
18
|
setup do
|
15
19
|
Object.const_set(:Haml, HamlHere) unless defined?(Haml)
|
16
20
|
@render = lambda { Pagination::Template.new(@items).render }
|
17
21
|
end
|
18
22
|
|
19
|
-
def doc
|
20
|
-
Nokogiri(@render.call)
|
21
|
-
end
|
22
23
|
|
23
24
|
should "be able to render using haml" do
|
24
25
|
assert_nothing_raised do
|
@@ -26,50 +27,79 @@ class TestPaginationTemplate < Test::Unit::TestCase
|
|
26
27
|
end
|
27
28
|
end
|
28
29
|
|
29
|
-
should "have
|
30
|
-
assert_equal
|
31
|
-
doc.search('ul.pagination > li.prev-link.disabled > a').length
|
30
|
+
should "have no .pagination > a.prev-link" do
|
31
|
+
assert_equal 0, doc.search('.pagination > a.prev-link').length
|
32
32
|
end
|
33
33
|
|
34
34
|
should "have a ul > li.next-link with page=2" do
|
35
35
|
assert_equal 1,
|
36
|
-
doc.search('
|
36
|
+
doc.search('div.pagination > a.next-link[href="?page=2"]').length
|
37
37
|
end
|
38
38
|
|
39
|
-
should "display the first page as the
|
40
|
-
assert_equal 1,
|
41
|
-
doc.search('ul.pagination > li > ul.page-numbers > li > span').length
|
39
|
+
should "display the first page as the current page" do
|
40
|
+
assert_equal 1, doc.search('div.pagination > ul > li > span').length
|
42
41
|
|
43
|
-
assert_equal '1',
|
44
|
-
doc.search('ul.pagination > li > ul.page-numbers > li > span').text
|
42
|
+
assert_equal '1', doc.search('div.pagination > ul > li > span').text
|
45
43
|
end
|
46
44
|
|
47
45
|
should "display pages 2 to 5 as links" do
|
48
46
|
(2..5).each do |page|
|
49
47
|
assert_equal 1,
|
50
|
-
doc.search(%(
|
51
|
-
|
48
|
+
doc.search(%(div.pagination > ul > li >
|
49
|
+
a[href="?page=#{page}"])).length
|
52
50
|
|
53
51
|
assert_equal page.to_s,
|
54
|
-
doc.search(%(
|
55
|
-
|
52
|
+
doc.search(%(div.pagination > ul > li >
|
53
|
+
a[href="?page=#{page}"])).text
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
59
57
|
|
60
58
|
describe "erb rendering option" do
|
61
59
|
setup do
|
62
|
-
|
60
|
+
if defined?(Haml)
|
61
|
+
Object.send :remove_const, :Haml
|
62
|
+
end
|
63
|
+
|
64
|
+
@template = Pagination::Template.new(@items)
|
65
|
+
@render = lambda { @template.render }
|
63
66
|
end
|
64
67
|
|
65
68
|
should "render without any errors" do
|
66
|
-
|
67
|
-
assert_kind_of ERB, template.send(:engine)
|
69
|
+
assert_kind_of ERB, @template.send(:engine)
|
68
70
|
|
69
71
|
assert_nothing_raised do
|
70
|
-
|
72
|
+
@render.call
|
71
73
|
end
|
72
74
|
end
|
75
|
+
|
76
|
+
should "have no .pagination > a.prev-link" do
|
77
|
+
assert_equal 0, doc.search('.pagination > a.prev-link').length
|
78
|
+
end
|
79
|
+
|
80
|
+
should "have a ul > li.next-link with page=2" do
|
81
|
+
assert_equal 1,
|
82
|
+
doc.search('div.pagination > a.next-link[href="?page=2"]').length
|
83
|
+
end
|
84
|
+
|
85
|
+
should "display the first page as the current page" do
|
86
|
+
assert_equal 1, doc.search('div.pagination > ul > li > span').length
|
87
|
+
|
88
|
+
assert_equal '1', doc.search('div.pagination > ul > li > span').text
|
89
|
+
end
|
90
|
+
|
91
|
+
should "display pages 2 to 5 as links" do
|
92
|
+
(2..5).each do |page|
|
93
|
+
assert_equal 1,
|
94
|
+
doc.search(%(div.pagination > ul > li >
|
95
|
+
a[href="?page=#{page}"])).length
|
96
|
+
|
97
|
+
assert_equal page.to_s,
|
98
|
+
doc.search(%(div.pagination > ul > li >
|
99
|
+
a[href="?page=#{page}"])).text
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
73
103
|
end
|
74
104
|
end
|
75
105
|
|
data/views/paginate.erb
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
<% if items.render? %>
|
2
|
+
<div class="pagination">
|
3
|
+
<% if items.prev_page %>
|
4
|
+
<a class="prev-link" href="<%= '?page=%s' % items.prev_page %>">
|
5
|
+
<span>← Previous</span>
|
6
|
+
</a>
|
7
|
+
<% end %>
|
8
|
+
|
9
|
+
<ul>
|
10
|
+
<% items.displayed_pages.each do |page| %>
|
11
|
+
<% if items.current?(page) %>
|
12
|
+
<li class="active"><span><%= page %></span></li>
|
13
|
+
<% else %>
|
14
|
+
<li><a href="<%= '?page=%s' % page %>"><%= page %></a></li>
|
15
|
+
<% end %>
|
16
|
+
<% end %>
|
17
|
+
</ul>
|
18
|
+
|
19
|
+
<% if items.next_page %>
|
20
|
+
<a class="next-link" href="<%= '?page=%s' % items.next_page %>">
|
21
|
+
<span>Next →</span>
|
22
|
+
</a>
|
23
|
+
<% end %>
|
24
|
+
</div>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
|
28
|
+
|
1
29
|
<% if items.render? %>
|
2
30
|
<ul class="pagination">
|
3
31
|
<% if items.prev_page %>
|
data/views/paginate.haml
CHANGED
@@ -1,24 +1,19 @@
|
|
1
1
|
- if items.render?
|
2
|
-
%
|
2
|
+
%div.pagination
|
3
3
|
- if items.prev_page
|
4
|
-
%
|
5
|
-
%
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
4
|
+
%a.prev-link{:href => ("?page=%s" % items.prev_page)}
|
5
|
+
%span ← Previous
|
6
|
+
|
7
|
+
%ul
|
8
|
+
- items.displayed_pages.each do |page|
|
9
|
+
- if items.current?(page)
|
10
|
+
%li.active
|
11
|
+
%span= page
|
12
|
+
- else
|
13
13
|
%li
|
14
|
-
|
15
|
-
%span= page
|
16
|
-
- else
|
17
|
-
%a{:href => ("?page=%s" % page)}= page
|
14
|
+
%a{:href => ("?page=%s" % page)}= page
|
18
15
|
|
19
16
|
- if items.next_page
|
20
|
-
%
|
21
|
-
%
|
22
|
-
|
23
|
-
%li.next-link.disabled
|
24
|
-
%a(href='javascript:;') Next »
|
17
|
+
%a.next-link{:href => ("?page=%s" % items.next_page)}
|
18
|
+
%span Next →
|
19
|
+
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pagination
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 4
|
9
|
+
version: 0.1.4
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Cyril David
|
@@ -14,24 +19,28 @@ default_executable: pagination
|
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: contest
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
23
29
|
version: "0"
|
24
|
-
|
30
|
+
type: :development
|
31
|
+
version_requirements: *id001
|
25
32
|
- !ruby/object:Gem::Dependency
|
26
33
|
name: haml
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
34
|
+
prerelease: false
|
35
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
36
|
requirements:
|
31
37
|
- - ">="
|
32
38
|
- !ruby/object:Gem::Version
|
39
|
+
segments:
|
40
|
+
- 0
|
33
41
|
version: "0"
|
34
|
-
|
42
|
+
type: :development
|
43
|
+
version_requirements: *id002
|
35
44
|
description: Trying to make the pagination world a better place
|
36
45
|
email: cyx.ucron@gmail.com
|
37
46
|
executables:
|
@@ -74,18 +83,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
74
83
|
requirements:
|
75
84
|
- - ">="
|
76
85
|
- !ruby/object:Gem::Version
|
86
|
+
segments:
|
87
|
+
- 0
|
77
88
|
version: "0"
|
78
|
-
version:
|
79
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
90
|
requirements:
|
81
91
|
- - ">="
|
82
92
|
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
83
95
|
version: "0"
|
84
|
-
version:
|
85
96
|
requirements: []
|
86
97
|
|
87
98
|
rubyforge_project:
|
88
|
-
rubygems_version: 1.3.
|
99
|
+
rubygems_version: 1.3.6
|
89
100
|
signing_key:
|
90
101
|
specification_version: 3
|
91
102
|
summary: A simplistic pagination library
|