Skip to content

Commit

Permalink
Created Application mixin to allow defining global behavior for all c…
Browse files Browse the repository at this point in the history
…ontrollers.
  • Loading branch information
mde committed Mar 26, 2010
1 parent 93879da commit cfc84ca
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions lib/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion scripts/Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '.');
Expand Down

0 comments on commit cfc84ca

Please sign in to comment.