bootstrap.js
Summary
No overview generated for 'bootstrap.js'
require.paths.unshift('./app');
var fs = require('fs');
var sys = require('sys');
var helpers = require('mobius-js/helpers/helpers');
var Bootstrap = function() {}
Bootstrap.prototype.loadControllers = function(callback) {
var controllers = {};
fs.readdir("app/controllers/", function (err, files) {
if (err) {
throw err;
}
for (var key in files) {
var controllerFile = files[key].split('.')[0];
if (files[key].split('.')[1] == 'js') {
controllers[controllerFile.toLowerCase()] = (require('controllers/' + controllerFile))[helpers.stringToClassName(controllerFile, '-')];
}
}
callback();
});
return controllers;
};
exports.loadControllers = Bootstrap.prototype.loadControllers;
Bootstrap.prototype.loadModels = function(callback) {
var models = {}
fs.readdir("app/models/", function (err, files) {
if (err) throw err;
for (var key in files) {
var modelFile = files[key].split('.')[0];
if (files[key].split('.')[1] == 'js') {
models[modelFile.toLowerCase()] = (require('models/' + modelFile))[helpers.stringToClassName(modelFile, '-')];
}
}
callback();
});
return models;
}
exports.loadModels = Bootstrap.prototype.loadModels;
Bootstrap.prototype.initializeRoutes = function(routes, controllers, mobiusProcessingStack) {
for (var key in routes) {
var callback = function(controller, action, id) {
if (!controller) {
controller = arguments.callee.prototype.controller;
}
if (!action) {
action = arguments.callee.prototype.action;
}
controllerInstance = new controllers[controller.toLowerCase()](mobiusProcessingStack);
controllerInstance.execute(controller, action, this);
}
var staticCallback = function(file) {
var path = arguments.callee.prototype.path || '';
if (file) {
this.sendfile(path + '/' + file);
} else {
this.sendfile(path);
}
}
callback.prototype.controller = routes[key]['controller'];
callback.prototype.action = routes[key]['action'];
staticCallback.prototype.path = routes[key]['path'];
if (routes[key]['type'] == 'static') {
get(routes[key]['route'], staticCallback);
} else if (routes[key]['method'] == 'post') {
post(routes[key]['route'], callback);
} else {
get(routes[key]['route'], callback);
}
}
}
exports.initializeRoutes = Bootstrap.prototype.initializeRoutes;
Bootstrap.prototype.createIndexes = function(models, mobiusProcessingStack) {
for (var modelKey in models) {
var modelClassName = helpers.stringToClassName(modelKey, '-');
models[modelKey].prototype['className'] = modelClassName;
var modelInstance = new models[modelKey](mobiusProcessingStack, models[modelKey]);
var indexes = ['meta', ['_id', 1]];
for (var variableKey in models[modelKey]) {
if (variableKey != 'constructor' && variableKey != 'extend' && variableKey != 'include') {
if (models[modelKey][variableKey]['index']) {
var newIndex = [variableKey, 1];
indexes.push(newIndex);
}
}
}
modelInstance.createIndex({'indexes' : indexes});
}
}
exports.createIndexes = Bootstrap.prototype.createIndexes;
Bootstrap.prototype.initializeControllers = function(controllers, models, mobiusProcessingStack) {
for (var modelKey in models) {
var modelInstance = new models[modelKey](mobiusProcessingStack, models[modelKey]);
var modelClassName = helpers.stringToClassName(modelKey, '-');
for (var controllerKey in controllers) {
MobiusModel[modelClassName] = modelInstance;
}
}
}
exports.initializeControllers = Bootstrap.prototype.initializeControllers;
Documentation generated by
JSDoc on Sat May 15 07:53:00 2010