Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Created Application mixin to allow defining global behavior for all c…

…ontrollers.
  • Loading branch information...
commit cfc84ca9bef6475d0a5e6d6613e37bc534ebb3e1 1 parent 93879da
mde authored
Showing with 9 additions and 4 deletions.
  1. +4 −0 lib/app.js
  2. +3 −3 lib/controller.js
  3. +2 −1  scripts/Jakefile.js
View
4 lib/app.js
@@ -38,6 +38,10 @@ var App = function (config) {
constructor.prototype = new Controller(route.controller, params, req, resp);
var controller = new constructor();
+ // Mix in any user-defined Application methods
+ var mixin = new this.controllers.Application();
+ controller = fleegix.mixin(controller, mixin);
+
controller[route.action].call(controller, params);
}
else {
View
6 lib/controller.js
@@ -28,8 +28,8 @@ Controller.prototype = new function () {
this.respond = function (content, format) {
var negotiated = this.negotiateContent(format);
- this.format = negotiated[0];
- this.contentType = negotiated[1];
+ this.format = negotiated.format;
+ this.contentType = negotiated.contentType;
if (!this.contentType) {
throw new errors.NotAcceptableError('Not an acceptable media type.');
@@ -116,7 +116,7 @@ Controller.prototype = new function () {
throw new errors.InternalServerError('Unknown format');
}
- return [format, contentType];
+ return {format: format, contentType: contentType};
};
this.formatContent = function (content) {
View
3  scripts/Jakefile.js
@@ -30,7 +30,8 @@ exports.tasks = {
'mkdir -p ./' + dir + '/app/controllers',
'mkdir -p ./' + dir + '/public',
'cp ~/.node_libraries/geddy/scripts/gen/router.js ' + dir + '/config/',
- 'cp ~/.node_libraries/geddy/scripts/gen/main.js ' + dir + '/app/controllers/'
+ 'cp ~/.node_libraries/geddy/scripts/gen/main.js ' + dir + '/app/controllers/',
+ 'cp ~/.node_libraries/geddy/scripts/gen/application.js ' + dir + '/app/controllers/'
]
runCmds(cmds, function () {
sys.puts('Created app ' + dir + '.');
Please sign in to comment.
Something went wrong with that request. Please try again.