Quellcode durchsuchen

change var name

pull/716/head
Yotam Madem vor 6 Jahren
Ursprung
Commit
92aa7134e1
2 geänderte Dateien mit 14 neuen und 14 gelöschten Zeilen
  1. +8
    -8
      mustache.js
  2. +6
    -6
      test/parse-test.js

+ 8
- 8
mustache.js Datei anzeigen

@@ -122,7 +122,7 @@
function parseTemplate (template, tags) { function parseTemplate (template, tags) {
if (!template) if (!template)
return []; return [];
var firstNonSpace = true;
var lineHasNonSpace = false;
var sections = []; // Stack to hold section tokens var sections = []; // Stack to hold section tokens
var tokens = []; // Buffer to hold the tokens var tokens = []; // Buffer to hold the tokens
var spaces = []; // Indices of whitespace tokens on the current line var spaces = []; // Indices of whitespace tokens on the current line
@@ -178,7 +178,7 @@
indentation += chr; indentation += chr;
} else { } else {
nonSpace = true; nonSpace = true;
firstNonSpace = false;
lineHasNonSpace = true;
indentation += ' '; indentation += ' ';
} }


@@ -190,7 +190,7 @@
stripSpace(); stripSpace();
indentation = ''; indentation = '';
tagIndex = 0; tagIndex = 0;
firstNonSpace = true;
lineHasNonSpace = false;
} }
} }
} }
@@ -224,7 +224,7 @@
throw new Error('Unclosed tag at ' + scanner.pos); throw new Error('Unclosed tag at ' + scanner.pos);


if (type == '>') { if (type == '>') {
token = [ type, value, start, scanner.pos, indentation, tagIndex, firstNonSpace ];
token = [ type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace ];
} else { } else {
token = [ type, value, start, scanner.pos ]; token = [ type, value, start, scanner.pos ];
} }
@@ -612,11 +612,11 @@
return this.renderTokens(token[4], context, partials, originalTemplate); return this.renderTokens(token[4], context, partials, originalTemplate);
}; };


Writer.prototype.indentPartial = function indentPartial (partial, indentation, firstNonSpace) {
Writer.prototype.indentPartial = function indentPartial (partial, indentation, lineHasNonSpace) {
var filteredIndentation = indentation.replace(/[^ \t]/g, ''); var filteredIndentation = indentation.replace(/[^ \t]/g, '');
var partialByNl = partial.split('\n'); var partialByNl = partial.split('\n');
for (var i = 0; i < partialByNl.length; i++) { for (var i = 0; i < partialByNl.length; i++) {
if (partialByNl[i].length && (i > 0 || firstNonSpace)) {
if (partialByNl[i].length && (i > 0 || !lineHasNonSpace)) {
partialByNl[i] = filteredIndentation + partialByNl[i]; partialByNl[i] = filteredIndentation + partialByNl[i];
} }
} }
@@ -628,12 +628,12 @@


var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; var value = isFunction(partials) ? partials(token[1]) : partials[token[1]];
if (value != null) { if (value != null) {
var firstNonSpace = token[6];
var lineHasNonSpace = token[6];
var tagIndex = token[5]; var tagIndex = token[5];
var indentation = token[4]; var indentation = token[4];
var indentedValue = value; var indentedValue = value;
if (tagIndex == 0 && indentation) { if (tagIndex == 0 && indentation) {
indentedValue = this.indentPartial(value, indentation, firstNonSpace);
indentedValue = this.indentPartial(value, indentation, lineHasNonSpace);
} }
return this.renderTokens(this.parse(indentedValue, tags), context, partials, indentedValue); return this.renderTokens(this.parse(indentedValue, tags), context, partials, indentedValue);
} }


+ 6
- 6
test/parse-test.js Datei anzeigen

@@ -40,12 +40,12 @@ var expectations = {
'a\n{{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [ [ '#', 'b', 9, 15, [], 16 ] ], 23 ], [ 'text', 'b', 30, 31 ] ], 'a\n{{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 2, 8, [ [ '#', 'b', 9, 15, [], 16 ] ], 23 ], [ 'text', 'b', 30, 31 ] ],
'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 31, 32 ] ], 'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}}\nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 31, 32 ] ],
'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 32, 33 ] ], 'a\n {{#a}}\n{{#b}}\n{{/b}}\n{{/a}} \nb' : [ [ 'text', 'a\n', 0, 2 ], [ '#', 'a', 3, 9, [ [ '#', 'b', 10, 16, [], 17 ] ], 24 ], [ 'text', 'b', 32, 33 ] ],
'{{>abc}}' : [ [ '>', 'abc', 0, 8, '', 0, true ] ],
'{{> abc }}' : [ [ '>', 'abc', 0, 10, '', 0, true ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, true ] ],
' {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, true ] ],
' {{> abc }} {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, true ], [ '>', 'abc', 13, 23, ' ', 1, true ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, true ] ],
'{{>abc}}' : [ [ '>', 'abc', 0, 8, '', 0, false ] ],
'{{> abc }}' : [ [ '>', 'abc', 0, 10, '', 0, false ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, false ] ],
' {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, false ] ],
' {{> abc }} {{> abc }}\n' : [ [ '>', 'abc', 2, 12, ' ', 0, false ], [ '>', 'abc', 13, 23, ' ', 1, false ] ],
'{{ > abc }}' : [ [ '>', 'abc', 0, 11, '', 0, false ] ],
'{{=<% %>=}}' : [ [ '=', '<% %>', 0, 11 ] ], '{{=<% %>=}}' : [ [ '=', '<% %>', 0, 11 ] ],
'{{= <% %> =}}' : [ [ '=', '<% %>', 0, 13 ] ], '{{= <% %> =}}' : [ [ '=', '<% %>', 0, 13 ] ],
'{{=<% %>=}}<%={{ }}=%>' : [ [ '=', '<% %>', 0, 11 ], [ '=', '{{ }}', 11, 22 ] ], '{{=<% %>=}}<%={{ }}=%>' : [ [ '=', '<% %>', 0, 11 ], [ '=', '{{ }}', 11, 22 ] ],


Laden…
Abbrechen
Speichern