From 9ddc12bad8773f022456be2bd72107ade97c06c2 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Tue, 30 Aug 2016 14:39:20 -0700 Subject: [PATCH] Convertible: ensure layouts the argument and payload the argument are set properly in the renderer --- lib/jekyll/convertible.rb | 12 ++++++++++-- lib/jekyll/renderer.rb | 31 ++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/lib/jekyll/convertible.rb b/lib/jekyll/convertible.rb index 9922f779..52fc49b4 100644 --- a/lib/jekyll/convertible.rb +++ b/lib/jekyll/convertible.rb @@ -190,7 +190,10 @@ module Jekyll # # Returns nothing def render_all_layouts(layouts, payload, info) + _renderer.layouts = layouts _renderer.place_in_layouts(output, payload, info) + ensure + @_renderer = nil # this will allow the modifications above to disappear end # Add any necessary layouts to this convertible document. @@ -200,11 +203,16 @@ module Jekyll # # Returns nothing. def do_layout(payload, layouts) - @_renderer = Jekyll::Renderer.new(site, self, payload) - _renderer.run + _renderer.tap do |renderer| + renderer.layouts = layouts + renderer.payload = payload + renderer.run + end Jekyll.logger.debug "Post-Render Hooks:", self.relative_path Jekyll::Hooks.trigger hook_owner, :post_render, self + ensure + @_renderer = nil # this will allow the modifications above to disappear end # Write the generated page file to the destination directory. diff --git a/lib/jekyll/renderer.rb b/lib/jekyll/renderer.rb index b1177b60..db01a167 100644 --- a/lib/jekyll/renderer.rb +++ b/lib/jekyll/renderer.rb @@ -2,12 +2,33 @@ module Jekyll class Renderer - attr_reader :document, :site, :payload + attr_reader :document, :site + attr_writer :layouts, :payload - def initialize(site, document, site_payload = nil) + def initialize(site, document, site_payload = nil, layouts: nil) @site = site @document = document - @payload = site_payload || site.site_payload + @payload = site_payload + @layouts = layouts + end + + # Fetches the payload used in Liquid rendering. + # It can be written with #payload=(new_payload) + # Falls back to site.site_payload if no payload is set. + # + # Returns a Jekyll::Drops::UnifiedPayloadDrop + def payload + @payload ||= site.site_payload + end + + # The list of layouts registered for this Renderer. + # It can be written with #layouts=(new_layouts) + # Falls back to site.layouts if no layouts are registered. + # + # Returns a Hash of String => Jekyll::Layout identified + # as basename without the extension name. + def layouts + @layouts || site.layouts end # Determine which converters to use based on this document's @@ -137,7 +158,7 @@ module Jekyll # Returns the content placed in the Liquid-rendered layouts def place_in_layouts(content, payload, info) output = content.dup - layout = site.layouts[document.data["layout"]] + layout = layouts[document.data["layout"]] Jekyll.logger.warn( "Build Warning:", @@ -167,7 +188,7 @@ module Jekyll site.in_source_dir(layout.path) ) if document.write? - if (layout = site.layouts[layout.data["layout"]]) + if (layout = layouts[layout.data["layout"]]) break if used.include?(layout) used << layout end