Merge branch 'escape-curly-braces' of github.com:matteodem/meteor into matteodem-escape-curly-braces

This commit is contained in:
David Greenspan
2014-10-28 14:58:52 -07:00
3 changed files with 14 additions and 3 deletions

View File

@@ -150,6 +150,8 @@ _.extend(CodeGen.prototype, {
return BlazeTools.EmitCode(includeCode);
}
} else if (tag.type === 'ESCAPE') {
return HTML.Raw(tag.value);
} else {
// Can't get here; TemplateTag validation should catch any
// inappropriate tag types that might come out of the parser.

View File

@@ -164,6 +164,9 @@ Tinytest.add("spacebars-compiler - stache tags", function (test) {
run('{{foo "="}}', {type: 'DOUBLE', path: ['foo'],
args: [['STRING', '=']]});
run('{{| asdf', { type: 'ESCAPE', value: '{{' });
run('{{{| asdf', { type: 'ESCAPE', value: '{{{' });
run('{{{{| asdf', { type: 'ESCAPE', value: '{{{{' });
});

View File

@@ -12,6 +12,7 @@ SpacebarsCompiler = {};
// - `"BLOCKOPEN"` - `{{#foo}}`
// - `"BLOCKCLOSE"` - `{{/foo}}`
// - `"ELSE"` - `{{else}}`
// - `"ESCAPE"` - `{{|`, `{{{|`, `{{{{|` and so on
//
// Besides `type`, the mandatory properties of a TemplateTag are:
//
@@ -53,6 +54,7 @@ var makeStacheTagStartRegex = function (r) {
};
var starts = {
ESCAPE: makeStacheTagStartRegex(/^[\{]{2,}\|/),
ELSE: makeStacheTagStartRegex(/^\{\{\s*else(?=[\s}])/i),
DOUBLE: makeStacheTagStartRegex(/^\{\{\s*(?!\s)/),
TRIPLE: makeStacheTagStartRegex(/^\{\{\{\s*(?!\s)/),
@@ -88,6 +90,7 @@ TemplateTag.parse = function (scannerOrString) {
return null;
var ret = result[0];
scanner.pos += ret.length;
scanner.current = ret;
return ret;
};
@@ -230,9 +233,10 @@ TemplateTag.parse = function (scannerOrString) {
error('Expected ' + what);
};
// must do ELSE first; order of others doesn't matter
if (run(starts.ELSE)) type = 'ELSE';
// must do ESCAPE first, immediately followed by ELSE
// order of others doesn't matter
if (run(starts.ESCAPE)) type = 'ESCAPE';
else if (run(starts.ELSE)) type = 'ELSE';
else if (run(starts.DOUBLE)) type = 'DOUBLE';
else if (run(starts.TRIPLE)) type = 'TRIPLE';
else if (run(starts.BLOCKCOMMENT)) type = 'BLOCKCOMMENT';
@@ -263,6 +267,8 @@ TemplateTag.parse = function (scannerOrString) {
} else if (type === 'ELSE') {
if (! run(ends.DOUBLE))
expected('`}}`');
} else if (type === 'ESCAPE') {
tag.value = scanner.current.slice(0, -1);
} else {
// DOUBLE, TRIPLE, BLOCKOPEN, INCLUSION
tag.path = scanPath();