Connor Taylor GitHub 6 лет назад
Родитель
Сommit
83e2adead8
Не найден GPG ключ соответствующий данной подписи Идентификатор GPG ключа: 4AEE18F83AFDEB23
6 измененных файлов: 17 добавлений и 2 удалений
  1. +3
    -1
      mustache.js
  2. +4
    -0
      test/_files/partial_function.js
  3. +1
    -0
      test/_files/partial_function.mustache
  4. +1
    -0
      test/_files/partial_function.partial
  5. +1
    -0
      test/_files/partial_function.txt
  6. +7
    -1
      test/render-test.js

+ 3
- 1
mustache.js Просмотреть файл

@@ -595,7 +595,9 @@
Writer.prototype.renderPartial = function renderPartial (token, context, partials, tags) {
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, tags), context, partials, value);
};


+ 4
- 0
test/_files/partial_function.js Просмотреть файл

@@ -0,0 +1,4 @@
({
id: 'main',
value: 'foo'
})

+ 1
- 0
test/_files/partial_function.mustache Просмотреть файл

@@ -0,0 +1 @@
{{>partial}}

+ 1
- 0
test/_files/partial_function.partial Просмотреть файл

@@ -0,0 +1 @@
{{id}}: {{value}}

+ 1
- 0
test/_files/partial_function.txt Просмотреть файл

@@ -0,0 +1 @@
main: foo

+ 7
- 1
test/render-test.js Просмотреть файл

@@ -65,7 +65,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);
}


Загрузка…
Отмена
Сохранить