Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version number is now exposed

Blade middleware now integrates with node-static-asset
  • Loading branch information...
commit f72cc5aee278eef734bf8ce4638d29c1608bf6df 1 parent 63ac28d
@bminer authored
Showing with 16 additions and 5 deletions.
  1. +1 −5 bin/blade
  2. +15 −0 lib/blade.js
View
6 bin/blade
@@ -9,11 +9,7 @@ if(!fs.existsSync)
var opts = {};
-try {
- var package = JSON.parse(fs.readFileSync(__dirname + "/../package.json") );
- program.version(package.version);
-} catch(e) {}
-
+program.version(blade.version);
program
.usage("[options] source_path destination_path")
.option("-R, --render", "renders the template and outputs HTML (default)")
View
15 lib/blade.js
@@ -12,6 +12,9 @@ var fs = require("fs"),
Compiler = require("./compiler"),
bladeutil = require("./util");
+try {
+ exports.version = require("../package.json").version;
+} catch(e) {}
exports.compile = compile;
exports.compileFile = compileFile;
exports.Compiler = Compiler;
@@ -101,6 +104,16 @@ function middleware(sourcePath, options) {
sourcePath = path.resolve(sourcePath);
options.compileOptions.basedir = sourcePath;
var fileCache = {}, pluginPath = path.resolve(__dirname + "/../plugins/");
+ function staticAsset(req, path) {
+ //support for node-static-asset
+ if(typeof req.assetFingerprint == "function" && exports.version)
+ {
+ var expires = new Date();
+ expires.setFullYear(expires.getFullYear() + 1);
+ req.assetFingerprint(pathname, pathname + "?v=" + exports.version,
+ {"etag": exports.version, "expires": expires});
+ }
+ }
return function(req, res, next) {
var pathname = url.parse(req.url).pathname;
if(options.runtimeMount && pathname == options.runtimeMount)
@@ -113,6 +126,7 @@ function middleware(sourcePath, options) {
data = bladeutil.uglify(data.toString(), true);
fileCache["runtime"] = data;
res.type("application/javascript").send(data);
+ staticAsset(req, pathname);
});
}
else if(options.pluginsMount &&
@@ -131,6 +145,7 @@ function middleware(sourcePath, options) {
data = bladeutil.uglify(data.toString(), true);
fileCache[fullPath] = data;
res.type("application/javascript").send(data);
+ staticAsset(req, pathname);
});
}
else if(pathname.substr(0, options.mount.length) == options.mount)
Please sign in to comment.
Something went wrong with that request. Please try again.