controller.js
Summary
No overview generated for 'controller.js'
var resig = require('resig/resig');
var sys = require('sys');
var helpers = require('mobius-js/helpers/helpers');
var webHelpers = require('mobius-js/helpers/web-helpers')
MobiusController = resig.Class.extend( {
cookies: {},
rendered: false
});
MobiusController.prototype.init = function(mobiusProcessingStack) {
this.mobiusProcessingStack = mobiusProcessingStack;
},
MobiusController.prototype.execute = function(controller, action, express) {
this.action = action || 'index';
this.renderAction = this.action;
if (this.renderAction == 'index') {
this.renderAction = controller;
}
this.express = express;
this._loadParams();
this._loadCookies();
this._invokeAction(this.action);
if (!this.rendered) {
this.mobiusProcessingStack.render({
self : this,
view : this.renderAction + '.html.mejs',
options : {},
}, this._render);
}
},
MobiusController.prototype.render = function(view, options) {
var options = options || {};
this.rendered = true;
this.mobiusProcessingStack.render({
self : this,
view : view,
options : options,
}, this._render);
},
MobiusController.prototype._render = function(params) {
params['self']._setCookies();
params['options']['locals'] = params['self']._getLocals();
params['options']['locals']['partial'] = function(partial) {
return params['self'].express.partial(partial);
}
params['self'].express.render(params['view'], params['options']);
},
MobiusController.prototype._invokeAction = function(action) {
action = helpers.stringToActionName(action, '-');
if (typeof this[action] == 'function') {
this[action].call(this)
} else {
this.express.redirect('/public/errors/action-not-found.html');
}
},
MobiusController.prototype._getLocals = function() {
var locals = {};
for (var key in this) {
if (typeof this[key] != 'function') {
locals[key] = this[key];
}
}
return locals;
},
MobiusController.prototype._loadCookies = function() {
for (var key in this.express.cookies) {
this.cookies[key] = this.express.cookies[key];
}
}
MobiusController.prototype._setCookies = function() {
for (var key in this.cookies) {
this.express.cookie(key, this.cookies[key]);
}
}
MobiusController.prototype._loadParams = function() {
this.params = {};
if (this.express.params.get && this.express.params.post) {
for (var key in this.express.params.post) {
this.express.params.get[key] = this.express.params.post[key];
}
this.params = this.express.params.get;
} else
if (this.express.post) {
this.params = this.express.params.post;
} else
if (this.express.get) {
this.params = this.express.params.get;
}
}
Documentation generated by
JSDoc on Sat May 15 07:53:00 2010