From f17e6cb15d4c90a4740ebb08bf61294a4161753b Mon Sep 17 00:00:00 2001 From: Brandon Mathis Date: Tue, 9 Apr 2013 09:13:50 -0500 Subject: [PATCH] removed unncessary pagination plugin --- plugins/pagination.rb | 121 ------------------------------------------ 1 file changed, 121 deletions(-) delete mode 100644 plugins/pagination.rb diff --git a/plugins/pagination.rb b/plugins/pagination.rb deleted file mode 100644 index b2802f4..0000000 --- a/plugins/pagination.rb +++ /dev/null @@ -1,121 +0,0 @@ -require File.expand_path('../../lib/colors.rb', __FILE__) - -module Jekyll - module Generators - class Pagination < Generator - # This generator is safe from arbitrary code execution. - safe true - - # Generate paginated pages if necessary. - # - # site - The Site. - # - # Returns nothing. - def generate(site) - site.pages.dup.each do |page| - paginate(site, page) if Pager.pagination_enabled?(site.config, page.name) - end - end - - # Paginates the blog's posts. Renders the index.html file into paginated - # directories, e.g.: page2/index.html, page3/index.html, etc and adds more - # site-wide data. - # - # site - The Site. - # page - The index.html Page that requires pagination. - # - # {"paginator" => { "page" => , - # "per_page" => , - # "posts" => [], - # "total_posts" => , - # "total_pages" => , - # "previous_page" => , - # "next_page" => }} - def paginate(site, page) - all_posts = site.site_payload['site']['posts'] - pages = Pager.calculate_pages(all_posts, site.config['paginate'].to_i) - (1..pages).each do |num_page| - pager = Pager.new(site.config, num_page, all_posts, pages) - if num_page > 1 - newpage = Page.new(site, site.source, page.dir, page.name) - newpage.pager = pager - newpage.dir = File.join(page.dir, paginate_path(site, num_page)) - site.pages << newpage - else - page.pager = pager - end - end - end - - private - def paginate_path(site, num_page) - format = site.config['paginate_path'] - format.sub(':num', num_page.to_s) - end - end - end - - class Pager - attr_reader :page, :per_page, :posts, :total_posts, :total_pages, :previous_page, :next_page - - # 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. - def self.calculate_pages(all_posts, per_page) - (all_posts.size.to_f / per_page.to_i).ceil - end - - # Determine if pagination is enabled for a given file. - # - # config - The configuration Hash. - # file - The String filename of the file. - # - # Returns true if pagination is enabled, false otherwise. - def self.pagination_enabled?(config, file) - file == 'index.html' && !config['paginate'].nil? - end - - # Initialize a new Pager. - # - # config - The Hash configuration of the site. - # page - The Integer page number. - # all_posts - The Array of all the site's Posts. - # num_pages - The Integer number of pages or nil if you'd like the number - # of pages calculated. - def initialize(config, page, all_posts, num_pages = nil) - @page = page - @per_page = config['paginate'].to_i - @total_pages = num_pages || Pager.calculate_pages(all_posts, @per_page) - - if @page > @total_pages - raise RuntimeError, "page number can't be greater than total pages: #{@page} > #{@total_pages}".red - end - - init = (@page - 1) * @per_page - offset = (init + @per_page - 1) >= all_posts.size ? all_posts.size : (init + @per_page - 1) - - @total_posts = all_posts.size - @posts = all_posts[init..offset] - @previous_page = @page != 1 ? @page - 1 : nil - @next_page = @page != @total_pages ? @page + 1 : nil - end - - # Convert this Pager's data to a Hash suitable for use by Liquid. - # - # Returns the Hash representation of this Pager. - def to_liquid - { - 'page' => page, - 'per_page' => per_page, - 'posts' => posts, - 'total_posts' => total_posts, - 'total_pages' => total_pages, - 'previous_page' => previous_page, - 'next_page' => next_page - } - end - end -end