Add partial hash parser support

This commit is contained in:
kpdecker
2014-01-17 16:31:59 -06:00
parent 93a3725480
commit f90981adf6
5 changed files with 19 additions and 4 deletions
+2 -1
View File
@@ -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;
},
+6 -1
View File
@@ -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 + " }}");
};
+1 -1
View File
@@ -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);
});
});
+8
View File
@@ -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");
});
+2 -1
View File
@@ -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