Make raw blocks operate like blocks
This commit is contained in:
@@ -131,13 +131,18 @@ var AST = {
|
||||
}
|
||||
},
|
||||
|
||||
RawBlockNode: function(mustache, content, locInfo) {
|
||||
RawBlockNode: function(mustache, content, close, locInfo) {
|
||||
LocationInfo.call(this, locInfo);
|
||||
|
||||
if (mustache.sexpr.id.original !== close) {
|
||||
throw new Exception(mustache.sexpr.id.original + " doesn't match " + close, this);
|
||||
}
|
||||
|
||||
content = new AST.ContentNode(content, locInfo);
|
||||
|
||||
this.type = 'block';
|
||||
this.mustache = mustache;
|
||||
mustache.sexpr.isHelper = mustache.isHelper = true;
|
||||
mustache.params.splice(0, 0, new AST.StringNode(content, locInfo));
|
||||
this.program = new AST.ProgramNode([content], locInfo);
|
||||
},
|
||||
|
||||
ContentNode: function(string, locInfo) {
|
||||
|
||||
+4
-4
@@ -12,8 +12,8 @@ describe('helpers', function() {
|
||||
it("helper for raw block gets raw content", function() {
|
||||
var string = "{{{{raw}}}} {{test}} {{{{/raw}}}}";
|
||||
var hash = { test: "hello" };
|
||||
var helpers = { raw: function(content) {
|
||||
return content;
|
||||
var helpers = { raw: function(options) {
|
||||
return options.fn();
|
||||
} };
|
||||
shouldCompileTo(string, [hash, helpers], " {{test}} ",
|
||||
"raw block helper gets raw content");
|
||||
@@ -22,8 +22,8 @@ describe('helpers', function() {
|
||||
it("helper for raw block gets parameters", function() {
|
||||
var string = "{{{{raw 1 2 3}}}} {{test}} {{{{/raw}}}}";
|
||||
var hash = { test: "hello" };
|
||||
var helpers = { raw: function(content, a, b, c) {
|
||||
return content + a + b + c;
|
||||
var helpers = { raw: function(a, b, c, options) {
|
||||
return options.fn() + a + b + c;
|
||||
} };
|
||||
shouldCompileTo(string, [hash, helpers], " {{test}} 123",
|
||||
"raw block helper gets raw content");
|
||||
|
||||
@@ -157,6 +157,10 @@ describe('parser', function() {
|
||||
shouldThrow(function() {
|
||||
ast_for("{{#goodbyes}}{{/hellos}}");
|
||||
}, Error, /goodbyes doesn't match hellos/);
|
||||
|
||||
shouldThrow(function() {
|
||||
ast_for("{{{{goodbyes}}}} {{{{/hellos}}}}");
|
||||
}, Error, /goodbyes doesn't match hellos/);
|
||||
});
|
||||
|
||||
it('knows how to report the correct line number in errors', function() {
|
||||
|
||||
+10
-2
@@ -49,7 +49,11 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
|
||||
return 'CONTENT';
|
||||
}
|
||||
|
||||
<raw>"{{{{/"[^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]"}}}}" { yytext = yytext.substr(5, yyleng-9); this.popState(); return 'END_RAW_BLOCK'; }
|
||||
<raw>"{{{{/"[^\s!"#%-,\.\/;->@\[-\^`\{-~]+/[=}\s\/.]"}}}}" {
|
||||
yytext = yytext.substr(5, yyleng-9);
|
||||
this.popState();
|
||||
return 'END_RAW_BLOCK';
|
||||
}
|
||||
<raw>[^\x00]*?/("{{{{/") { return 'CONTENT'; }
|
||||
|
||||
<com>[\s\S]*?"--}}" strip(0,4); this.popState(); return 'COMMENT';
|
||||
@@ -58,7 +62,11 @@ ID [^\s!"#%-,\.\/;->@\[-\^`\{-~]+/{LOOKAHEAD}
|
||||
<mu>")" return 'CLOSE_SEXPR';
|
||||
|
||||
<mu>"{{{{" { return 'OPEN_RAW_BLOCK'; }
|
||||
<mu>"}}}}" { this.popState(); this.begin('raw'); return 'CLOSE_RAW_BLOCK'; }
|
||||
<mu>"}}}}" {
|
||||
this.popState();
|
||||
this.begin('raw');
|
||||
return 'CLOSE_RAW_BLOCK';
|
||||
}
|
||||
<mu>"{{{{"[^\x00]*"}}}}" {
|
||||
yytext = yytext.substr(4, yyleng-8);
|
||||
this.popState();
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ statements
|
||||
;
|
||||
|
||||
statement
|
||||
: openRawBlock CONTENT END_RAW_BLOCK -> new yy.RawBlockNode($1, $2, @$)
|
||||
: openRawBlock CONTENT END_RAW_BLOCK -> new yy.RawBlockNode($1, $2, $3, @$)
|
||||
| openInverse program closeBlock -> new yy.BlockNode($1, $2.inverse, $2, $3, @$)
|
||||
| openBlock program closeBlock -> new yy.BlockNode($1, $2, $2.inverse, $3, @$)
|
||||
| mustache -> $1
|
||||
|
||||
Reference in New Issue
Block a user