Skip to content

Commit

Permalink
Push to 3.0.0rc3
Browse files Browse the repository at this point in the history
Blade caching mechanism now requires all compilation options to match in order to get a cache "hit" (fixes #123)
  • Loading branch information
bminer committed Mar 7, 2013
1 parent 8d8eba1 commit 682726c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
21 changes: 13 additions & 8 deletions lib/blade.js
Expand Up @@ -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);
});
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/compiler.js
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion smart.json
Expand Up @@ -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": {
}
Expand Down

0 comments on commit 682726c

Please sign in to comment.