Class: Kaminari::Helpers::Paginator
- Defined in:
- lib/kaminari/helpers/paginator.rb
Overview
The main container tag
Defined Under Namespace
Classes: PageProxy
Instance Method Summary collapse
-
#each_relevant_page ⇒ Object
(also: #each_page)
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.
-
#initialize(template, window: nil, outer_window: nil, left: nil, right: nil, inner_window: nil, **options) ⇒ Paginator
constructor
:nodoc:.
- #page_tag(page) ⇒ Object
-
#render(&block) ⇒ Object
render given block as a view template.
-
#to_s ⇒ Object
:nodoc:.
Methods inherited from Tag
Constructor Details
#initialize(template, window: nil, outer_window: nil, left: nil, right: nil, inner_window: nil, **options) ⇒ Paginator
:nodoc:
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/kaminari/helpers/paginator.rb', line 9 def initialize(template, window: nil, outer_window: nil, left: nil, right: nil, inner_window: nil, **) #:nodoc: outer_window ||= Kaminari.config.outer_window left ||= Kaminari.config.left right ||= Kaminari.config.right @window_options = {window: window || inner_window || Kaminari.config.window, left: left.zero? ? outer_window : left, right: right.zero? ? outer_window : right} @template, @options, @theme, @views_prefix, @last = template, , [:theme], [:views_prefix], nil @window_options.merge! @options @window_options[:current_page] = @options[:current_page] = PageProxy.new(@window_options, @options[:current_page], nil) #XXX Using parent template's buffer class for rendering each partial here. This might cause problems if the handler mismatches @output_buffer = if defined?(::ActionView::OutputBuffer) ::ActionView::OutputBuffer.new elsif template.instance_variable_get(:@output_buffer) template.instance_variable_get(:@output_buffer).class.new else ActiveSupport::SafeBuffer.new end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
delegates view helper methods to @template
79 80 81 |
# File 'lib/kaminari/helpers/paginator.rb', line 79 def method_missing(name, *args, &block) @template.respond_to?(name) ? @template.send(name, *args, &block) : super end |
Instance Method Details
#each_relevant_page ⇒ Object Also known as: each_page
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
41 42 43 44 45 46 47 |
# File 'lib/kaminari/helpers/paginator.rb', line 41 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 |
#page_tag(page) ⇒ Object
59 60 61 |
# File 'lib/kaminari/helpers/paginator.rb', line 59 def page_tag(page) @last = Page.new @template, @options.merge(page: page) end |
#render(&block) ⇒ Object
render given block as a view template
30 31 32 33 |
# File 'lib/kaminari/helpers/paginator.rb', line 30 def render(&block) instance_eval(&block) if @options[:total_pages] > 1 @output_buffer end |
#to_s ⇒ Object
:nodoc:
71 72 73 74 75 76 |
# File 'lib/kaminari/helpers/paginator.rb', line 71 def to_s #:nodoc: Thread.current[:kaminari_rendering] = true super @window_options.merge paginator: self ensure Thread.current[:kaminari_rendering] = false end |