Skip to content

Instantly share code, notes, and snippets.

@insin
Created January 31, 2012 12:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insin/1710254 to your computer and use it in GitHub Desktop.
Save insin/1710254 to your computer and use it in GitHub Desktop.
Add a little whitespace...
function match(prefix, method, route, controllerName, action) {
action = action || 'index'
prefix = prefix == 'root' ? '' : '/' + prefix
route = prefix ? ((route != '/') ? prefix + route : prefix) : route
var controllerFile = app.set('controllers') + prefix + '/' + controllerName + 'Controller'
, Controller = require(controllerFile)
app[method](route, function (req, res, next) {
var inst = new Controller(req, res, next)
, beforeFilters = v(inst.beforeFilters).chain()
.filter(function (f) {
return !v.find(inst.excludeFilters, function (x) {
return x.filter == f.filter && action == x.action
})
})
.filter(function (f) {
return !f.action || f.action == action
})
.map(function (f) {
return function (callback) {
f.filter.call(inst, callback)
}
})
.value()
v.waterfall(beforeFilters, function (err, result) {
if (err) return inst.error(err, v(req.params).values())
inst[action].apply(inst, v(req.params).values())
})
})
}
module.exports.init = function (routes) {
v.each(routes, function(key, value) {
v(value).each(function (tuple) {
tuple.unshift(key)
match.apply(null, tuple)
})
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment