| @@ -122,7 +122,7 @@ | |||
| function parseTemplate (template, tags) { | |||
| if (!template) | |||
| return []; | |||
| var firstNonSpace = true; | |||
| var lineHasNonSpace = false; | |||
| var sections = []; // Stack to hold section tokens | |||
| var tokens = []; // Buffer to hold the tokens | |||
| var spaces = []; // Indices of whitespace tokens on the current line | |||
| @@ -178,7 +178,7 @@ | |||
| indentation += chr; | |||
| } else { | |||
| nonSpace = true; | |||
| firstNonSpace = false; | |||
| lineHasNonSpace = true; | |||
| indentation += ' '; | |||
| } | |||
| @@ -190,7 +190,7 @@ | |||
| stripSpace(); | |||
| indentation = ''; | |||
| tagIndex = 0; | |||
| firstNonSpace = true; | |||
| lineHasNonSpace = false; | |||
| } | |||
| } | |||
| } | |||
| @@ -224,7 +224,7 @@ | |||
| throw new Error('Unclosed tag at ' + scanner.pos); | |||
| if (type == '>') { | |||
| token = [ type, value, start, scanner.pos, indentation, tagIndex, firstNonSpace ]; | |||
| token = [ type, value, start, scanner.pos, indentation, tagIndex, lineHasNonSpace ]; | |||
| } else { | |||
| token = [ type, value, start, scanner.pos ]; | |||
| } | |||
| @@ -612,11 +612,11 @@ | |||
| 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 partialByNl = partial.split('\n'); | |||
| 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]; | |||
| } | |||
| } | |||
| @@ -628,12 +628,12 @@ | |||
| var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; | |||
| if (value != null) { | |||
| var firstNonSpace = token[6]; | |||
| var lineHasNonSpace = token[6]; | |||
| var tagIndex = token[5]; | |||
| var indentation = token[4]; | |||
| var indentedValue = value; | |||
| 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); | |||
| } | |||
| @@ -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', 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 ] ], | |||
| '{{>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, 13 ] ], | |||
| '{{=<% %>=}}<%={{ }}=%>' : [ [ '=', '<% %>', 0, 11 ], [ '=', '{{ }}', 11, 22 ] ], | |||