Add support for hash args in the tokenizer and parser

This commit is contained in:
tomhuda
2011-03-03 21:33:28 -08:00
parent 51d2543ba1
commit e0aa705f71
6 changed files with 81 additions and 4 deletions
+5
View File
@@ -52,6 +52,11 @@ var Handlebars = require("handlebars");
this.string = string;
};
Handlebars.AST.HashNode = function(pairs) {
this.type = "hash";
this.pairs = pairs;
};
Handlebars.AST.IdNode = function(parts) {
this.type = "ID";
this.original = parts.join("/");
+13
View File
@@ -89,6 +89,19 @@ Handlebars.PrintVisitor.prototype.partial = function(partial) {
return this.pad("{{> " + content + " }}");
};
Handlebars.PrintVisitor.prototype.hash = function(hash) {
var pairs = hash.pairs;
var joinedPairs = [], left, right;
for(var i=0, l=pairs.length; i<l; i++) {
left = pairs[i][0];
right = this.accept(pairs[i][1]);
joinedPairs.push( left + "=" + right );
}
return "HASH{" + joinedPairs.join(", ") + "}";
};
Handlebars.PrintVisitor.prototype.STRING = function(string) {
return '"' + string.string + '"';
};