class Kaminari::Helpers::Paginator
The main container tag
Public Instance Methods
each_relevant_page() { |page_proxy| ... }
click to toggle source
enumerate each page providing PageProxy object as the block parameter Because of performance reason, this doesn't actually enumerate all pages but pages that are seemingly relevant to the paginator. “Relevant” pages are:
-
pages inside the left outer window plus one for showing the gap tag
-
pages inside the inner window plus one on the left plus one on the right for showing the gap tags
-
pages inside the right outer window plus one for showing the gap tag
# File lib/kaminari/helpers/paginator.rb, line 49 def each_relevant_page return to_enum(:each_relevant_page) unless block_given? relevant_pages(@window_options).each do |i| yield PageProxy.new(@window_options, i, @last) end end
Also aliased as: each_page
page_tag(page)
click to toggle source
# File lib/kaminari/helpers/paginator.rb, line 67 def page_tag(page) @last = Page.new @template, @options.merge(:page => page) end
render(&block)
click to toggle source
render given block as a view template
# File lib/kaminari/helpers/paginator.rb, line 38 def render(&block) instance_eval(&block) if @options[:total_pages] > 1 @output_buffer end
Private Instance Methods
relevant_pages(options)
click to toggle source
# File lib/kaminari/helpers/paginator.rb, line 58 def relevant_pages(options) left_window_plus_one = 1.upto(options[:left] + 1).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[:total_pages])} end