mirror of
https://github.com/kaminari/kaminari.git
synced 2022-11-09 13:44:37 -05:00
Merge branch 'master' of https://github.com/cbeer/kaminari into cbeer-master
This commit is contained in:
commit
a54c3ce466
1 changed files with 33 additions and 0 deletions
|
@ -11,6 +11,31 @@ module Kaminari
|
|||
# so that this instance can actually "render"
|
||||
include ::ActionView::Context
|
||||
|
||||
module Windows
|
||||
def relevant_pages options
|
||||
[left_window(options), inside_window(options), right_window(options)].map(&:to_a).flatten.uniq.sort.reject { |x| x < 1 or x > options[:num_pages] }
|
||||
end
|
||||
|
||||
def all_pages options
|
||||
1.upto(options[:num_pages])
|
||||
end
|
||||
|
||||
protected
|
||||
def left_window options
|
||||
1.upto(options[:left] + 1)
|
||||
end
|
||||
|
||||
def right_window options
|
||||
(options[:num_pages] - options[:right]).upto(options[:num_pages])
|
||||
end
|
||||
|
||||
def inside_window options
|
||||
(options[:current_page] - options[:window]).upto(options[:current_page] + options[:window])
|
||||
end
|
||||
end
|
||||
|
||||
include Windows
|
||||
|
||||
def initialize(template, options) #:nodoc:
|
||||
@window_options = {}.tap do |h|
|
||||
h[:window] = options.delete(:window) || options.delete(:inner_window) || Kaminari.config.window
|
||||
|
@ -42,6 +67,14 @@ module Kaminari
|
|||
end
|
||||
end
|
||||
|
||||
def each_relevant_page
|
||||
return to_enum(:each_relevant_page) unless block_given?
|
||||
|
||||
relevant_pages(@window_options.merge(@options)).each do |i|
|
||||
yield PageProxy.new(@window_options.merge(@options), i, @last)
|
||||
end
|
||||
end
|
||||
|
||||
def page_tag(page)
|
||||
@last = Page.new @template, @options.merge(:page => page)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue