kaminari 0.9.10 → 0.9.12
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of kaminari might be problematic. Click here for more details.
- data/CHANGELOG +10 -0
- data/VERSION +1 -1
- data/app/views/kaminari/_paginator.html.erb +22 -3
- data/app/views/kaminari/_paginator.html.haml +17 -2
- data/kaminari.gemspec +1 -1
- data/lib/kaminari/helpers.rb +24 -42
- data/lib/kaminari/tags.rb +98 -10
- data/spec/helpers/helpers_spec.rb +100 -96
- data/spec/helpers/tags_spec.rb +111 -0
- metadata +3 -3
data/CHANGELOG
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
== 0.9.12
|
2
|
+
|
3
|
+
* Moved the whole pagination logic to the paginator partial so that users can
|
4
|
+
touch it
|
5
|
+
Note: You need to update your _paginator.html.* if you've already customized
|
6
|
+
it. If you haven't overridden _paginator.html.* files, then probably
|
7
|
+
there're nothing you have to do.
|
8
|
+
See this commit for the example:
|
9
|
+
https://github.com/amatsuda/kaminari_themes/commit/2dfb41c
|
10
|
+
|
1
11
|
== 0.9.10
|
2
12
|
|
3
13
|
* the per() method accepts String, zero and minus value now #7 [koic]
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.9.
|
1
|
+
0.9.12
|
@@ -4,7 +4,26 @@
|
|
4
4
|
num_pages: total number of pages
|
5
5
|
per_page: number of items to fetch per page
|
6
6
|
remote: data-remote
|
7
|
+
paginator: the paginator that renders the pagination tags inside
|
7
8
|
-%>
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
<%= paginator.render do -%>
|
10
|
+
<nav class='pagination'>
|
11
|
+
<%= current_page > 1 ? prev_link_tag : prev_span_tag %>
|
12
|
+
<% each_page do |page| -%>
|
13
|
+
<% if page.current? -%>
|
14
|
+
<%= current_page_tag %>
|
15
|
+
<% elsif page.left_outer? || page.right_outer? || page.inside_window? -%>
|
16
|
+
<% if page.first? -%>
|
17
|
+
<%= first_page_link_tag %>
|
18
|
+
<% elsif page.last? -%>
|
19
|
+
<%= last_page_link_tag %>
|
20
|
+
<% else -%>
|
21
|
+
<%= page_link_tag %>
|
22
|
+
<% end -%>
|
23
|
+
<% elsif !page.was_truncated? -%>
|
24
|
+
<%= truncated_span_tag %>
|
25
|
+
<% end -%>
|
26
|
+
<% end -%>
|
27
|
+
<%= num_pages > current_page ? next_link_tag : next_span_tag %>
|
28
|
+
</nav>
|
29
|
+
<% end -%>
|
@@ -4,5 +4,20 @@
|
|
4
4
|
num_pages: total number of pages
|
5
5
|
per_page: number of items to fetch per page
|
6
6
|
remote: data-remote
|
7
|
-
|
8
|
-
|
7
|
+
paginator: the paginator that renders the pagination tags inside
|
8
|
+
= paginator.render do
|
9
|
+
%nav.pagination
|
10
|
+
= current_page > 1 ? prev_link_tag : prev_span_tag
|
11
|
+
- each_page do |page|
|
12
|
+
- if page.current?
|
13
|
+
= current_page_tag
|
14
|
+
- elsif page.left_outer? || page.right_outer? || page.inside_window?
|
15
|
+
- if page.first?
|
16
|
+
= first_page_link_tag
|
17
|
+
- elsif page.last?
|
18
|
+
= last_page_link_tag
|
19
|
+
- else
|
20
|
+
= page_link_tag
|
21
|
+
- elsif !page.was_truncated?
|
22
|
+
= truncated_span_tag
|
23
|
+
= num_pages > current_page ? next_link_tag : next_span_tag
|
data/kaminari.gemspec
CHANGED
data/lib/kaminari/helpers.rb
CHANGED
@@ -2,38 +2,14 @@ require File.join(File.dirname(__FILE__), 'tags')
|
|
2
2
|
|
3
3
|
module Kaminari
|
4
4
|
module Helpers
|
5
|
-
|
5
|
+
# Wraps the template context and helps each tag render itselves
|
6
|
+
class TemplateWrapper
|
6
7
|
attr_reader :options, :params
|
8
|
+
delegate :render, :url_for, :to => :@template
|
7
9
|
|
8
10
|
def initialize(template, options) #:nodoc:
|
9
11
|
@template, @options = template, options
|
10
12
|
@params = options[:params] ? template.params.merge(options.delete :params) : template.params
|
11
|
-
@left, @window, @right = (options[:left] || options[:outer_window] || 1), (options[:window] || options[:inner_window] || 4), (options[:right] || options[:outer_window] || 1)
|
12
|
-
end
|
13
|
-
|
14
|
-
def tagify_links #:nodoc:
|
15
|
-
num_pages, current_page, left, window, right = @options[:num_pages], @options[:current_page], @left, @window, @right
|
16
|
-
return [] if num_pages <= 1
|
17
|
-
|
18
|
-
tags = []
|
19
|
-
tags << (current_page > 1 ? PrevLink.new(self) : PrevSpan.new(self))
|
20
|
-
1.upto(num_pages) do |i|
|
21
|
-
if i == current_page
|
22
|
-
tags << CurrentPage.new(self, :page => i)
|
23
|
-
elsif (i <= left + 1) || ((num_pages - i) <= right) || ((i - current_page).abs <= window)
|
24
|
-
case i
|
25
|
-
when 1
|
26
|
-
tags << FirstPageLink.new(self, :page => i)
|
27
|
-
when num_pages
|
28
|
-
tags << LastPageLink.new(self, :page => i)
|
29
|
-
else
|
30
|
-
tags << PageLink.new(self, :page => i)
|
31
|
-
end
|
32
|
-
else
|
33
|
-
tags << TruncatedSpan.new(self) unless tags.last.is_a? TruncatedSpan
|
34
|
-
end
|
35
|
-
end
|
36
|
-
tags << (num_pages > current_page ? NextLink.new(self) : NextSpan.new(self))
|
37
13
|
end
|
38
14
|
|
39
15
|
def partial_exists?(name) #:nodoc:
|
@@ -41,12 +17,8 @@ module Kaminari
|
|
41
17
|
resolver.find_all(*args_for_lookup(name)).present?
|
42
18
|
end
|
43
19
|
|
44
|
-
def
|
45
|
-
|
46
|
-
clear_content_for :kaminari_paginator_tags
|
47
|
-
@template.content_for :kaminari_paginator_tags, tagify_links.join.html_safe
|
48
|
-
Paginator.new(self).to_s
|
49
|
-
end
|
20
|
+
def output_buffer #:nodoc:
|
21
|
+
@template.instance_variable_get('@output_buffer')
|
50
22
|
end
|
51
23
|
|
52
24
|
private
|
@@ -63,19 +35,34 @@ module Kaminari
|
|
63
35
|
method.call name, ['kaminari'], true, []
|
64
36
|
end
|
65
37
|
end
|
38
|
+
end
|
66
39
|
|
67
|
-
|
68
|
-
|
40
|
+
# The main class that controlls the whole process
|
41
|
+
class PaginationRenderer
|
42
|
+
def initialize(template, options) #:nodoc:
|
43
|
+
@window_options = {}.tap do |h|
|
44
|
+
h[:window] = options.delete(:window) || options.delete(:inner_window) || 4
|
45
|
+
outer_window = options.delete(:outer_window)
|
46
|
+
h[:left] = options.delete(:left) || outer_window || 1
|
47
|
+
h[:right] = options.delete(:right) || outer_window || 1
|
48
|
+
end
|
49
|
+
@template = TemplateWrapper.new(template, options)
|
50
|
+
end
|
51
|
+
|
52
|
+
def to_s #:nodoc:
|
53
|
+
suppress_logging_render_partial do
|
54
|
+
Paginator.new(@template, @window_options).to_s
|
55
|
+
end
|
69
56
|
end
|
70
57
|
|
58
|
+
private
|
71
59
|
# dirty hack
|
72
60
|
def suppress_logging_render_partial(&blk)
|
73
61
|
if subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}
|
74
62
|
class << subscriber
|
75
63
|
alias_method :render_partial_with_logging, :render_partial
|
76
64
|
# do nothing
|
77
|
-
def render_partial(event)
|
78
|
-
end
|
65
|
+
def render_partial(event); end
|
79
66
|
end
|
80
67
|
ret = blk.call
|
81
68
|
class << subscriber
|
@@ -87,11 +74,6 @@ module Kaminari
|
|
87
74
|
blk.call
|
88
75
|
end
|
89
76
|
end
|
90
|
-
|
91
|
-
# another dirty hack
|
92
|
-
def clear_content_for(name)
|
93
|
-
@template.instance_variable_get('@_content_for')[name] = ActiveSupport::SafeBuffer.new
|
94
|
-
end
|
95
77
|
end
|
96
78
|
|
97
79
|
# = Helpers
|
data/lib/kaminari/tags.rb
CHANGED
@@ -17,12 +17,12 @@ module Kaminari
|
|
17
17
|
# installed template will be used.
|
18
18
|
# e.g.) Paginator -> $GEM_HOME/kaminari-x.x.x/app/views/kaminari/_paginator.html.erb
|
19
19
|
class Tag
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(template, options = {}) #:nodoc:
|
21
|
+
@template, @options = template, template.options.merge(options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def to_s(locals = {}) #:nodoc:
|
25
|
-
@
|
25
|
+
@template.render :partial => find_template, :locals => @options.merge(locals)
|
26
26
|
end
|
27
27
|
|
28
28
|
private
|
@@ -41,13 +41,13 @@ module Kaminari
|
|
41
41
|
# 3. the default one inside the engine
|
42
42
|
def find_template
|
43
43
|
self.class.ancestor_renderables.each do |klass|
|
44
|
-
return "kaminari/#{klass.template_filename}" if @
|
44
|
+
return "kaminari/#{klass.template_filename}" if @template.partial_exists? klass.template_filename
|
45
45
|
end
|
46
46
|
"kaminari/#{self.class.template_filename}"
|
47
47
|
end
|
48
48
|
|
49
49
|
def page_url_for(page)
|
50
|
-
@
|
50
|
+
@template.url_for @template.params.merge(:page => (page <= 1 ? nil : page))
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -65,6 +65,99 @@ module Kaminari
|
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
# The container tag
|
69
|
+
class Paginator < Tag
|
70
|
+
include Renderable
|
71
|
+
attr_reader :options
|
72
|
+
|
73
|
+
def initialize(template, window_options) #:nodoc:
|
74
|
+
@template, @options = template, window_options.reverse_merge(template.options)
|
75
|
+
# so that this instance can actually "render". Black magic?
|
76
|
+
@output_buffer = @template.output_buffer
|
77
|
+
end
|
78
|
+
|
79
|
+
# render given block as a view template
|
80
|
+
def render(&block)
|
81
|
+
instance_eval &block if @options[:num_pages] > 1
|
82
|
+
nil
|
83
|
+
end
|
84
|
+
|
85
|
+
# enumerate each page providing PageProxy object as the block parameter
|
86
|
+
def each_page
|
87
|
+
1.upto(@options[:num_pages]) do |i|
|
88
|
+
@page = i
|
89
|
+
yield PageProxy.new(options, i, @last)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
%w[current_page first_page_link last_page_link page_link].each do |tag|
|
94
|
+
eval <<-DEF
|
95
|
+
def #{tag}_tag
|
96
|
+
@last = #{tag.classify}.new @template, :page => @page
|
97
|
+
end
|
98
|
+
DEF
|
99
|
+
end
|
100
|
+
|
101
|
+
%w[prev_link prev_span next_link next_span truncated_span].each do |tag|
|
102
|
+
eval <<-DEF
|
103
|
+
def #{tag}_tag
|
104
|
+
@last = #{tag.classify}.new @template
|
105
|
+
end
|
106
|
+
DEF
|
107
|
+
end
|
108
|
+
|
109
|
+
def to_s(window_options = {}) #:nodoc:
|
110
|
+
super window_options.merge :paginator => self
|
111
|
+
end
|
112
|
+
|
113
|
+
# Wraps a "page number" and provides some utility methods
|
114
|
+
class PageProxy
|
115
|
+
def initialize(options, page, last) #:nodoc:
|
116
|
+
@options, @page, @last = options, page, last
|
117
|
+
end
|
118
|
+
|
119
|
+
# the page number
|
120
|
+
def number
|
121
|
+
@page
|
122
|
+
end
|
123
|
+
|
124
|
+
# current page or not
|
125
|
+
def current?
|
126
|
+
@page == @options[:current_page]
|
127
|
+
end
|
128
|
+
|
129
|
+
# the first page or not
|
130
|
+
def first?
|
131
|
+
@page == 1
|
132
|
+
end
|
133
|
+
|
134
|
+
# the last page or not
|
135
|
+
def last?
|
136
|
+
@page == @options[:num_pages]
|
137
|
+
end
|
138
|
+
|
139
|
+
# within the left outer window or not
|
140
|
+
def left_outer?
|
141
|
+
@page <= @options[:left] + 1
|
142
|
+
end
|
143
|
+
|
144
|
+
# within the right outer window or not
|
145
|
+
def right_outer?
|
146
|
+
@options[:num_pages] - @page <= @options[:right]
|
147
|
+
end
|
148
|
+
|
149
|
+
# inside the inner window or not
|
150
|
+
def inside_window?
|
151
|
+
(@page - @options[:current_page]).abs <= @options[:window]
|
152
|
+
end
|
153
|
+
|
154
|
+
# The last rendered tag was "truncated" or not
|
155
|
+
def was_truncated?
|
156
|
+
@last.is_a? TruncatedSpan
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
68
161
|
# A page
|
69
162
|
module Page
|
70
163
|
include Renderable
|
@@ -164,10 +257,5 @@ module Kaminari
|
|
164
257
|
class TruncatedSpan < Tag
|
165
258
|
include NonLink
|
166
259
|
end
|
167
|
-
|
168
|
-
# The container tag
|
169
|
-
class Paginator < Tag
|
170
|
-
include Renderable
|
171
|
-
end
|
172
260
|
end
|
173
261
|
end
|
@@ -12,111 +12,115 @@ describe 'Kaminari::Helpers::PaginationRenderer' do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
describe '#params' do
|
15
|
-
|
15
|
+
before do
|
16
|
+
@renderer = PaginationRenderer.new(template, :params => {:controller => 'foo', :action => 'bar'})
|
17
|
+
end
|
18
|
+
subject { @renderer.instance_variable_get '@template' }
|
16
19
|
its(:params) { should == {:controller => 'foo', :action => 'bar'} }
|
17
20
|
end
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
#TODO test somehow...
|
23
|
+
# describe '#tagify_links' do
|
24
|
+
# def tags_with(options)
|
25
|
+
# PaginationRenderer.new(template, options).tagify_links
|
26
|
+
# end
|
23
27
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
# context '1 page in total' do
|
29
|
+
# subject { tags_with :num_pages => 1, :current_page => 1 }
|
30
|
+
# it { should have(0).tags }
|
31
|
+
# end
|
28
32
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
33
|
+
# context '10 pages in total' do
|
34
|
+
# context 'first page' do
|
35
|
+
# subject { tags_with :num_pages => 10, :current_page => 1 }
|
36
|
+
# it { should_not contain_tag PrevLink }
|
37
|
+
# it { should contain_tag PrevSpan }
|
38
|
+
# it { should contain_tag CurrentPage }
|
39
|
+
# it { should_not contain_tag FirstPageLink }
|
40
|
+
# it { should contain_tag LastPageLink }
|
41
|
+
# it { should contain_tag PageLink }
|
42
|
+
# it { should contain_tag NextLink }
|
43
|
+
# it { should_not contain_tag NextSpan }
|
44
|
+
# it { should contain_tag TruncatedSpan }
|
45
|
+
# end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
# context 'second page' do
|
48
|
+
# subject { tags_with :num_pages => 10, :current_page => 2 }
|
49
|
+
# it { should contain_tag PrevLink }
|
50
|
+
# it { should_not contain_tag PrevSpan }
|
51
|
+
# it { should contain_tag CurrentPage }
|
52
|
+
# it { should contain_tag FirstPageLink }
|
53
|
+
# it { should contain_tag LastPageLink }
|
54
|
+
# it { should contain_tag PageLink }
|
55
|
+
# it { should contain_tag NextLink }
|
56
|
+
# it { should_not contain_tag NextSpan }
|
57
|
+
# it { should contain_tag TruncatedSpan }
|
58
|
+
# end
|
55
59
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
60
|
+
# context 'third page' do
|
61
|
+
# subject { tags_with :num_pages => 10, :current_page => 3 }
|
62
|
+
# it { should contain_tag PrevLink }
|
63
|
+
# it { should_not contain_tag PrevSpan }
|
64
|
+
# it { should contain_tag CurrentPage }
|
65
|
+
# it { should contain_tag FirstPageLink }
|
66
|
+
# it { should contain_tag LastPageLink }
|
67
|
+
# it { should contain_tag PageLink }
|
68
|
+
# it { should contain_tag NextLink }
|
69
|
+
# it { should_not contain_tag NextSpan }
|
70
|
+
# it { should contain_tag TruncatedSpan }
|
71
|
+
# end
|
68
72
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
73
|
+
# context 'fourth page(no truncation)' do
|
74
|
+
# subject { tags_with :num_pages => 10, :current_page => 4 }
|
75
|
+
# it { should contain_tag PrevLink }
|
76
|
+
# it { should_not contain_tag PrevSpan }
|
77
|
+
# it { should contain_tag CurrentPage }
|
78
|
+
# it { should contain_tag FirstPageLink }
|
79
|
+
# it { should contain_tag LastPageLink }
|
80
|
+
# it { should contain_tag PageLink }
|
81
|
+
# it { should contain_tag NextLink }
|
82
|
+
# it { should_not contain_tag NextSpan }
|
83
|
+
# it { should_not contain_tag TruncatedSpan }
|
84
|
+
# end
|
81
85
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
86
|
+
# context 'seventh page(no truncation)' do
|
87
|
+
# subject { tags_with :num_pages => 10, :current_page => 7 }
|
88
|
+
# it { should contain_tag PrevLink }
|
89
|
+
# it { should_not contain_tag PrevSpan }
|
90
|
+
# it { should contain_tag CurrentPage }
|
91
|
+
# it { should contain_tag FirstPageLink }
|
92
|
+
# it { should contain_tag LastPageLink }
|
93
|
+
# it { should contain_tag PageLink }
|
94
|
+
# it { should contain_tag NextLink }
|
95
|
+
# it { should_not contain_tag NextSpan }
|
96
|
+
# it { should_not contain_tag TruncatedSpan }
|
97
|
+
# end
|
94
98
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
99
|
+
# context 'eighth page' do
|
100
|
+
# subject { tags_with :num_pages => 10, :current_page => 8 }
|
101
|
+
# it { should contain_tag PrevLink }
|
102
|
+
# it { should_not contain_tag PrevSpan }
|
103
|
+
# it { should contain_tag CurrentPage }
|
104
|
+
# it { should contain_tag FirstPageLink }
|
105
|
+
# it { should contain_tag LastPageLink }
|
106
|
+
# it { should contain_tag PageLink }
|
107
|
+
# it { should contain_tag NextLink }
|
108
|
+
# it { should_not contain_tag NextSpan }
|
109
|
+
# it { should contain_tag TruncatedSpan }
|
110
|
+
# end
|
107
111
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
112
|
+
# context 'last page' do
|
113
|
+
# subject { tags_with :num_pages => 10, :current_page => 10 }
|
114
|
+
# it { should contain_tag PrevLink }
|
115
|
+
# it { should_not contain_tag PrevSpan }
|
116
|
+
# it { should contain_tag CurrentPage }
|
117
|
+
# it { should contain_tag FirstPageLink }
|
118
|
+
# it { should_not contain_tag LastPageLink }
|
119
|
+
# it { should contain_tag PageLink }
|
120
|
+
# it { should_not contain_tag NextLink }
|
121
|
+
# it { should contain_tag NextSpan }
|
122
|
+
# it { should contain_tag TruncatedSpan }
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
# end
|
122
126
|
end
|
data/spec/helpers/tags_spec.rb
CHANGED
@@ -44,4 +44,115 @@ describe 'Kaminari::Helpers' do
|
|
44
44
|
its(:ancestor_renderables) { should == [NextSpan, Next, NonLink] }
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
describe 'Paginator' do
|
49
|
+
describe 'Paginator::PageProxy' do
|
50
|
+
describe '#current?' do
|
51
|
+
context 'current_page == page' do
|
52
|
+
subject { Paginator::PageProxy.new({:current_page => 26}, 26, nil) }
|
53
|
+
its(:current?) { should be_true }
|
54
|
+
end
|
55
|
+
context 'current_page != page' do
|
56
|
+
subject { Paginator::PageProxy.new({:current_page => 13}, 26, nil) }
|
57
|
+
its(:current?) { should_not be_true }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe '#first?' do
|
62
|
+
context 'page == 1' do
|
63
|
+
subject { Paginator::PageProxy.new({:current_page => 26}, 1, nil) }
|
64
|
+
its(:first?) { should be_true }
|
65
|
+
end
|
66
|
+
context 'page != 1' do
|
67
|
+
subject { Paginator::PageProxy.new({:current_page => 13}, 2, nil) }
|
68
|
+
its(:first?) { should_not be_true }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#last?' do
|
73
|
+
context 'current_page == page' do
|
74
|
+
subject { Paginator::PageProxy.new({:num_pages => 39}, 39, nil) }
|
75
|
+
its(:last?) { should be_true }
|
76
|
+
end
|
77
|
+
context 'current_page != page' do
|
78
|
+
subject { Paginator::PageProxy.new({:num_pages => 39}, 38, nil) }
|
79
|
+
its(:last?) { should_not be_true }
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#left_outer?' do
|
84
|
+
context 'current_page == left' do
|
85
|
+
subject { Paginator::PageProxy.new({:left => 3}, 3, nil) }
|
86
|
+
its(:left_outer?) { should be_true }
|
87
|
+
end
|
88
|
+
context 'current_page == left + 1' do
|
89
|
+
subject { Paginator::PageProxy.new({:left => 3}, 4, nil) }
|
90
|
+
its(:left_outer?) { should be_true }
|
91
|
+
end
|
92
|
+
context 'current_page == left + 2' do
|
93
|
+
subject { Paginator::PageProxy.new({:left => 3}, 5, nil) }
|
94
|
+
its(:left_outer?) { should_not be_true }
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#right_outer?' do
|
99
|
+
context 'num_pages - page > right' do
|
100
|
+
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 6, nil) }
|
101
|
+
its(:right_outer?) { should_not be_true }
|
102
|
+
end
|
103
|
+
context 'num_pages - page == right' do
|
104
|
+
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 7, nil) }
|
105
|
+
its(:right_outer?) { should be_true }
|
106
|
+
end
|
107
|
+
context 'num_pages - page < right' do
|
108
|
+
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 8, nil) }
|
109
|
+
its(:right_outer?) { should be_true }
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#inside_window?' do
|
114
|
+
context 'page > current_page' do
|
115
|
+
context 'page - current_page > window' do
|
116
|
+
subject { Paginator::PageProxy.new({:current_page => 4, :window => 5}, 10, nil) }
|
117
|
+
its(:inside_window?) { should_not be_true }
|
118
|
+
end
|
119
|
+
context 'page - current_page == window' do
|
120
|
+
subject { Paginator::PageProxy.new({:current_page => 4, :window => 6}, 10, nil) }
|
121
|
+
its(:inside_window?) { should be_true }
|
122
|
+
end
|
123
|
+
context 'page - current_page < window' do
|
124
|
+
subject { Paginator::PageProxy.new({:current_page => 4, :window => 7}, 10, nil) }
|
125
|
+
its(:inside_window?) { should be_true }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
context 'current_page > page' do
|
129
|
+
context 'current_page - page > window' do
|
130
|
+
subject { Paginator::PageProxy.new({:current_page => 15, :window => 4}, 10, nil) }
|
131
|
+
its(:inside_window?) { should_not be_true }
|
132
|
+
end
|
133
|
+
context 'current_page - page == window' do
|
134
|
+
subject { Paginator::PageProxy.new({:current_page => 15, :window => 5}, 10, nil) }
|
135
|
+
its(:inside_window?) { should be_true }
|
136
|
+
end
|
137
|
+
context 'current_page - page < window' do
|
138
|
+
subject { Paginator::PageProxy.new({:current_page => 15, :window => 6}, 10, nil) }
|
139
|
+
its(:inside_window?) { should be_true }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
describe '#was_truncated?' do
|
144
|
+
before do
|
145
|
+
stub(@template = Object.new).options { {} }
|
146
|
+
end
|
147
|
+
context 'last.is_a? TruncatedSpan' do
|
148
|
+
subject { Paginator::PageProxy.new({}, 10, TruncatedSpan.new(@template)) }
|
149
|
+
its(:was_truncated?) { should be_true }
|
150
|
+
end
|
151
|
+
context 'last.is not a TruncatedSpan' do
|
152
|
+
subject { Paginator::PageProxy.new({}, 10, PageLink.new(@template)) }
|
153
|
+
its(:was_truncated?) { should_not be_true }
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
47
158
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kaminari
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 35
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 12
|
10
|
+
version: 0.9.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Akira Matsuda
|