Comparing version 0.0.5 to 0.1.0
@@ -0,1 +1,5 @@ | ||
## v0.1.0 | ||
* Update for express 3 compatibility. | ||
## v0.0.5 | ||
@@ -21,2 +25,2 @@ | ||
* initial version | ||
* initial version |
{ | ||
"name": "jac", | ||
"version": "0.0.5", | ||
"version": "0.1.0", | ||
"description": "jac provides methods to reference asset urls using permanently cachable urls.", | ||
@@ -16,3 +16,3 @@ "main": "index", | ||
"supertest": "~0.5.1", | ||
"express": "~2.5.11", | ||
"express": "~3.4.0", | ||
"should": "~1.2.1", | ||
@@ -19,0 +19,0 @@ "URIjs": "~1.8.3" |
@@ -27,3 +27,3 @@ #jac [](https://travis-ci.org/busbud/jac) | ||
## Example | ||
The following example shows how to wire up jac | ||
The following example shows how to wire up jac with an express 3.x app | ||
* App code sets up the jac middleware | ||
@@ -37,3 +37,3 @@ * A JSON file stores the configuration for the jac middleware | ||
, jac = require('jac') | ||
, app = express.createServer() | ||
, app = express() | ||
, config = require('./config'); | ||
@@ -46,3 +46,3 @@ | ||
app.get('/someview', function (req, res) { | ||
var jac = res.local('jac') // returns jac view helper | ||
var jac = res.locals.jac // returns jac view helper | ||
, key = '/images/happy.png' // matches config key | ||
@@ -147,4 +147,4 @@ , url = jac.resolve(key); // returns url with digest, handled by middleware | ||
## Compatibility | ||
This version of jac is compatible with express 2.5. | ||
It depends on `res.local()` to get and set the view local `jac` via middleware. | ||
This version of jac is compatible with express 3.x. | ||
It depends on `res.locals` to get and set the view local `jac` via middleware. | ||
@@ -151,0 +151,0 @@ ## Production |
@@ -45,14 +45,2 @@ "use strict"; | ||
/** | ||
* Inject jac img view locals | ||
* | ||
* @param res express response object | ||
*/ | ||
function locals (res) { | ||
var jac = res.local('jac') || {}; | ||
jac.resolve = resolveAsset; | ||
res.local('jac', jac); | ||
} | ||
function middleware (req, res, next) { | ||
@@ -62,3 +50,7 @@ var asset = assetsByRoute[req.url]; | ||
if (!asset) { | ||
locals(res); | ||
var jac = res.locals.jac || {}; | ||
jac.resolve = resolveAsset; | ||
res.locals.jac = jac; | ||
return next(); | ||
@@ -65,0 +57,0 @@ } |
@@ -35,8 +35,8 @@ "use strict"; | ||
app.get('/view-spacer', function (req, res) { | ||
res.send(res.local('jac').resolve('/images/spacer.gif')); | ||
res.send(res.locals.jac.resolve('/images/spacer.gif')); | ||
}); | ||
app.get('/view-unresolved', function (req, res) { | ||
res.send(res.local('jac').resolve('/images/noexisto.gif')); | ||
res.send(res.locals.jac.resolve('/images/noexisto.gif')); | ||
}); | ||
app.error(function (err, req, res, next) { | ||
app.use(function (err, req, res, next) { | ||
res.send(err.message, 500); | ||
@@ -47,3 +47,3 @@ }); | ||
after(function () { | ||
app.close(); | ||
app = null; | ||
}); | ||
@@ -50,0 +50,0 @@ |
Sorry, the diff of this file is not supported yet
37444
691