Skip to content
Browse files

0.0.1

  • Loading branch information...
1 parent 6d7b4c7 commit a1640d255a61d49ab99071b02935fedbd71fd6c7 @morozovsk committed Jun 14, 2012
Showing with 21 additions and 8 deletions.
  1. +20 −7 controller.js
  2. +1 −1 samples/sample-without-modules/app/controllers/index.js
View
27 controller.js
@@ -10,27 +10,40 @@ module.exports = function (mvc, app, request, response) {
this._redirect = response.redirect;
this._formats = [];
- this._view = {};
this._template = null;
this._layout = null;
- this._local = response.local;
- this._locals = response.locals;
+ this._local = function(name, val){
+ this.locals = this.locals || {};
+ return undefined === val
+ ? this.locals[name]
+ : this.locals[name] = val;
+ };
+
+ this._locals = this.helpers = function(obj){
+ if (obj) {
+ for (var key in obj) {
+ this.local(key, obj[key]);
+ }
+ } else {
+ return this.locals;
+ }
+ };
this._render = function () {
- return response.render(request.params.controller + '/' + request.params.action, this._view);
+ return response.render(request.params.controller + '/' + request.params.action, this._locals());
}
this._json = function () {
- return response.json(this._view);
+ return response.json(response.locals());
}
this._jsonp = function () {
- return response.send(request.query.callback + '(' + JSON.stringify(this._view) + ');');
+ return response.send(request.query.callback + '(' + JSON.stringify(response.locals()) + ');');
}
this._xml = function () {
- return response.send(require('mvc/xml').XML.stringify(this._view));
+ return response.send(require('mvc/xml').XML.stringify(response.locals()));
}
this._output = function () {
View
2 samples/sample-without-modules/app/controllers/index.js
@@ -1,6 +1,6 @@
module.exports = function() {
this.indexAction = function() {
var model = this._model('message');
- this._view.info = model.getInfo();
+ this._local('info', model.getInfo());
}
}

0 comments on commit a1640d2

Please sign in to comment.
Something went wrong with that request. Please try again.