Permalink
Browse files

More TomDoc and formatting cleanup.

  • Loading branch information...
1 parent aa0d82f commit 82bd83fe7f5282ccf73b2396846e1acf362ba277 @mojombo mojombo committed May 9, 2011
Showing with 163 additions and 100 deletions.
  1. +2 −2 lib/jekyll.rb
  2. +32 −4 lib/jekyll/generators/pagination.rb
  3. +112 −74 lib/jekyll/site.rb
  4. +12 −15 lib/jekyll/static_file.rb
  5. +5 −5 lib/jekyll/tags/highlight.rb
View
@@ -94,8 +94,8 @@ module Jekyll
}
}
- # Generate a Jekyll configuration Hash by merging the default options
- # with anything in _config.yml, and adding the given options on top.
+ # Public: Generate a Jekyll configuration Hash by merging the default
+ # options with anything in _config.yml, and adding the given options on top.
#
# override - A Hash of config directives that override any options in both
# the defaults and the config file. See Jekyll::DEFAULTS for a
@@ -1,18 +1,26 @@
module Jekyll
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, ie: page2/index.html, page3/index.html, etc and adds more
+ # directories, e.g.: page2/index.html, page3/index.html, etc and adds more
# site-wide data.
- # +page+ is the index.html Page that requires pagination
+ #
+ # site - The Site.
+ # page - The index.html Page that requires pagination.
#
# {"paginator" => { "page" => <Number>,
# "per_page" => <Number>,
@@ -36,22 +44,40 @@ def paginate(site, page)
end
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)
num_pages = all_posts.size / per_page.to_i
num_pages = num_pages + 1 if all_posts.size % per_page.to_i != 0
num_pages
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
@@ -70,6 +96,9 @@ def initialize(config, page, all_posts, num_pages = 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,
@@ -83,5 +112,4 @@ def to_liquid
end
end
-
end
Oops, something went wrong.

0 comments on commit 82bd83f

Please sign in to comment.