Class: Jekyll::Generators::Pagination

### Home Classes Methods

### In Files

- lib/jekyll/generators/pagination.rb

### Parent

Jekyll::Generator

### Methods

- ::first_page_url
- #generate
- #paginate
- #template_page

### Files

- LICENSE

### Class/Module Index

Quicksearch

- Jekyll
- Jekyll::Command
- Jekyll::Commands
- Jekyll::Commands::Build
- Jekyll::Commands::Doctor
- Jekyll::Commands::New
- Jekyll::Commands::Serve
- Jekyll::Configuration
- Jekyll::Converter
- Jekyll::Converters
- Jekyll::Converters::Identity
- Jekyll::Converters::Markdown
- Jekyll::Converters::Markdown::KramdownParser
- Jekyll::Converters::Markdown::MarukuParser
- Jekyll::Converters::Markdown::RDiscountParser
- Jekyll::Converters::Markdown::RedcarpetParser
- Jekyll::Converters::Markdown::RedcarpetParser::CommonMethods
- Jekyll::Converters::Markdown::RedcarpetParser::WithPygments
- Jekyll::Converters::Markdown::RedcarpetParser::WithoutPygments
- Jekyll::Converters::Textile
- Jekyll::Convertible
- Jekyll::Deprecator
- Jekyll::Draft
- Jekyll::Excerpt
- Jekyll::FatalException
- Jekyll::Filters
- Jekyll::Generator
- Jekyll::Generators
- Jekyll::Generators::Pagination
- Jekyll::GistTag
- Jekyll::Layout
- Jekyll::Page
- Jekyll::Pager
- Jekyll::Plugin
- Jekyll::Post
- Jekyll::RelatedPosts
- Jekyll::Site
- Jekyll::Site::Cleaner
- Jekyll::StaticFile
- Jekyll::Stevenson
- Jekyll::Tags
- Jekyll::Tags::HighlightBlock
- Jekyll::Tags::IncludeTag
- Jekyll::Tags::PostComparer
- Jekyll::Tags::PostUrl
- Jekyll::URL
- Date
- Enumerable
- Hash
- Object

No matching classes.

# Jekyll::Generators::Pagination

### Public Class Methods

first_page_url(site) click to toggle source

Static: Fetch the URL of the template page. Used to determine the

    path to the first pager in the series.

site - the Jekyll::Site object

Returns the url of the template page

    # File lib/jekyll/generators/pagination.rb, line 59
    def self.first_page_url(site)
      if page = Pagination.new.template_page(site)
        page.url
      else
        nil
      end
    end

### Public Instance Methods

generate(site) click to toggle source

Generate paginated pages if necessary.

site - The Site.

Returns nothing.

    # File lib/jekyll/generators/pagination.rb, line 12
    def generate(site)
      if Pager.pagination_enabled?(site)
        if template = template_page(site)
          paginate(site, template)
        else
          Jekyll.logger.warn "Pagination:", "Pagination is enabled, but I couldn't find" +
          "an index.html page to use as the pagination template. Skipping pagination."
        end
      end
    end

paginate(site, page) click to toggle source

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" => <Number>,

    "per_page" => <Number>,
    "posts" => [<Post>],
    "total_posts" => <Number>,
    "total_pages" => <Number>,
    "previous_page" => <Number>,
    "next_page" => <Number> }}

    # File lib/jekyll/generators/pagination.rb, line 37
    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, num_page, all_posts, pages)
        if num_page > 1
          newpage = Page.new(site, site.source, page.dir, page.name)
          newpage.pager = pager
          newpage.dir = Pager.paginate_path(site, num_page)
          site.pages << newpage
        else
          page.pager = pager
        end
      end
    end

template_page(site) click to toggle source

Public: Find the Jekyll::Page which will act as the pager template

site - the Jekyll::Site object

Returns the Jekyll::Page which will act as the pager template

    # File lib/jekyll/generators/pagination.rb, line 72
    def template_page(site)
      site.pages.dup.select do |page|
        Pager.pagination_candidate?(site.config, page)
      end.sort do |one, two|
        two.path.size <=> one.path.size
      end.first
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.