Class: JekyllIndexPages::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll-index-pages/pagination.rb

Defined Under Namespace

Classes: Pager

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(docs, per_page) ⇒ Pagination

Returns a new instance of Pagination.



13
14
15
16
17
18
# File 'lib/jekyll-index-pages/pagination.rb', line 13

def initialize(docs, per_page)
  @docs = docs
  @per_page = per_page
  @total = per_page > 0 ? (docs.length.to_f / per_page).ceil : 0
  @pager = Pager.new([], @total, 0, 0, 0)
end

Instance Attribute Details

#pagerObject (readonly)

Returns the value of attribute pager.



11
12
13
# File 'lib/jekyll-index-pages/pagination.rb', line 11

def pager
  @pager
end

#totalObject (readonly)

Returns the value of attribute total.



11
12
13
# File 'lib/jekyll-index-pages/pagination.rb', line 11

def total
  @total
end

Instance Method Details

#paginate(current) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-index-pages/pagination.rb', line 20

def paginate(current)
  first = @per_page * current
  last = first + @per_page

  @pager.docs = @docs[first...last]
  @pager.current_page = current + 1
  @pager.prev_page = current
  @pager.next_page = (current < total - 1) ? current + 2 : 0
end