Class: Jekyll::Itafroma::ArchivePager

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/itafroma/archive_pager.rb

Overview

Represents the pager used for ArchivePages.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site, page, all_pages, num_pages = nil) ⇒ ArchivePager

Initialize a new Archive Pager.

site - the Jekyll::Site object page - The Integer page number. all_pages - The Array of the archive's Posts. num_pages - The Integer number of pages or nil if you'd like the number

of pages calculated.

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/jekyll/itafroma/archive_pager.rb', line 42

def initialize(site, page, all_pages, num_pages = nil)
  @page = page
  @per_page = 1
  @total_pages = num_pages || all_pages.size

  if @page > @total_pages
    fail "Jekyll Archive Generator: page number can't be greater than total pages: #{@page} > #{@total_pages}"
  end

  @pages = all_pages
  @previous_page = @page != 1 ? @page - 1 : nil
  @previous_page_path = ArchivePager.paginate_path(all_pages, @previous_page)
  @next_page = @page != @total_pages ? @page + 1 : nil
  @next_page_path = ArchivePager.paginate_path(all_pages, @next_page)
end

Instance Attribute Details

#next_pageObject (readonly)

Returns the value of attribute next_page


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def next_page
  @next_page
end

#next_page_pathObject (readonly)

Returns the value of attribute next_page_path


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def next_page_path
  @next_page_path
end

#pageObject (readonly)

Returns the value of attribute page


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def page
  @page
end

#pagesObject (readonly)

Returns the value of attribute pages


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def pages
  @pages
end

#per_pageObject (readonly)

Returns the value of attribute per_page


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def per_page
  @per_page
end

#previous_pageObject (readonly)

Returns the value of attribute previous_page


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def previous_page
  @previous_page
end

#previous_page_pathObject (readonly)

Returns the value of attribute previous_page_path


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def previous_page_path
  @previous_page_path
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def total_pages
  @total_pages
end

#total_postsObject (readonly)

Returns the value of attribute total_posts


18
19
20
# File 'lib/jekyll/itafroma/archive_pager.rb', line 18

def total_posts
  @total_posts
end

Class Method Details

.paginate_path(posts, num_page) ⇒ Object

Static: Return the pagination path of the archive page

posts - The Array of the archive's Posts. num_page - the pagination page number

Returns the pagination path as a string


28
29
30
31
32
33
# File 'lib/jekyll/itafroma/archive_pager.rb', line 28

def self.paginate_path(posts, num_page)
  return posts.first.url if num_page.nil?
  return nil if num_page < 1
  return nil if num_page > posts.size
  posts[num_page - 1].url
end

Instance Method Details

#to_liquidObject

Convert this Pager's data to a Hash suitable for use by Liquid.

Returns the Hash representation of this Pager.


61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/jekyll/itafroma/archive_pager.rb', line 61

def to_liquid
  {
    'page' => page,
    'per_page' => per_page,
    'pages' => pages,
    'total_pages' => total_pages,
    'previous_page' => previous_page,
    'previous_page_path' => previous_page_path,
    'next_page' => next_page,
    'next_page_path' => next_page_path
  }
end