Class: RailsPaginationUltimate::Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_pagination_ultimate/action_view_helper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, collection, options = {}) ⇒ Paginator

Returns a new instance of Paginator.



47
48
49
50
51
52
53
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 47

def initialize(template, collection, options = {})
  @template = template
  @collection = collection
  @options = options
  @current_page = collection.current_page
  @total_pages = collection.total_pages
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



45
46
47
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 45

def collection
  @collection
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



45
46
47
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 45

def current_page
  @current_page
end

#optionsObject (readonly)

Returns the value of attribute options.



45
46
47
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 45

def options
  @options
end

#templateObject (readonly)

Returns the value of attribute template.



45
46
47
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 45

def template
  @template
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



45
46
47
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 45

def total_pages
  @total_pages
end

Instance Method Details

#renderObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/rails_pagination_ultimate/action_view_helper.rb', line 55

def render
  return "" if total_pages <= 1 && total_pages != Float::INFINITY

  if options[:template]
    return template.render(partial: options[:template], locals: { 
      collection: collection, 
      options: options, 
      template: template,
      windowed_page_numbers: windowed_page_numbers
    })
  end

  case options[:type]
  when :load_more
    render_load_more
  when :infinite_scroll
    render_infinite_scroll
  else
    render_standard
  end
end