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 43 def each_relevant_page return to_enum(:each_relevant_page) unless block_given? relevant_pages(@window_options).each do |page| yield PageProxy.new(@window_options, page, @last) end end
Also aliased as: each_page
page_tag(page)
click to toggle source
# File lib/kaminari/helpers/paginator.rb, line 61 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 28 def render(&block) instance_eval(&block) if @options[:total_pages] > 1 # This allows for showing fall-back HTML when there's only one page: # # <%= paginate(@search_results) || "Showing all search results" %> @output_buffer.presence end
Private Instance Methods
method_missing(name, *args, &block)
click to toggle source
delegates view helper methods to @template
Calls superclass method
# File lib/kaminari/helpers/paginator.rb, line 81 def method_missing(name, *args, &block) @template.respond_to?(name) ? @template.send(name, *args, &block) : super end
relevant_pages(options)
click to toggle source
# File lib/kaminari/helpers/paginator.rb, line 52 def relevant_pages(options) left_window_plus_one = [*1..options[:left] + 1] right_window_plus_one = [*options[:total_pages] - options[:right]..options[:total_pages]] inside_window_plus_each_sides = [*options[:current_page] - options[:window] - 1..options[:current_page] + options[:window] + 1] (left_window_plus_one | inside_window_plus_each_sides | right_window_plus_one).sort.reject {|x| (x < 1) || (x > options[:total_pages])} end