Permalink
Browse files

Push to 3.0.0rc3

Blade caching mechanism now requires all compilation options to match in order to get a cache "hit" (fixes #123)
  • Loading branch information...
1 parent 8d8eba1 commit 682726c16a6aba7bfcdd9d5dc70357db8f85cd5d @bminer committed Mar 7, 2013
Showing with 16 additions and 10 deletions.
  1. +13 −8 lib/blade.js
  2. +1 −0 lib/compiler.js
  3. +1 −1 package.json
  4. +1 −1 smart.json
View
@@ -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
View
@@ -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,
View
@@ -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",
View
@@ -3,7 +3,7 @@
"author": "Blake Miner <miner.blake@gmail.com> (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": {
}

0 comments on commit 682726c

Please sign in to comment.