Permalink
Browse files

fixed request-level exposure. closes #26

  • Loading branch information...
1 parent 905d6be commit 581590f59e7c24ff63add4b2ef29f2931416813a @jonpacker jonpacker committed Aug 14, 2012
Showing with 26 additions and 32 deletions.
  1. +26 −32 lib/express-expose.js
View
58 lib/express-expose.js
@@ -56,38 +56,6 @@ app.expose = function(obj, namespace, name){
namespace = namespace || exports.namespace;
}
- // 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;
-
- // request level
- if (req) locals(req, this);
-
- // app level
- if (!req) {
- app.use(function(req, res, next){
- locals(req, res);
- next();
- });
- }
- }
-
// buffer string
if ('string' == typeof obj) {
this.js = this.js || {};
@@ -106,6 +74,32 @@ app.expose = function(obj, namespace, name){
this.expose('\n');
}
+ // 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;
+ }
+
+ // app level locals
+ if (!req && !app._exposed[name]) {
+ app._exposed[name] = true;
+ app.use(function(req, res, next){
+ locals(req, res);
+ next();
+ });
+ // request level locals
+ } else if (req) {
+ locals(req, this);
+ }
+
return this;
};

0 comments on commit 581590f

Please sign in to comment.