summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLes Hill <leshill@gmail.com>2012-12-13 10:33:20 -0800
committerLes Hill <leshill@gmail.com>2012-12-13 11:15:38 -0800
commit4bb794d814d068361a101a87735e2b9bbcee5115 (patch)
tree954c5fab968696bc3364671ecca47e6ac6c8a4f9 /src
parentfd0560b95124bd6d335c0bd6af907281a22d72ea (diff)
downloadhandlebars.js-4bb794d814d068361a101a87735e2b9bbcee5115.zip
handlebars.js-4bb794d814d068361a101a87735e2b9bbcee5115.tar.gz
handlebars.js-4bb794d814d068361a101a87735e2b9bbcee5115.tar.bz2
Partials can be paths
Allows partials with slashes, a common partial syntax. For example: {{> shared/dude}}
Diffstat (limited to 'src')
-rw-r--r--src/handlebars.l6
-rw-r--r--src/handlebars.yy8
2 files changed, 10 insertions, 4 deletions
diff --git a/src/handlebars.l b/src/handlebars.l
index 87dce26..04c7c4c 100644
--- a/src/handlebars.l
+++ b/src/handlebars.l
@@ -1,5 +1,5 @@
-%x mu emu com
+%x mu emu com par
%%
@@ -19,7 +19,7 @@
<com>[\s\S]*?"--}}" { yytext = yytext.substr(0, yyleng-4); this.popState(); return 'COMMENT'; }
-<mu>"{{>" { return 'OPEN_PARTIAL'; }
+<mu>"{{>" { this.begin("par"); return 'OPEN_PARTIAL'; }
<mu>"{{#" { return 'OPEN_BLOCK'; }
<mu>"{{/" { return 'OPEN_ENDBLOCK'; }
<mu>"{{^" { return 'OPEN_INVERSE'; }
@@ -46,6 +46,8 @@
<mu>[a-zA-Z0-9_$-]+/[=}\s\/.] { return 'ID'; }
<mu>'['[^\]]*']' { yytext = yytext.substr(1, yyleng-2); return 'ID'; }
<mu>. { return 'INVALID'; }
+<par>\s+ { /*ignore whitespace*/ }
+<par>[a-zA-Z0-9_$-/]+ { this.popState(); return 'PARTIAL_NAME'; }
<INITIAL,mu><<EOF>> { return 'EOF'; }
diff --git a/src/handlebars.yy b/src/handlebars.yy
index 70b7777..8929693 100644
--- a/src/handlebars.yy
+++ b/src/handlebars.yy
@@ -45,8 +45,8 @@ mustache
partial
- : OPEN_PARTIAL path CLOSE { $$ = new yy.PartialNode($2); }
- | OPEN_PARTIAL path path CLOSE { $$ = new yy.PartialNode($2, $3); }
+ : OPEN_PARTIAL partialName CLOSE { $$ = new yy.PartialNode($2); }
+ | OPEN_PARTIAL partialName path CLOSE { $$ = new yy.PartialNode($2, $3); }
;
simpleInverse
@@ -91,6 +91,10 @@ hashSegment
| ID EQUALS DATA { $$ = [$1, new yy.DataNode($3)]; }
;
+partialName
+ : PARTIAL_NAME { $$ = new yy.PartialNameNode($1); }
+ ;
+
path
: pathSegments { $$ = new yy.IdNode($1); }
;