class Jekyll::CategoryIndexPage

Auto-generated page for a category index.

When pagination is enabled, contains a CategoryPager object as paginator. The posts in the category are always available as posts, the total number of those is always total_posts.

Constants

ATTRIBUTES_FOR_LIQUID

Attributes for Liquid templates.

Public Class Methods

new(site, dir, page_name, category, category_layout, posts_in_category, use_paginator) click to toggle source

Initialize a new category index page.

site - The Site object. dir - Base directory for all category pages. page_name - Name of this category page (either 'index.html' or 'page#.html'). category - Current category as a String. category_layout - Name of the category index page layout (must reside in the '_layouts' directory). posts_in_category - Array with full list of Posts in the current category. use_paginator - Whether a CategoryPager object shall be instantiated as 'paginator'.

Calls superclass method
# File lib/jekyll/category_pages.rb, line 154
def initialize(site, dir, page_name, category, category_layout, posts_in_category, use_paginator)
  @site = site
  @base = site.source
  super(@site, @base, '', category_layout)
  @dir = dir
  @name = page_name

  self.process @name

  @category = category
  @posts_in_category = posts_in_category
  @my_paginator = nil

  self.read_yaml(@base, category_layout)
  self.data.merge!('title' => category)
  if use_paginator
    @my_paginator = CategoryPager.new
    self.data.merge!('paginator' => @my_paginator)
  end
end

Public Instance Methods

add_paginator_relations(page, per_page, total_pages, previous_page_path, next_page_path, previous_page, next_page) click to toggle source

Add relations of this page to other pages handled by a CategoryPager.

Note that this method SHALL NOT be called if the category pages are instantiated without pagination. This method SHALL be called if the category pages are instantiated with pagination.

page - Current page number. per_page - Posts per page. total_pages - Total number of pages. previous_page - Number of previous page or nil. next_page - Number of next page or nil. previous_page_path - String with path to previous page or nil. next_page_path - String with path to next page or nil.

# File lib/jekyll/category_pages.rb, line 187
def add_paginator_relations(page, per_page, total_pages, previous_page_path, next_page_path, previous_page, next_page)
  if @my_paginator
    @my_paginator.add_relations(page, per_page, total_pages,
                                previous_page, next_page, previous_page_path, next_page_path)
    @my_paginator.add_posts(page, per_page, @posts_in_category)
  else
    Jekyll.logger.warn("Categories", "add_relations does nothing since the category page has been initialized without pagination")
  end
end
category() click to toggle source

Get the category name this index page refers to

Returns a string.

# File lib/jekyll/category_pages.rb, line 200
def category
  @category
end
paginator() click to toggle source

Get the paginator object describing the current index page.

Returns a CategoryPager object or nil.

# File lib/jekyll/category_pages.rb, line 207
def paginator
  @my_paginator
end
posts() click to toggle source

Get all Posts in this category.

Returns an Array of Posts.

# File lib/jekyll/category_pages.rb, line 214
def posts
  @posts_in_category
end
total_posts() click to toggle source

Get the number of posts in this category.

Returns an Integer number of posts.

# File lib/jekyll/category_pages.rb, line 221
def total_posts
  @posts_in_category.size
end