Make the ID node capable of handling paths

TODO: handle invalid paths in the tokenizer or parser
  TODO: invalidate "{{ foo/ bar }}"
This commit is contained in:
wycats
2010-11-25 16:12:50 -08:00
parent 7d0204bf9f
commit f8b245896d
5 changed files with 31 additions and 10 deletions
+6 -1
View File
@@ -33,6 +33,11 @@ Handlebars.HandlebarsLexer.prototype.lex = function() {
if(lookahead === "") return;
if(this.state == "MUSTACHE") {
if(this.peek() === "/") {
this.getchar();
return "SEP";
}
// chomp optional whitespace
while(this.peek() === " ") { this.ignorechar(); }
@@ -64,7 +69,7 @@ Handlebars.HandlebarsLexer.prototype.lex = function() {
// All other cases are IDs or errors
} else {
// grab alphanumeric characters
while(this.peek().match(/[0-9A-Za-z]/)) { this.getchar() }
while(this.peek().match(/[0-9A-Za-z\.]/)) { this.getchar() }
// if any characters were grabbed => ID
if(this.yytext.length) { return "ID" }
+6 -1
View File
@@ -79,7 +79,12 @@ Handlebars.PrintVisitor.prototype.STRING = function(string) {
};
Handlebars.PrintVisitor.prototype.ID = function(id) {
return "ID:" + id.id;
var path = id.id.join("/");
if(id.id.length > 1) {
return "PATH:" + path;
} else {
return "ID:" + path;
}
};
Handlebars.PrintVisitor.prototype.content = function(content) {