summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/handlebars/compiler/ast.js3
-rw-r--r--lib/handlebars/compiler/printer.js7
-rw-r--r--spec/ast.js2
-rw-r--r--spec/parser.js8
-rw-r--r--src/handlebars.yy3
5 files changed, 19 insertions, 4 deletions
diff --git a/lib/handlebars/compiler/ast.js b/lib/handlebars/compiler/ast.js
index dda682e..5538f40 100644
--- a/lib/handlebars/compiler/ast.js
+++ b/lib/handlebars/compiler/ast.js
@@ -97,11 +97,12 @@ var AST = {
// pass or at runtime.
},
- PartialNode: function(partialName, context, strip, locInfo) {
+ PartialNode: function(partialName, context, hash, strip, locInfo) {
LocationInfo.call(this, locInfo);
this.type = "partial";
this.partialName = partialName;
this.context = context;
+ this.hash = hash;
this.strip = strip;
},
diff --git a/lib/handlebars/compiler/printer.js b/lib/handlebars/compiler/printer.js
index ad55c7d..b7b760f 100644
--- a/lib/handlebars/compiler/printer.js
+++ b/lib/handlebars/compiler/printer.js
@@ -82,7 +82,12 @@ PrintVisitor.prototype.mustache = function(mustache) {
PrintVisitor.prototype.partial = function(partial) {
var content = this.accept(partial.partialName);
- if(partial.context) { content = content + " " + this.accept(partial.context); }
+ if(partial.context) {
+ content += " " + this.accept(partial.context);
+ }
+ if (partial.hash) {
+ content += " " + this.accept(partial.hash);
+ }
return this.pad("{{> " + content + " }}");
};
diff --git a/spec/ast.js b/spec/ast.js
index 46f0131..430574e 100644
--- a/spec/ast.js
+++ b/spec/ast.js
@@ -193,7 +193,7 @@ describe('ast', function() {
describe("PartialNode", function(){
it('stores location info', function(){
- var pn = new handlebarsEnv.AST.PartialNode("so_partial", {}, {}, LOCATION_INFO);
+ var pn = new handlebarsEnv.AST.PartialNode("so_partial", {}, {}, {}, LOCATION_INFO);
testLocationInfoStorage(pn);
});
});
diff --git a/spec/parser.js b/spec/parser.js
index 70c1635..0f6ed31 100644
--- a/spec/parser.js
+++ b/spec/parser.js
@@ -84,6 +84,14 @@ describe('parser', function() {
equals(ast_for("{{> foo bar}}"), "{{> PARTIAL:foo ID:bar }}\n");
});
+ it('parses a partial with hash', function() {
+ equals(ast_for("{{> foo bar=bat}}"), "{{> PARTIAL:foo HASH{bar=ID:bat} }}\n");
+ });
+
+ it('parses a partial with context and hash', function() {
+ equals(ast_for("{{> foo bar bat=baz}}"), "{{> PARTIAL:foo ID:bar HASH{bat=ID:baz} }}\n");
+ });
+
it('parses a partial with a complex name', function() {
equals(ast_for("{{> shared/partial?.bar}}"), "{{> PARTIAL:shared/partial?.bar }}\n");
});
diff --git a/src/handlebars.yy b/src/handlebars.yy
index 7bff512..bac1cc9 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -63,7 +63,8 @@ mustache
;
partial
- : OPEN_PARTIAL partialName path? CLOSE -> new yy.PartialNode($2, $3, stripFlags($1, $4), @$)
+ : OPEN_PARTIAL partialName param hash? CLOSE -> new yy.PartialNode($2, $3, $4, stripFlags($1, $5), @$)
+ | OPEN_PARTIAL partialName hash? CLOSE -> new yy.PartialNode($2, undefined, $3, stripFlags($1, $4), @$)
;
simpleInverse