| @@ -504,7 +504,9 @@ | |||||
| * Clears all cached templates in this writer. | * Clears all cached templates in this writer. | ||||
| */ | */ | ||||
| Writer.prototype.clearCache = function clearCache () { | Writer.prototype.clearCache = function clearCache () { | ||||
| this.templateCache !== undefined && this.templateCache.clear(); | |||||
| if (typeof this.templateCache !== 'undefined') { | |||||
| this.templateCache.clear(); | |||||
| } | |||||
| }; | }; | ||||
| /** | /** | ||||
| @@ -676,6 +678,9 @@ | |||||
| Writer: undefined, | Writer: undefined, | ||||
| set templateCache (cache) { | set templateCache (cache) { | ||||
| defaultWriter.templateCache = cache; | defaultWriter.templateCache = cache; | ||||
| }, | |||||
| get templateCache () { | |||||
| return defaultWriter.templateCache; | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -497,7 +497,9 @@ function Writer () { | |||||
| * Clears all cached templates in this writer. | * Clears all cached templates in this writer. | ||||
| */ | */ | ||||
| Writer.prototype.clearCache = function clearCache () { | Writer.prototype.clearCache = function clearCache () { | ||||
| this.templateCache !== undefined && this.templateCache.clear(); | |||||
| if (typeof this.templateCache !== 'undefined') { | |||||
| this.templateCache.clear(); | |||||
| } | |||||
| }; | }; | ||||
| /** | /** | ||||
| @@ -669,6 +671,9 @@ var mustache = { | |||||
| Writer: undefined, | Writer: undefined, | ||||
| set templateCache (cache) { | set templateCache (cache) { | ||||
| defaultWriter.templateCache = cache; | defaultWriter.templateCache = cache; | ||||
| }, | |||||
| get templateCache () { | |||||
| return defaultWriter.templateCache; | |||||
| } | } | ||||
| }; | }; | ||||
| @@ -56,20 +56,14 @@ var expectations = { | |||||
| : [ [ '#', 'foo', 0, 8, [ [ '#', 'a', 11, 17, [ [ 'text', ' ', 18, 22 ], [ 'name', 'b', 22, 27 ], [ 'text', '\n', 27, 28 ] ], 30 ] ], 37 ] ] | : [ [ '#', 'foo', 0, 8, [ [ '#', 'a', 11, 17, [ [ 'text', ' ', 18, 22 ], [ 'name', 'b', 22, 27 ], [ 'text', '\n', 27, 28 ] ], 30 ] ], 37 ] ] | ||||
| }; | }; | ||||
| var originalTemplateCache; | |||||
| before(function () { | |||||
| originalTemplateCache = Mustache.templateCache; | |||||
| }); | |||||
| beforeEach(function (){ | beforeEach(function (){ | ||||
| Mustache.clearCache(); | Mustache.clearCache(); | ||||
| Mustache.templateCache = { | |||||
| _cache: {}, | |||||
| set: function set (key, value) { | |||||
| this._cache[key] = value; | |||||
| }, | |||||
| get: function get (key) { | |||||
| return this._cache[key]; | |||||
| }, | |||||
| clear: function clear () { | |||||
| this._cache = {}; | |||||
| } | |||||
| }; | |||||
| Mustache.templateCache = originalTemplateCache; | |||||
| }); | }); | ||||
| describe('Mustache.parse', function () { | describe('Mustache.parse', function () { | ||||