generate phase added to site#process and pagination is now a generator

This commit is contained in:
Kris Brown 2010-02-27 15:31:59 +00:00
parent bae52e0aba
commit 1261840769
4 changed files with 17 additions and 12 deletions

View File

@ -4,6 +4,7 @@
* Generation for a specific time (#59) * Generation for a specific time (#59)
* site.time allocated on render not per site_payload invocation (#59) * site.time allocated on render not per site_payload invocation (#59)
* pages now present in the site payload and can be used through the site.pages and site.html_pages variables * pages now present in the site payload and can be used through the site.pages and site.html_pages variables
* generate phase added to site#process and pagination is now a generator
* Bug Fixes * Bug Fixes
* Render highlighted code for non markdown/textile pages (#116) * Render highlighted code for non markdown/textile pages (#116)
* Expand source to full path so includes work anywhere (#101) * Expand source to full path so includes work anywhere (#101)

View File

@ -3,7 +3,7 @@ module Jekyll
class Page class Page
include Convertible include Convertible
attr_accessor :site attr_accessor :site, :pager
attr_accessor :name, :ext, :basename, :dir attr_accessor :name, :ext, :basename, :dir
attr_accessor :data, :content, :output attr_accessor :data, :content, :output
@ -81,7 +81,8 @@ module Jekyll
# Returns nothing # Returns nothing
def render(layouts, site_payload) def render(layouts, site_payload)
payload = { payload = {
"page" => self.to_liquid "page" => self.to_liquid,
'paginator' => pager.to_liquid
}.deep_merge(site_payload) }.deep_merge(site_payload)
do_layout(payload, layouts) do_layout(payload, layouts)

View File

@ -30,7 +30,7 @@ module Jekyll
@next_page = @page != @total_pages ? @page + 1 : nil @next_page = @page != @total_pages ? @page + 1 : nil
end end
def to_hash def to_liquid
{ {
'page' => page, 'page' => page,
'per_page' => per_page, 'per_page' => per_page,

View File

@ -92,13 +92,14 @@ module Jekyll
end end
# Do the actual work of processing the site and generating the # Do the actual work of processing the site and generating the
# real deal. Now has 4 phases; reset, read, render, write. This allows # real deal. 5 phases; reset, read, generate, render, write. This allows
# rendering to have full site payload available. # rendering to have full site payload available.
# #
# Returns nothing # Returns nothing
def process def process
self.reset self.reset
self.read self.read
self.generate
self.render self.render
self.write self.write
end end
@ -154,12 +155,8 @@ module Jekyll
post.render(self.layouts, site_payload) post.render(self.layouts, site_payload)
end end
self.pages.dup.each do |page| self.pages.each do |page|
if Pager.pagination_enabled?(self.config, page.name) page.render(self.layouts, site_payload)
paginate(page)
else
page.render(self.layouts, site_payload)
end
end end
self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} } self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a} }
@ -254,6 +251,12 @@ module Jekyll
end end
end end
def generate
self.pages.dup.each do |page|
paginate(page) if Pager.pagination_enabled?(self.config, page.name)
end
end
# Paginates the blog's posts. Renders the index.html file into paginated # 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, ie: page2/index.html, page3/index.html, etc and adds more
# site-wide data. # site-wide data.
@ -273,11 +276,11 @@ module Jekyll
pager = Pager.new(self.config, num_page, all_posts, pages) pager = Pager.new(self.config, num_page, all_posts, pages)
if num_page > 1 if num_page > 1
newpage = Page.new(self, self.source, page.dir, page.name) newpage = Page.new(self, self.source, page.dir, page.name)
newpage.render(self.layouts, site_payload.merge({'paginator' => pager.to_hash})) newpage.pager = pager
newpage.dir = File.join(page.dir, "page#{num_page}") newpage.dir = File.join(page.dir, "page#{num_page}")
self.pages << newpage self.pages << newpage
else else
page.render(self.layouts, site_payload.merge({'paginator' => pager.to_hash})) page.pager = pager
end end
end end
end end