Skip to content

Commit

Permalink
Express 2.x and 3.x support, fixes #14. Also fixes #10
Browse files Browse the repository at this point in the history
  • Loading branch information
bengourley committed Jul 5, 2012
1 parent cc8c020 commit 46a81ca
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 173 deletions.
29 changes: 15 additions & 14 deletions lib/compact.js
Expand Up @@ -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();
Expand All @@ -231,7 +231,8 @@ module.exports.createCompact = function(options, globalUglifyOptions) {

return {
addNamespace: addNamespace,
js: compactJavascript,
middleware: middleware,
js: middleware,
ns: namespaces,
globalUglifyOptions: globalUglifyOptions
};
Expand Down

0 comments on commit 46a81ca

Please sign in to comment.