Connor Taylor GitHub 6 lat temu
rodzic
commit
83e2adead8
Nie znaleziono w bazie danych klucza dla tego podpisu ID klucza GPG: 4AEE18F83AFDEB23
6 zmienionych plików z 17 dodań i 2 usunięć
  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 Wyświetl plik

@@ -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 Wyświetl plik

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

+ 1
- 0
test/_files/partial_function.mustache Wyświetl plik

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

+ 1
- 0
test/_files/partial_function.partial Wyświetl plik

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

+ 1
- 0
test/_files/partial_function.txt Wyświetl plik

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

+ 7
- 1
test/render-test.js Wyświetl plik

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


Ładowanie…
Anuluj
Zapisz