lib/frontman/renderers/haml_renderer.rb in frontman-ssg-0.0.4 vs lib/frontman/renderers/haml_renderer.rb in frontman-ssg-0.1.0

- old
+ new

@@ -1,7 +1,7 @@ # typed: false -# frozen_string_literal: true +# frozen_string_literal: false require 'haml' require 'frontman/renderers/renderer' module Frontman @@ -15,8 +15,36 @@ Haml::Engine.new(layout) end def render_content(compiled, content, scope, _data) compiled.render(scope.get_binding) { content } + end + + def load_buffer(context) + haml_locals = context.instance_variable_get(:@_haml_locals) + + haml_locals[:_hamlout].buffer if haml_locals + end + + def save_buffer(context) + @buffer = nil + haml_locals = context.instance_variable_get(:@_haml_locals) + + return unless haml_locals + + @buffer = haml_locals[:_hamlout].buffer + # empty the buffer so we can capture everything from the new render + haml_locals[:_hamlout].buffer = '' + context.instance_variable_set(:@_haml_locals, haml_locals) + end + + def restore_buffer(context) + haml_locals = context.instance_variable_get(:@_haml_locals) + + return unless haml_locals + + haml_locals[:_hamlout].buffer = @buffer + context.instance_variable_set(:@_haml_locals, haml_locals) + @buffer = nil end end end