Skip to content

Commit

Permalink
fix: handle window case correctly due to this
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexRiedler committed Dec 16, 2024
1 parent f878eae commit 7b4c6d6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/handlebars_assets/handlebars_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ def compile_default(source)
unindent <<-PARTIAL
(function() {
Handlebars.registerPartial(#{@template_path.name}, #{template});
}).call(this);
}).call(this || window);
PARTIAL
else
unindent <<-TEMPLATE
(function() {
this.#{template_namespace} || (this.#{template_namespace} = {});
this.#{template_namespace}[#{@template_path.name}] = #{template};
return this.#{template_namespace}[#{@template_path.name}];
}).call(this);
}).call(this || window);
TEMPLATE
end
end
Expand Down
7 changes: 3 additions & 4 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ module CompilerSupport

def compile_hbs(source)
compiler_src = Pathname(HandlebarsAssets::Config.compiler_path).join(HandlebarsAssets::Config.compiler).read
ExecJS.compile("var window = {}; #{compiler_src}").call('Handlebars.precompile', source,
HandlebarsAssets::Config.options)
ExecJS.compile("#{compiler_src}").call('Handlebars.precompile', source, HandlebarsAssets::Config.options)
end

def hbs_compiled(template_name, source)
Expand All @@ -38,7 +37,7 @@ def hbs_compiled(template_name, source)
this.#{template_namespace} || (this.#{template_namespace} = {});
this.#{template_namespace}[#{template_name.dump}] = Handlebars.template(#{compiled_hbs});
return this.#{template_namespace}[#{template_name.dump}];
}).call(this);
}).call(this || window);
END_EXPECTED
end

Expand All @@ -48,7 +47,7 @@ def hbs_compiled_partial(partial_name, source)
<<~END_EXPECTED
(function() {
Handlebars.registerPartial(#{partial_name.dump}, Handlebars.template(#{compiled_hbs}));
}).call(this);
}).call(this || window);
END_EXPECTED
end
end
Expand Down
2 changes: 1 addition & 1 deletion vendor/assets/javascripts/handlebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THE SOFTWARE.
exports["Handlebars"] = factory();
else
root["Handlebars"] = factory();
})(this, function() {
})(this || window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
Expand Down
2 changes: 1 addition & 1 deletion vendor/assets/javascripts/handlebars.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ THE SOFTWARE.
exports["Handlebars"] = factory();
else
root["Handlebars"] = factory();
})(this, function() {
})(this || window, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
Expand Down

0 comments on commit 7b4c6d6

Please sign in to comment.