Browse Source

Fix behavior when rendering lambda sections & add regression test

The `render` argument passed to a `function (text, render)` lambda function was not accounting for custom tags or other configuration. This issue has been fixed and a regression test has been added for this case.
tags/v4.1.0
Sophie Kirschner Phillip Johnsen 4 years ago
parent
commit
862e497c25
4 changed files with 22 additions and 8 deletions
  1. +1
    -1
      mustache.js
  2. +1
    -1
      mustache.min.js
  3. +1
    -1
      mustache.mjs
  4. +19
    -5
      test/render-test.js

+ 1
- 1
mustache.js View File

@@ -597,7 +597,7 @@
// This function is used to render an arbitrary template
// in the current context by higher-order sections.
function subRender (template) {
return self.render(template, context, partials);
return self.render(template, context, partials, config);
}

if (!value) return;


+ 1
- 1
mustache.min.js
File diff suppressed because it is too large
View File


+ 1
- 1
mustache.mjs View File

@@ -590,7 +590,7 @@ Writer.prototype.renderSection = function renderSection (token, context, partial
// This function is used to render an arbitrary template
// in the current context by higher-order sections.
function subRender (template) {
return self.render(template, context, partials);
return self.render(template, context, partials, config);
}

if (!value) return;


+ 19
- 5
test/render-test.js View File

@@ -182,7 +182,13 @@ describe('Mustache.render', function () {
});
it('uses provided config.tags and config.escape when rendering sections', function () {
var template = '<[[&value-raw]] [[#test-1]][[value-1]][[/test-1]][[^test-2]][[value-2]][[/test-2]]>';
var template = (
'<[[&value-raw]]: ' +
'[[#test-1]][[value-1]][[/test-1]]' +
'[[^test-2]][[value-2]][[/test-2]], ' +
'[[#test-lambda]][[value-lambda]][[/test-lambda]]' +
'>'
);
function escapeQuotes (text) {
return '"' + text + '"';
@@ -196,20 +202,28 @@ describe('Mustache.render', function () {
'test-1': true,
'value-1': 'abc',
'test-2': true,
'value-2': '123'
'value-2': '123',
'test-lambda': function () {
return function (text, render) { return 'lambda: ' + render(text); };
},
'value-lambda': 'bar'
};
var viewTestFalse = {
'value-raw': 'foo',
'test-1': false,
'value-1': 'abc',
'test-2': false,
'value-2': '123'
'value-2': '123',
'test-lambda': function () {
return function (text, render) { return 'lambda: ' + render(text); };
},
'value-lambda': 'bar'
};
var outputTrue = Mustache.render(template, viewTestTrue, {}, config);
var outputFalse = Mustache.render(template, viewTestFalse, {}, config);

assert.equal(outputTrue, '<foo "abc">');
assert.equal(outputFalse, '<foo "123">');
assert.equal(outputTrue, '<foo: "abc", lambda: "bar">');
assert.equal(outputFalse, '<foo: "123", lambda: "bar">');
});
});



Loading…
Cancel
Save