Przeglądaj źródła

Cache partials by template, not by name

Fixes #257
tags/0.7.1
Michael Jackson 13 lat temu
rodzic
commit
658f9e051f
1 zmienionych plików z 8 dodań i 6 usunięć
  1. +8
    -6
      mustache.js

+ 8
- 6
mustache.js Wyświetl plik

@@ -193,24 +193,26 @@ var Mustache;
}; };


Writer.prototype.compile = function (template, tags) { Writer.prototype.compile = function (template, tags) {
return this._compile(this._cache, template, template, tags);
return this._compile(template, tags);
}; };


Writer.prototype.compilePartial = function (name, template, tags) { Writer.prototype.compilePartial = function (name, template, tags) {
return this._compile(this._partialCache, name, template, tags);
var fn = this._compile(template, tags);
this._partialCache[name] = fn;
return fn;
}; };


Writer.prototype.render = function (template, view, partials) { Writer.prototype.render = function (template, view, partials) {
return this.compile(template)(view, partials); return this.compile(template)(view, partials);
}; };


Writer.prototype._compile = function (cache, key, template, tags) {
if (!cache[key]) {
Writer.prototype._compile = function (template, tags) {
if (!this._cache[template]) {
var tokens = exports.parse(template, tags); var tokens = exports.parse(template, tags);
var fn = compileTokens(tokens); var fn = compileTokens(tokens);


var self = this; var self = this;
cache[key] = function (view, partials) {
this._cache[template] = function (view, partials) {
if (partials) { if (partials) {
if (typeof partials === "function") { if (typeof partials === "function") {
self._loadPartial = partials; self._loadPartial = partials;
@@ -225,7 +227,7 @@ var Mustache;
}; };
} }


return cache[key];
return this._cache[template];
}; };


Writer.prototype._section = function (name, context, text, callback) { Writer.prototype._section = function (name, context, text, callback) {


Ładowanie…
Anuluj
Zapisz