lib/frontman/renderers/erb_renderer.rb in frontman-ssg-0.1.0 vs lib/frontman/renderers/erb_renderer.rb in frontman-ssg-0.1.1

- old
+ new

@@ -4,10 +4,15 @@ require 'erubis' require 'frontman/renderers/renderer' module Frontman class ErbRenderer < Frontman::Renderer + def initialize + @buffer = {} + super + end + def compile(layout) Erubis::Eruby.new(layout, bufvar: '@_erbout') end def render_content(compiled, content, scope, data) @@ -21,16 +26,18 @@ def save_buffer(context) buffer = context.instance_variable_get(:@_erbout) return unless buffer - @buffer = buffer + @buffer[context.buffer_hash] = buffer context.instance_variable_set(:@_erbout, '') end def restore_buffer(context) - context.instance_variable_set(:@_erbout, @buffer) if @buffer - @buffer = nil + return unless @buffer[context.buffer_hash] + + context.instance_variable_set(:@_erbout, @buffer[context.buffer_hash]) + @buffer.delete(context.buffer_hash) end def load_buffer(context) context.instance_variable_get(:@_erbout) end