From c1ce6ba176f90aabea6226944739f7c247027712 Mon Sep 17 00:00:00 2001 From: Jared White Date: Tue, 17 Dec 2024 15:06:01 -0800 Subject: [PATCH] Cache instantiated template objects for ERB and Serbea (#958) --- .../converters/erb_templates.rb | 18 +++++++++++------- .../converters/serbea_templates.rb | 11 +++++++---- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb index 59abab91f..ced919a05 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb @@ -119,13 +119,17 @@ class ERBTemplates < Converter def convert(content, convertible) erb_view = Bridgetown::ERBView.new(convertible) - erb_renderer = Tilt::ErubiTemplate.new( - convertible.path, - line_start(convertible), - outvar: "@_erbout", - bufval: "Bridgetown::OutputBuffer.new", - engine_class: ERBEngine - ) { content } + erb_renderer = + convertible.site.tmp_cache["erb-tmpl:#{convertible.path}:#{content.hash}"] ||= + Tilt::ErubiTemplate.new( + convertible.path, + line_start(convertible), + outvar: "@_erbout", + bufval: "Bridgetown::OutputBuffer.new", + engine_class: ERBEngine + ) do + content + end if convertible.is_a?(Bridgetown::Layout) erb_renderer.render(erb_view) do diff --git a/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb b/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb index ec72f5e60..523baba4e 100644 --- a/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb +++ b/bridgetown-core/lib/bridgetown-core/converters/serbea_templates.rb @@ -34,10 +34,13 @@ class SerbeaTemplates < Converter # @return [String] The converted content def convert(content, convertible) serb_view = Bridgetown::SerbeaView.new(convertible) - serb_renderer = Tilt::SerbeaTemplate.new( - convertible.path, - line_start(convertible) - ) { content } + + serb_renderer = + convertible.site.tmp_cache["serb-tmpl:#{convertible.path}:#{content.hash}"] ||= + Tilt::SerbeaTemplate.new( + convertible.path, + line_start(convertible) + ) { content } if convertible.is_a?(Bridgetown::Layout) serb_renderer.render(serb_view) do