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_page ⇒ Object
enumerate each page providing PageProxy object as the block parameter.
-
#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:
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/kaminari/helpers/paginator.rb', line 11 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 # initialize the output_buffer for Context @output_buffer = ActionView::OutputBuffer.new end |
Instance Method Details
#each_page ⇒ Object
enumerate each page providing PageProxy object as the block parameter
34 35 36 37 38 39 40 |
# File 'lib/kaminari/helpers/paginator.rb', line 34 def each_page return to_enum(:each_page) unless block_given? 1.upto(@options[:num_pages]) do |i| yield PageProxy.new(@window_options.merge(@options), i, @last) end end |
#page_tag(page) ⇒ Object
42 43 44 |
# File 'lib/kaminari/helpers/paginator.rb', line 42 def page_tag(page) @last = Page.new @template, @options.merge(:page => page) end |
#render(&block) ⇒ Object
render given block as a view template
28 29 30 31 |
# File 'lib/kaminari/helpers/paginator.rb', line 28 def render(&block) instance_eval &block if @options[:num_pages] > 1 @output_buffer end |
#to_s ⇒ Object
:nodoc:
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/kaminari/helpers/paginator.rb', line 54 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 |