From 682726c16a6aba7bfcdd9d5dc70357db8f85cd5d Mon Sep 17 00:00:00 2001 From: Blake Miner Date: Thu, 7 Mar 2013 16:54:11 +0000 Subject: [PATCH] Push to 3.0.0rc3 Blade caching mechanism now requires all compilation options to match in order to get a cache "hit" (fixes #123) --- lib/blade.js | 21 +++++++++++++-------- lib/compiler.js | 1 + package.json | 2 +- smart.json | 2 +- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/blade.js b/lib/blade.js index 6d4aa71..7c505e7 100644 --- a/lib/blade.js +++ b/lib/blade.js @@ -30,17 +30,22 @@ function compile(string, options, cb) { if(options.filename) options.filename = path.resolve(options.filename); - if(options.cache && !options.filename) - cb(new Error("The `filename` option is required for caching")); - else if(options.cache && cache[options.filename]) - cb(null, cache[options.filename]); + if(options.cache) + { + if(!options.filename) + return cb(new Error("The `filename` option is required for caching")); + else + var cacheKey = JSON.stringify(options); + } + if(cacheKey && cache[cacheKey]) + cb(null, cache[cacheKey]); else { var compiler = new Compiler(string, options); compiler.compile(function(err, tmpl) { if(err) return cb(err); - if(options.cache) - cache[options.filename] = tmpl; + if(cacheKey) + cache[cacheKey] = tmpl; cb(null, tmpl); }); } @@ -98,11 +103,11 @@ function middleware(sourcePath, options) { options.compileOptions = { "cache": process.env.NODE_ENV == "production", "minify": process.env.NODE_ENV == "production", - "includeSource": process.env.NODE_ENV == "development", - "middleware": true + "includeSource": process.env.NODE_ENV == "development" }; sourcePath = path.resolve(sourcePath); options.compileOptions.basedir = sourcePath; + options.compileOptions.middleware = true; var fileCache = {}, pluginPath = path.resolve(__dirname + "/../plugins/"); function staticAsset(req, path) { //support for node-static-asset diff --git a/lib/compiler.js b/lib/compiler.js index 65ff964..69214ec 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -41,6 +41,7 @@ function Compiler(string, opts) { this.options.basedir = path.resolve(this.options.basedir) || process.cwd(); this.options.reldir = path.dirname(path.relative( this.options.basedir, this.options.filename) ); + //Hide full paths for templates compiled by the Blade middleware if(this.options.middleware) { this.options.filename = path.relative(this.options.basedir, diff --git a/package.json b/package.json index ed5577b..e8a1041 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "live binding", "meteor" ], - "version": "3.0.0rc2", + "version": "3.0.0rc3", "homepage": "https://github.com/bminer/node-blade", "repository": { "type": "git", diff --git a/smart.json b/smart.json index a45ab33..bdecbf9 100644 --- a/smart.json +++ b/smart.json @@ -3,7 +3,7 @@ "author": "Blake Miner (http://www.blakeminer.com/)", "description": "Blade - HTML Template Compiler, inspired by Jade & Haml", "homepage": "https://github.com/bminer/node-blade", - "version": "3.0.0rc2", + "version": "3.0.0rc3", "git": "https://github.com/bminer/node-blade.git", "packages": { }