Sha256: cfbda36276ea5be40d5d55cfaf2f3072fd6cfd5c1cfd8b3fb1dce77d24785b80

Contents?: true

Size: 868 Bytes

Versions: 12

Compression:

Stored size: 868 Bytes

Contents

class Commontator::Collection < WillPaginate::Collection
  attr_reader :root_per_page

  # This method determines if we are in a shorter version of the first page, which we call page 0
  def page_zero?
    total_entries > @per_page && @per_page < @root_per_page
  end

  def initialize(array, count, root_per_page, per_page, page = 1)
    self.total_entries = count
    @root_per_page = root_per_page
    @per_page = per_page
    @current_page = page_zero? ? 0 : WillPaginate::PageNumber(page)
    @first_call = true

    replace(array)
  end

  # We return 2 total_pages under certain conditions to trick will_paginate
  # into rendering the pagination controls when it otherwise wouldn't
  def total_pages
    min_total_pages = page_zero? && @first_call ? 2 : 1
    @first_call = false
    [ (total_entries.to_f/@root_per_page).ceil, min_total_pages ].max
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
commontator-7.0.1 app/models/commontator/collection.rb
commontator-7.0.0 app/models/commontator/collection.rb
commontator-6.3.2 app/models/commontator/collection.rb
commontator-6.3.1 app/models/commontator/collection.rb
commontator-6.3.0 app/models/commontator/collection.rb
commontator-6.2.1 app/models/commontator/collection.rb
commontator-6.2.0 app/models/commontator/collection.rb
commontator-6.1.1 app/models/commontator/collection.rb
commontator-6.1.0 app/models/commontator/collection.rb
commontator-6.0.1 app/models/commontator/collection.rb
commontator-6.0.0 app/models/commontator/collection.rb
commontator-6.0.0.pre.2 app/models/commontator/collection.rb