From 45ec4076f90032170c1484207f67dae50e0d8a6a Mon Sep 17 00:00:00 2001 From: Jeremy Jackson Date: Tue, 18 Nov 2025 08:11:59 -0700 Subject: [PATCH] Improves performance on partials, by only compiling them when they're retrieved / going to be rendered. --- lib/ruby-handlebars.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/ruby-handlebars.rb b/lib/ruby-handlebars.rb index 881a93c..a554942 100644 --- a/lib/ruby-handlebars.rb +++ b/lib/ruby-handlebars.rb @@ -39,11 +39,13 @@ def get_as_helper(name) end def register_partial(name, content) - @partials[name.to_s] = Template.new(self, template_to_ast(content)) + @partials[name.to_s] = { content: content, compiled: nil } end def get_partial(name) - @partials[name.to_s] || raise(::Handlebars::MissingPartial, "Partial \"#{name}\" not registered.") + raise(::Handlebars::MissingPartial, "Partial \"#{name}\" not registered.") unless @partials[name.to_s] + + @partials[name.to_s][:compiled] ||= Template.new(self, template_to_ast(@partials[name.to_s][:content])) end def set_escaper(escaper = nil)