serby/compact — pull request #17 by bengourley (2012-07-05 21:36:03+00:00)
Title: Support for Express 2.x and 3.x (fixes #14), also fixes #10

This commit switches to using `res.locals` to expose the helper functions to views (rather than `app.dynamicHelpers` or `app.locals`. It also means that the helper functions are scoped only to the request, rather than bleeding through to subsequent requests (which happens when using `app` level functions, as outlined in #10).

The function `js` has been renamed to `middleware` to be more explicit about what it does, however, it is also assigned to `js` for backwards compatibility.

**This commit makes no breaking changes to the API, so projects using previous versions can update without changing.**

------
One thing to note as I was testing on an actual project is to make sure that any middleware that might re-route to a different view should be applied above the compact middleware, eg:

```JS
app.get(
'/:section/:article',
getPageContent,
compact.middleware(['social'], ['contact']),
function(req, res, next) {
res.render('article');
}
);
```

`getPageContent()` might call `next(err)` if it can't find any content, meaning that an error view gets rendered instead of article. If the `compact.middleware` was applied before `getPageContent` the helpers for the 'article' view would be rendered on the error view.