class Jekyll::CategoryPager
Handle pagination of category index pages.
Attributes
Public Class Methods
Static: Calculate the number of pages.
all_posts - The Array of all Posts. per_page
- The Integer of entries per page.
Returns the Integer number of pages.
# File lib/jekyll/category_pages.rb, line 237 def self.calculate_pages(all_posts, per_page) (all_posts.size.to_f / per_page.to_i).ceil end
Public Instance Methods
Add page-specific post data.
page - Current page number. per_page
- Posts per page. posts_in_category - Array with full list of Posts in the current category.
# File lib/jekyll/category_pages.rb, line 265 def add_posts(page, per_page, posts_in_category) total_posts = posts_in_category.size init = (page - 1) * per_page offset = (init + per_page - 1) >= total_posts ? total_posts : (init + per_page - 1) @total_posts = total_posts @posts = posts_in_category[init..offset] end
Add numeric relationships of this page to other pages.
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 250 def add_relations(page, per_page, total_pages, previous_page, next_page, previous_page_path, next_page_path) @page = page @per_page = per_page @total_pages = total_pages @previous_page = previous_page @next_page = next_page @previous_page_path = previous_page_path @next_page_path = next_page_path end
Convert this CategoryPager's data to a Hash suitable for use by Liquid.
Returns the Hash representation of this CategoryPager
.
# File lib/jekyll/category_pages.rb, line 277 def to_liquid { 'page' => page, 'per_page' => per_page, 'posts' => posts, 'total_posts' => total_posts, '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