2011-02-20 13:04:18 +09:00
|
|
|
module Kaminari
|
|
|
|
module PageScopeMethods
|
2011-12-12 00:14:52 +09:00
|
|
|
# Specify the <tt>per_page</tt> value for the preceding <tt>page</tt> scope
|
|
|
|
# Model.page(3).per(10)
|
|
|
|
def per(num)
|
|
|
|
if (n = num.to_i) <= 0
|
|
|
|
self
|
|
|
|
else
|
|
|
|
limit(n).offset(offset_value / limit_value * n)
|
2011-02-20 13:04:18 +09:00
|
|
|
end
|
2011-12-12 00:14:52 +09:00
|
|
|
end
|
2011-02-20 13:04:18 +09:00
|
|
|
|
2011-12-12 00:14:52 +09:00
|
|
|
def padding(num)
|
|
|
|
offset(offset_value + num.to_i)
|
|
|
|
end
|
2011-03-14 10:14:14 -07:00
|
|
|
|
2011-12-12 00:14:52 +09:00
|
|
|
# Total number of pages
|
2012-05-25 15:31:53 +09:00
|
|
|
def total_pages
|
2011-12-12 00:14:52 +09:00
|
|
|
(total_count.to_f / limit_value).ceil
|
|
|
|
end
|
2011-02-20 13:04:18 +09:00
|
|
|
|
2011-12-12 00:14:52 +09:00
|
|
|
# Current page number
|
|
|
|
def current_page
|
|
|
|
(offset_value / limit_value) + 1
|
|
|
|
end
|
2011-03-05 19:32:15 +01:00
|
|
|
|
2011-12-12 00:14:52 +09:00
|
|
|
# First page of the collection ?
|
|
|
|
def first_page?
|
|
|
|
current_page == 1
|
|
|
|
end
|
2011-03-05 19:32:15 +01:00
|
|
|
|
2011-12-12 00:14:52 +09:00
|
|
|
# Last page of the collection?
|
|
|
|
def last_page?
|
2012-05-25 15:31:53 +09:00
|
|
|
current_page >= total_pages
|
2011-02-20 13:04:18 +09:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|