Permalink
Browse files

fix 3x support now that locals.use() is gone. closes #22

  • Loading branch information...
tj committed Jul 30, 2012
1 parent fa9d7ce commit 86d2799633955e0e4fe52ad28fb93eb899abfca6
Showing with 26 additions and 12 deletions.
  1. +26 −12 lib/express-expose.js
View
@@ -43,6 +43,7 @@ exports.name = 'javascript';
res.expose =
app.expose = function(obj, namespace, name){
var app = this.app || this;
+ var req = this.req;
app._exposed = app._exposed || {};
@@ -55,23 +56,36 @@ app.expose = function(obj, namespace, name){
namespace = namespace || exports.namespace;
}
- // register dynamic helper
+ // locals
+ function locals(req, res) {
+ var appjs = app.exposed(name)
+ , resjs = res.exposed(name)
+ , js = '';
+
+ if (appjs || resjs) {
+ js += '// app: \n' + appjs;
+ js += '// res: \n' + resjs;
+ }
+
+ res.locals[name] = js;
+ }
+
+ // locals
+
if (!app._exposed[name]) {
var helpers = {};
app._exposed[name] = true;
- app.locals.use(function(req, res) {
- var appjs = app.exposed(name)
- , resjs = res.exposed(name)
- , js = '';
-
- if (appjs || resjs) {
- js += '// app: \n' + appjs;
- js += '// res: \n' + resjs;
- }
+ // request level
+ if (req) locals(req, this);
- res.locals[name] = js;
- });
+ // app level
+ if (!req) {
+ app.use(function(req, res, next){
+ locals(req, res);
+ next();
+ });
+ }
}
// buffer string

0 comments on commit 86d2799

Please sign in to comment.