Class: Kaminari::Helpers::Paginator
- Includes:
- ActionView::Context
- 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, 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, options) ⇒ Paginator
:nodoc:
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kaminari/helpers/paginator.rb', line 14 def initialize(template, ) #:nodoc: @window_options = {}.tap do |h| h[:window] = .delete(:window) || .delete(:inner_window) || Kaminari.config.window outer_window = .delete(:outer_window) || Kaminari.config.outer_window h[:left] = .delete(:left) || Kaminari.config.left h[:left] = outer_window if h[:left] == 0 h[:right] = .delete(:right) || Kaminari.config.right h[:right] = outer_window if h[:right] == 0 end @template, @options = template, @theme = @options[:theme] ? "#{@options[:theme]}/" : '' @options[:current_page] = PageProxy.new @window_options.merge(@options), @options[:current_page], nil #FIXME for compatibility. remove num_pages at some time in the future @options[:total_pages] ||= @options[:num_pages] @last = nil # initialize the output_buffer for Context @output_buffer = ActionView::OutputBuffer.new 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
45 46 47 48 49 50 51 |
# File 'lib/kaminari/helpers/paginator.rb', line 45 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 |
#page_tag(page) ⇒ Object
63 64 65 |
# File 'lib/kaminari/helpers/paginator.rb', line 63 def page_tag(page) @last = Page.new @template, @options.merge(:page => page) end |
#render(&block) ⇒ Object
render given block as a view template
34 35 36 37 |
# File 'lib/kaminari/helpers/paginator.rb', line 34 def render(&block) instance_eval(&block) if @options[:total_pages] > 1 @output_buffer end |
#to_s ⇒ Object
:nodoc:
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/kaminari/helpers/paginator.rb', line 75 def to_s #:nodoc: subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber} return super @window_options.merge(@options).merge :paginator => self unless subscriber # dirty hack to suppress logging render_partial class << subscriber alias_method :render_partial_with_logging, :render_partial # do nothing def render_partial(event); end end ret = super @window_options.merge(@options).merge :paginator => self class << subscriber alias_method :render_partial, :render_partial_with_logging undef :render_partial_with_logging end ret end |