Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
Support partial block statements with --traverse
Browse files Browse the repository at this point in the history
  • Loading branch information
jsahlen committed Mar 6, 2017
1 parent e41ce17 commit 1b24c9a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function findPartials(tree) {
var partials = [];
hbTraverse(tree, function(node) {
// handlebars 3,4
if (node.type === 'PartialStatement' && !inlinePartials[node.name.original]) {
if ((node.type === 'PartialStatement' || node.type === 'PartialBlockStatement') && node.name.original.substr(0,1) !== "@" && !inlinePartials[node.name.original]) {
partials.push(node.name.original);
return
}
Expand Down
5 changes: 5 additions & 0 deletions test/blockPartialBrowserCode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Handlebars = require("hbsfy/runtime");

var template = require("./block_partial_require.hbs");

document.body.innerHTML = template();
1 change: 1 addition & 0 deletions test/block_partial_require.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{#> ./block_partial_required.hbs}}<p>inside</p>{{/./block_partial_required.hbs}}
26 changes: 26 additions & 0 deletions test/block_partial_require_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var concat = require("concat-stream");
var browserify = require("browserify");
var assert = require("assert");
var vm = require("vm");

var b = browserify(__dirname + "/blockPartialBrowserCode.js");
b.transform(require("hbsfy"), { traverse: true });

var context = {
document: {
body: {}
}
};

b.bundle().pipe(concat(function(data) {
var bundle = data.toString();
assert(/require\('.\/block_partial_required\.hbs'\)/.test(bundle), 'looking for require');
assert(/block_partial_required.hbs['"]\:/.test(bundle), 'looking for included partial');
assert(/var partial\$0/.test(bundle), 'looking for partial temp var');
assert(/, partial\$0/.test(bundle), 'looking for partial registration');
vm.runInNewContext(bundle, context);
}));

setTimeout(function() {
assert.equal(context.document.body.innerHTML.trim(), "<div><p>inside</p></div>");
}, 400);
1 change: 1 addition & 0 deletions test/block_partial_required.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>{{> @partial-block}}</div>

0 comments on commit 1b24c9a

Please sign in to comment.