Permalink
Browse files

Express 2.x and 3.x support, fixes #14. Also fixes #10

  • Loading branch information...
1 parent cc8c020 commit 46a81cacc0765b9a6483ba43ef834e6d98d4e86d @bengourley bengourley committed Jul 5, 2012
Showing with 104 additions and 173 deletions.
  1. +15 −14 lib/compact.js
  2. +89 −159 test/compact.test.js
View
@@ -199,29 +199,29 @@ module.exports.createCompact = function(options, globalUglifyOptions) {
}
}
- function compactJavascript() {
+ function middleware() {
+
if (arguments.length === 0) {
throw new Error('You must pass one or more arrays containing valid namespace names');
}
+
var namespaceGroups = Array.prototype.slice.call(arguments);
return function(req, res, next) {
processNamespaceGroups(namespaceGroups, function(error, results) {
if (error) {
return next(error);
}
- var app = req.app;
- app.configure(function() {
- app.helpers({
- compactJs: function() {
- return results;
- },
- compactJsHtml: function() {
- return results.map(function(filename) {
- return '<script src="' + filename + '"></script>';
- }).join('');
- }
- });
+
+ res.locals({
+ compactJs: function () {
+ return results;
+ },
+ compactJsHtml: function() {
+ return results.map(function(filename) {
+ return '<script src="' + filename + '"></script>';
+ }).join('');
+ }
});
next();
@@ -231,7 +231,8 @@ module.exports.createCompact = function(options, globalUglifyOptions) {
return {
addNamespace: addNamespace,
- js: compactJavascript,
+ middleware: middleware,
+ js: middleware,
ns: namespaces,
globalUglifyOptions: globalUglifyOptions
};
Oops, something went wrong.

0 comments on commit 46a81ca

Please sign in to comment.