Skip to content

Commit

Permalink
Cache instantiated template objects for ERB and Serbea (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredcwhite authored Dec 17, 2024
1 parent b6a636b commit c1ce6ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
18 changes: 11 additions & 7 deletions bridgetown-core/lib/bridgetown-core/converters/erb_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1ce6ba

Please sign in to comment.