class Pading::Actionview::Paginator

Public Class Methods

new(template, **options) click to toggle source
# File lib/pading/actionview/paginator.rb, line 8
def initialize(template, **options)
  @template = template
  @options = options
  @options[:current_page] = PageProxy.new(@options, options[:current_page_number])
  #
  # undefined method `safe_append='
  # 允许写 多个 <% %>
  @output_buffer = if defined?(::ActionView::OutputBuffer)
                     ::ActionView::OutputBuffer.new
                   elsif template.instance_variable_get(:@output_buffer)
                     # instance_variable_get 获取并返回对象的实例变量的值。 如果未定义实例变量,则返回nil
                     template.instance_variable_get(:@output_buffer).class.new
                   else
                     ActiveSupport::SafeBuffer.new
                   end
end

Public Instance Methods

each_page() { |page_proxy| ... } click to toggle source
# File lib/pading/actionview/paginator.rb, line 49
def each_page
  # Kaminari.config.window = 1
  window = 1
  each_start = @options[:current_page_number] - 1 - window
  each_end = @options[:current_page_number] + 1 + window
  each_start = 1 if each_start < window
  each_end = @options[:total_pages] if each_end > @options[:total_pages]

  (each_start..each_end).each do |page|
    yield PageProxy.new(@options,page)
  end

end
page_tag(page) click to toggle source
# File lib/pading/actionview/paginator.rb, line 64
def page_tag(page)
 Page.new @template, @options.merge(page: page)
end
render(&block) click to toggle source
# File lib/pading/actionview/paginator.rb, line 31
def render(&block)
  # total_pages 总页数 大于 1 就渲染从出来
  # instance_eval 将您的块作为一个块传递给instance_eval
  instance_eval(&block) if @options[:total_pages] > 1
  @output_buffer
end
to_s(locals = {}) click to toggle source
Calls superclass method
# File lib/pading/actionview/paginator.rb, line 26
def to_s(locals = {})
  super @options.merge paginator: self
end