From 8224c07b30bafc06838244dc8f78088e0c476c49 Mon Sep 17 00:00:00 2001 From: Alex Riedler Date: Sun, 15 Dec 2024 20:08:36 -0500 Subject: [PATCH] fix: auto-recompilation --- lib/handlebars_assets/handlebars_template.rb | 16 +++++++++------- test/handlebars_assets/hamlbars_test.rb | 2 +- .../handlebars_processor_test.rb | 2 +- test/handlebars_assets/slimbars_test.rb | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/handlebars_assets/handlebars_template.rb b/lib/handlebars_assets/handlebars_template.rb index 0b72921..b79953b 100644 --- a/lib/handlebars_assets/handlebars_template.rb +++ b/lib/handlebars_assets/handlebars_template.rb @@ -36,7 +36,8 @@ def initialize(options = {}) def call(input) renderer = HandlebarsRenderer.new(path: input[:filename]) engine = renderer.choose_engine(input[:data]) - renderer.compile(engine.render) + rendered = renderer.compile(engine.render) + { data: rendered, metadata: { dependencies: [input[:filename]] } } end end @@ -91,12 +92,13 @@ def compile(source) # handle the case of multiple frameworks combined with ember # DEFER: use extension setup for ember - if (HandlebarsAssets::Config.multiple_frameworks? && @template_path.ember?) || - (HandlebarsAssets::Config.ember? && !HandlebarsAssets::Config.multiple_frameworks?) - compile_ember(trim_source) - else - compile_default(trim_source) - end + data = + if (HandlebarsAssets::Config.multiple_frameworks? && @template_path.ember?) || + (HandlebarsAssets::Config.ember? && !HandlebarsAssets::Config.multiple_frameworks?) + compile_ember(trim_source) + else + compile_default(trim_source) + end end def compile_ember(source) diff --git a/test/handlebars_assets/hamlbars_test.rb b/test/handlebars_assets/hamlbars_test.rb index c229f4d..5979dfb 100644 --- a/test/handlebars_assets/hamlbars_test.rb +++ b/test/handlebars_assets/hamlbars_test.rb @@ -26,7 +26,7 @@ def test_render_haml scope = make_scope root, file source = '%p This is {{handlebars}}' - rendered = HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source) + rendered = HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source)[:data] assert_equal hbs_compiled('test_render', compile_haml(source)), rendered end diff --git a/test/handlebars_assets/handlebars_processor_test.rb b/test/handlebars_assets/handlebars_processor_test.rb index 6db415a..662cdf6 100644 --- a/test/handlebars_assets/handlebars_processor_test.rb +++ b/test/handlebars_assets/handlebars_processor_test.rb @@ -13,7 +13,7 @@ def teardown end def render_it(scope, source) - HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source) + HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source)[:data] end end end diff --git a/test/handlebars_assets/slimbars_test.rb b/test/handlebars_assets/slimbars_test.rb index 5b70885..1329c8c 100644 --- a/test/handlebars_assets/slimbars_test.rb +++ b/test/handlebars_assets/slimbars_test.rb @@ -22,7 +22,7 @@ def test_render_slim scope = make_scope root, file source = 'p This is {{handlebars}}' - rendered = HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source) + rendered = HandlebarsAssets::HandlebarsProcessor.call(filename: scope.pathname.to_s, data: source)[:data] assert_equal hbs_compiled('test_render', compile_slim(source)), rendered end