num_pages => total_pages

This commit is contained in:
Akira Matsuda 2012-05-25 15:31:53 +09:00
parent 1f8389ae8f
commit e79935c2d5
33 changed files with 90 additions and 89 deletions

View File

@ -2,7 +2,7 @@
- available local variables
url: url to the first page
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>

View File

@ -2,7 +2,7 @@
-# available local variables
-# url: url to the first page
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.first

View File

@ -2,7 +2,7 @@
- available local variables
url : url to the first page
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.first

View File

@ -1,7 +1,7 @@
<%# Non-link tag that stands for skipped pages...
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>

View File

@ -1,7 +1,7 @@
-# Non-link tag that stands for skipped pages...
-# available local variables
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.page.gap

View File

@ -1,7 +1,7 @@
/ Non-link tag that stands for skipped pages...
- available local variables
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.page.gap

View File

@ -2,7 +2,7 @@
- available local variables
url: url to the last page
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>

View File

@ -2,7 +2,7 @@
-# available local variables
-# url: url to the last page
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.last

View File

@ -2,7 +2,7 @@
- available local variables
url : url to the last page
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.last

View File

@ -2,7 +2,7 @@
- available local variables
url: url to the next page
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>

View File

@ -2,7 +2,7 @@
-# available local variables
-# url: url to the next page
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.next

View File

@ -2,7 +2,7 @@
- available local variables
url : url to the next page
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.next

View File

@ -3,10 +3,11 @@
page: a page object for "this" page
url: url to this page
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>
<%= p total_pages %>
<span class="page<%= ' current' if page.current? %>">
<%= link_to_unless page.current?, page, url, opts = {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
</span>

View File

@ -3,7 +3,7 @@
-# page: a page object for "this" page
-# url: url to this page
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span{:class => "page#{' current' if page.current?}"}

View File

@ -3,7 +3,7 @@
page : a page object for "this" page
url : url to this page
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span class="page#{' current' if page.current?}"

View File

@ -1,7 +1,7 @@
<%# The container tag
- available local variables
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
paginator: the paginator that renders the pagination tags inside

View File

@ -1,7 +1,7 @@
-# The container tag
-# available local variables
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
-# paginator: the paginator that renders the pagination tags inside

View File

@ -1,7 +1,7 @@
/ The container tag
- available local variables
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
paginator : the paginator that renders the pagination tags inside

View File

@ -2,7 +2,7 @@
- available local variables
url: url to the previous page
current_page: a page object for the currently displayed page
num_pages: total number of pages
total_pages: total number of pages
per_page: number of items to fetch per page
remote: data-remote
-%>

View File

@ -2,7 +2,7 @@
-# available local variables
-# url: url to the previous page
-# current_page: a page object for the currently displayed page
-# num_pages: total number of pages
-# total_pages: total number of pages
-# per_page: number of items to fetch per page
-# remote: data-remote
%span.prev

View File

@ -2,7 +2,7 @@
- available local variables
url : url to the previous page
current_page : a page object for the currently displayed page
num_pages : total number of pages
total_pages : total number of pages
per_page : number of items to fetch per page
remote : data-remote
span.prev

View File

@ -15,7 +15,7 @@ module Kaminari
# * <tt>:remote</tt> - Ajax? (false by default)
# * <tt>:ANY_OTHER_VALUES</tt> - Any other hash key & values would be directly passed into each tag as :locals value.
def paginate(scope, options = {}, &block)
paginator = Kaminari::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
paginator = Kaminari::Helpers::Paginator.new self, options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
paginator.to_s
end
@ -101,7 +101,7 @@ module Kaminari
end
entry_name = entry_name.pluralize unless collection.total_count == 1
if collection.num_pages < 2
if collection.total_pages < 2
t('helpers.page_entries_info.one_page.display_entries', :entry_name => entry_name, :count => collection.total_count)
else
first = collection.offset_value + 1

View File

@ -29,7 +29,7 @@ module Kaminari
# render given block as a view template
def render(&block)
instance_eval(&block) if @options[:num_pages] > 1
instance_eval(&block) if @options[:total_pages] > 1
@output_buffer
end
@ -50,10 +50,10 @@ module Kaminari
def relevant_pages(options)
left_window_plus_one = 1.upto(options[:left] + 1).to_a
right_window_plus_one = (options[:num_pages] - options[:right]).upto(options[:num_pages]).to_a
right_window_plus_one = (options[:total_pages] - options[:right]).upto(options[:total_pages]).to_a
inside_window_plus_each_sides = (options[:current_page] - options[:window] - 1).upto(options[:current_page] + options[:window] + 1).to_a
(left_window_plus_one + inside_window_plus_each_sides + right_window_plus_one).uniq.sort.reject {|x| (x < 1) || (x > options[:num_pages])}
(left_window_plus_one + inside_window_plus_each_sides + right_window_plus_one).uniq.sort.reject {|x| (x < 1) || (x > options[:total_pages])}
end
private :relevant_pages
@ -114,7 +114,7 @@ module Kaminari
# the last page or not
def last?
@page == @options[:num_pages]
@page == @options[:total_pages]
end
# the previous page or not
@ -134,7 +134,7 @@ module Kaminari
# within the right outer window or not
def right_outer?
@options[:num_pages] - @page < @options[:right]
@options[:total_pages] - @page < @options[:right]
end
# inside the inner window or not

View File

@ -82,7 +82,7 @@ module Kaminari::Helpers
current_params = Rack::Utils.parse_query(env['QUERY_STRING']).symbolize_keys rescue {}
paginator = Kaminari::Helpers::Paginator.new(
ActionViewTemplateProxy.new(:current_params => current_params, :current_path => current_path, :param_name => options[:param_name] || Kaminari.config.param_name),
options.reverse_merge(:current_page => scope.current_page, :num_pages => scope.num_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
options.reverse_merge(:current_page => scope.current_page, :total_pages => scope.total_pages, :per_page => scope.limit_value, :param_name => Kaminari.config.param_name, :remote => false)
)
paginator.to_s
end

View File

@ -68,7 +68,7 @@ module Kaminari
class LastPage < Tag
include Link
def page #:nodoc:
@options[:num_pages]
@options[:total_pages]
end
end

View File

@ -15,7 +15,7 @@ module Kaminari
end
# Total number of pages
def num_pages
def total_pages
(total_count.to_f / limit_value).ceil
end
@ -31,7 +31,7 @@ module Kaminari
# Last page of the collection?
def last_page?
current_page >= num_pages
current_page >= total_pages
end
end
end

View File

@ -35,13 +35,13 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context '1 page in total' do
# subject { tags_with :num_pages => 1, :current_page => 1 }
# subject { tags_with :total_pages => 1, :current_page => 1 }
# it { should have(0).tags }
# end
# context '10 pages in total' do
# context 'first page' do
# subject { tags_with :num_pages => 10, :current_page => 1 }
# subject { tags_with :total_pages => 10, :current_page => 1 }
# it { should_not contain_tag PrevLink }
# it { should contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -54,7 +54,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'second page' do
# subject { tags_with :num_pages => 10, :current_page => 2 }
# subject { tags_with :total_pages => 10, :current_page => 2 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -67,7 +67,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'third page' do
# subject { tags_with :num_pages => 10, :current_page => 3 }
# subject { tags_with :total_pages => 10, :current_page => 3 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -80,7 +80,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'fourth page(no truncation)' do
# subject { tags_with :num_pages => 10, :current_page => 4 }
# subject { tags_with :total_pages => 10, :current_page => 4 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -93,7 +93,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'seventh page(no truncation)' do
# subject { tags_with :num_pages => 10, :current_page => 7 }
# subject { tags_with :total_pages => 10, :current_page => 7 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -106,7 +106,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'eighth page' do
# subject { tags_with :num_pages => 10, :current_page => 8 }
# subject { tags_with :total_pages => 10, :current_page => 8 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }
@ -119,7 +119,7 @@ describe 'Kaminari::Helpers::Paginator' do
# end
# context 'last page' do
# subject { tags_with :num_pages => 10, :current_page => 10 }
# subject { tags_with :total_pages => 10, :current_page => 10 }
# it { should contain_tag PrevLink }
# it { should_not contain_tag PrevSpan }
# it { should contain_tag CurrentPage }

View File

@ -28,11 +28,11 @@ describe 'Kaminari::Helpers' do
describe '#last?' do
context 'current_page == page' do
subject { Paginator::PageProxy.new({:num_pages => 39}, 39, nil) }
subject { Paginator::PageProxy.new({:total_pages => 39}, 39, nil) }
its(:last?) { should be_true }
end
context 'current_page != page' do
subject { Paginator::PageProxy.new({:num_pages => 39}, 38, nil) }
subject { Paginator::PageProxy.new({:total_pages => 39}, 38, nil) }
its(:last?) { should_not be_true }
end
end
@ -75,16 +75,16 @@ describe 'Kaminari::Helpers' do
end
describe '#right_outer?' do
context 'num_pages - page > right' do
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 6, nil) }
context 'total_pages - page > right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 6, nil) }
its(:right_outer?) { should_not be_true }
end
context 'num_pages - page == right' do
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 7, nil) }
context 'total_pages - page == right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 7, nil) }
its(:right_outer?) { should_not be_true }
end
context 'num_pages - page < right' do
subject { Paginator::PageProxy.new({:num_pages => 10, :right => 3}, 8, nil) }
context 'total_pages - page < right' do
subject { Paginator::PageProxy.new({:total_pages => 10, :right => 3}, 8, nil) }
its(:right_outer?) { should be_true }
end
end

View File

@ -68,35 +68,35 @@ if defined? ActiveRecord
end
end
describe '#num_pages' do
describe '#total_pages' do
context 'per 25 (default)' do
subject { model_class.page }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per 7' do
subject { model_class.page(2).per(7) }
its(:num_pages) { should == 15 }
its(:total_pages) { should == 15 }
end
context 'per 65536' do
subject { model_class.page(50).per(65536) }
its(:num_pages) { should == 1 }
its(:total_pages) { should == 1 }
end
context 'per 0 (using default)' do
subject { model_class.page(50).per(0) }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per -1 (using default)' do
subject { model_class.page(5).per(-1) }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per "String value that can not be converted into Number" (using default)' do
subject { model_class.page(5).per('aho') }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
end
@ -153,7 +153,7 @@ if defined? ActiveRecord
subject { model_class.group('age').page(2).per 5 }
# 0..10
its(:total_count) { should == 11 }
its(:num_pages) { should == 3 }
its(:total_pages) { should == 3 }
end
context 'activerecord descendants' do

View File

@ -56,35 +56,35 @@ describe Kaminari::PaginatableArray do
end
end
describe '#num_pages' do
describe '#total_pages' do
context 'per 25 (default)' do
subject { array.page }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per 7' do
subject { array.page(2).per(7) }
its(:num_pages) { should == 15 }
its(:total_pages) { should == 15 }
end
context 'per 65536' do
subject { array.page(50).per(65536) }
its(:num_pages) { should == 1 }
its(:total_pages) { should == 1 }
end
context 'per 0 (using default)' do
subject { array.page(50).per(0) }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per -1 (using default)' do
subject { array.page(5).per(-1) }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'per "String value that can not be converted into Number" (using default)' do
subject { array.page(5).per('aho') }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
end

View File

@ -35,7 +35,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == User.count(:age.gte => 60) }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
end
context 'page 1' do
@ -45,7 +45,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 100 }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'page 2' do
@ -56,7 +56,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == 100 }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'page "foobar"' do
@ -66,7 +66,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 0 }
its(:total_count) { should == 100 }
its(:num_pages) { should == 4 }
its(:total_pages) { should == 4 }
end
context 'with criteria before' do
@ -76,7 +76,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
end
context 'with criteria after' do
@ -86,7 +86,7 @@ if defined? DataMapper
its('query.limit') { should == 25 }
its('query.offset') { should == 25 }
its(:total_count) { should == User.count(:age.gt => 60) }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
end
end
@ -99,7 +99,7 @@ if defined? DataMapper
its(:limit_value) { should == 20 }
its('query.offset') { should == 20 }
its(:total_count) { should == 100 }
its(:num_pages) { should == 5 }
its(:total_pages) { should == 5 }
end
context 'on query with condition' do
@ -108,7 +108,7 @@ if defined? DataMapper
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:num_pages) { should == 7 }
its(:total_pages) { should == 7 }
end
context 'on query with order' do
@ -121,7 +121,7 @@ if defined? DataMapper
its('query.limit') { should == 13 }
its('query.offset') { should == 52 }
its(:total_count) { should == 81 }
its(:num_pages) { should == 7 }
its(:total_pages) { should == 7 }
end
context 'on chained queries' do
@ -130,7 +130,7 @@ if defined? DataMapper
its('query.limit') { should == 13 }
its('query.offset') { should == 26 }
its(:total_count) { should == 31 }
its(:num_pages) { should == 3 }
its(:total_pages) { should == 3 }
end
context 'on query on association' do
@ -139,7 +139,7 @@ if defined? DataMapper
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 50 }
its(:num_pages) { should == 10 }
its(:total_pages) { should == 10 }
end
context 'on query with association conditions' do
@ -148,7 +148,7 @@ if defined? DataMapper
its('query.limit') { should == 5 }
its('query.offset') { should == 10 }
its(:total_count) { should == 50 }
its(:num_pages) { should == 10 }
its(:total_pages) { should == 10 }
end
end
end

View File

@ -13,7 +13,7 @@ if defined? MongoMapper
it { should be_a Plucky::Query }
its(:current_page) { should == 1 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip(0) }
end
@ -22,7 +22,7 @@ if defined? MongoMapper
it { should be_a Plucky::Query }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
@ -31,7 +31,7 @@ if defined? MongoMapper
it { should be_a Plucky::Query }
its(:current_page) { should == 1 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 0 }
end
@ -43,7 +43,7 @@ if defined? MongoMapper
subject { User.where(:salary => 1).page 2 }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
@ -55,7 +55,7 @@ if defined? MongoMapper
subject { User.page(2).where(:salary => 1) }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
end
@ -65,7 +65,7 @@ if defined? MongoMapper
it { should be_a Plucky::Query }
its(:current_page) { should == 2 }
its(:limit_value) { should == 10 }
its(:num_pages) { should == 5 }
its(:total_pages) { should == 5 }
it { should skip 10 }
end
end

View File

@ -15,7 +15,7 @@ if defined? Mongoid
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip(0) }
end
@ -24,7 +24,7 @@ if defined? Mongoid
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
@ -33,7 +33,7 @@ if defined? Mongoid
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 1 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 0 }
end
@ -45,7 +45,7 @@ if defined? Mongoid
end
its(:current_page) { should == 2 }
its(:limit_value) { should == 25 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
it { should skip 25 }
end
@ -65,7 +65,7 @@ if defined? Mongoid
it { should be_a Mongoid::Criteria }
its(:current_page) { should == 2 }
its(:limit_value) { should == 10 }
its(:num_pages) { should == 5 }
its(:total_pages) { should == 5 }
it { should skip 10 }
end
@ -85,7 +85,7 @@ if defined? Mongoid
its(:total_count) { should == 5 }
its(:limit_value) { should == 1 }
its(:current_page) { should == 1 }
its(:num_pages) { should == 5 }
its(:total_pages) { should == 5 }
end
context 'with criteria after' do
@ -94,7 +94,7 @@ if defined? Mongoid
its(:total_count) { should == 3 }
its(:limit_value) { should == 2 }
its(:current_page) { should == 1 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
end
context 'with criteria before' do
@ -103,7 +103,7 @@ if defined? Mongoid
its(:total_count) { should == 3 }
its(:limit_value) { should == 2 }
its(:current_page) { should == 1 }
its(:num_pages) { should == 2 }
its(:total_pages) { should == 2 }
end
end
end