module PassionView::Paginable
Constants
- DEFAULT_PER_PAGE
Attributes
current_page[RW]
current_per[RW]
Public Class Methods
new(items, options = {})
click to toggle source
Calls superclass method
# File lib/passion_view/paginable.rb, line 10 def initialize(items, options = {}) super pagination = options.delete(:pagination) || {} paginate_with(pagination[:page], pagination[:per]) end
Public Instance Methods
current_page?(page)
click to toggle source
# File lib/passion_view/paginable.rb, line 39 def current_page?(page) page.to_i == current_page end
first_page()
click to toggle source
# File lib/passion_view/paginable.rb, line 43 def first_page 1 end
first_page?(page = nil)
click to toggle source
# File lib/passion_view/paginable.rb, line 29 def first_page?(page = nil) page ||= current_page page.to_i == first_page end
first_page_path()
click to toggle source
# File lib/passion_view/paginable.rb, line 67 def first_page_path paginable_path(page: first_page) end
items()
click to toggle source
Calls superclass method
# File lib/passion_view/paginable.rb, line 17 def items super.page(current_page) .per(current_per) end
last_page()
click to toggle source
# File lib/passion_view/paginable.rb, line 59 def last_page [items.total_pages, 1].max end
last_page?(page = nil)
click to toggle source
# File lib/passion_view/paginable.rb, line 34 def last_page?(page = nil) page ||= current_page page.to_i == last_page end
last_page_path()
click to toggle source
# File lib/passion_view/paginable.rb, line 79 def last_page_path paginable_path(page: last_page) end
next_page(shift = 1)
click to toggle source
# File lib/passion_view/paginable.rb, line 51 def next_page(shift = 1) target = current_page + shift target = first_page if target < first_page target = last_page if target > last_page target end
next_page_path(shift = 1)
click to toggle source
# File lib/passion_view/paginable.rb, line 75 def next_page_path(shift = 1) paginable_path(page: next_page(shift)) end
next_pages(count = 2) { |target, next_page_path(idx)| ... }
click to toggle source
# File lib/passion_view/paginable.rb, line 22 def next_pages(count = 2) (-count..count).each do |idx| target = current_page + idx yield target, next_page_path(idx) if block_given? && !out_of_range?(target) end end
out_of_range?(target)
click to toggle source
# File lib/passion_view/paginable.rb, line 63 def out_of_range?(target) (target < first_page) || (target > last_page) end
page_path(options = {})
click to toggle source
# File lib/passion_view/paginable.rb, line 87 def page_path(options = {}) options end
paginable_params(page = nil, per = nil)
click to toggle source
# File lib/passion_view/paginable.rb, line 95 def paginable_params(page = nil, per = nil) params = {} page ||= current_page per ||= current_per params[:page] = page unless page == first_page params[:per] = per unless per.nil? || per == DEFAULT_PER_PAGE params end
paginable_path(options)
click to toggle source
# File lib/passion_view/paginable.rb, line 83 def paginable_path(options) page_path(url_options.merge(options)) end
paginate_with(page, per = nil)
click to toggle source
# File lib/passion_view/paginable.rb, line 106 def paginate_with(page, per = nil) self.current_page = page.nil? ? 1 : page.to_i self.current_per = per.nil? ? DEFAULT_PER_PAGE : per.to_i end
previous_page()
click to toggle source
# File lib/passion_view/paginable.rb, line 47 def previous_page next_page(-1) end
previous_page_path()
click to toggle source
# File lib/passion_view/paginable.rb, line 71 def previous_page_path paginable_path(page: previous_page) end
url_options()
click to toggle source
Calls superclass method
PassionView::Pathable#url_options
# File lib/passion_view/paginable.rb, line 91 def url_options super.merge(paginable_params) end