Created
October 25, 2011 02:56
-
-
Save pacovell/1311177 to your computer and use it in GitHub Desktop.
Red in all controllers in the base dir and add them to the returned object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Done. Controllers manager | |
Copyright (c) 2011 Done. Corporation | |
*/ | |
var fs = require('fs'), | |
dispatch = require('dispatch'), | |
logger = require(process.cwd() + '/lib/loggers').get('controller'); | |
var Controllers = function () { | |
var self = this, | |
path = process.cwd() + '/app/controllers'; | |
self.router = new dispatch.Router(); | |
fs.readdirSync(path).forEach(function (filename) { | |
var name = filename.split('_'); | |
var controller; | |
// Skip controllers.js | |
if (name.length > 1) { | |
controller = require([path, filename].join('/')); | |
name = name[0]; | |
self[name] = controller; | |
self.router.addResource(controller); | |
logger.debug('Loaded controller ' + controller.name); | |
} | |
}); | |
}; | |
module.exports = new Controllers(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment