diff --git a/mustache.js b/mustache.js index 5ffdfe64e..aeb138429 100644 --- a/mustache.js +++ b/mustache.js @@ -545,7 +545,9 @@ Writer.prototype.renderPartial = function renderPartial (token, context, partials) { if (!partials) return; - var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; + var value = isFunction(partials) + ? partials(token[1], context.view) + : partials[token[1]]; if (value != null) return this.renderTokens(this.parse(value), context, partials, value); }; diff --git a/test/_files/partial_function.js b/test/_files/partial_function.js new file mode 100644 index 000000000..8ba5d313d --- /dev/null +++ b/test/_files/partial_function.js @@ -0,0 +1,4 @@ +({ + id: 'main', + value: 'foo' +}) \ No newline at end of file diff --git a/test/_files/partial_function.mustache b/test/_files/partial_function.mustache new file mode 100644 index 000000000..7a336fee8 --- /dev/null +++ b/test/_files/partial_function.mustache @@ -0,0 +1 @@ +{{>partial}} \ No newline at end of file diff --git a/test/_files/partial_function.partial b/test/_files/partial_function.partial new file mode 100644 index 000000000..e1f426b1e --- /dev/null +++ b/test/_files/partial_function.partial @@ -0,0 +1 @@ +{{id}}: {{value}} \ No newline at end of file diff --git a/test/_files/partial_function.txt b/test/_files/partial_function.txt new file mode 100644 index 000000000..e7ea4f016 --- /dev/null +++ b/test/_files/partial_function.txt @@ -0,0 +1 @@ +main: foo \ No newline at end of file diff --git a/test/render-test.js b/test/render-test.js index e9d61a9da..e24a0201c 100644 --- a/test/render-test.js +++ b/test/render-test.js @@ -23,7 +23,13 @@ describe('Mustache.render', function () { it('knows how to render ' + test.name, function () { var output; if (test.partial) { - output = Mustache.render(test.template, view, { partial: test.partial }); + // Ensure partials can be retreived via an object or a function + // See Writer.prototype.renderPartial + var partial = test.name === 'partial_function' + ? function (partial, context) { return test.partial } + : { partial: test.partial }; + + output = Mustache.render(test.template, view, partial); } else { output = Mustache.render(test.template, view); }