Changeset 9132
- Timestamp:
- 06/20/08 18:01:03 (4 months ago)
- Files:
-
- sandbox/aida/demo-app/app/controllers/say_controller.js (modified) (1 diff)
- sandbox/aida/demo-app/main.js (modified) (1 diff)
- sandbox/aida/modules/aida/controller.js (modified) (1 diff)
- sandbox/aida/modules/aida/controller/layout.js (modified) (2 diffs)
- sandbox/aida/modules/aida/controller/templates.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/aida/demo-app/app/controllers/say_controller.js
r9131 r9132 42 42 43 43 this.index_action = function() { 44 render({layout:null}); 44 45 /* 45 46 res.writeln("---" + getShortName()) sandbox/aida/demo-app/main.js
r9128 r9132 16 16 17 17 importModule("aida.controller"); 18 importFromModule("aida.routing", "RouteSet");19 18 20 19 // main method called to start application sandbox/aida/modules/aida/controller.js
r9130 r9132 47 47 req.route = req.route || routeSet.recognizeRequest(req); 48 48 if (!req.route) return; // FIXME 404 49 varcontroller = getControllerInstance(req.route.controllerName, req, res, session);49 global.controller = getControllerInstance(req.route.controllerName, req, res, session); 50 50 51 51 Object.extend(req.data, req.route.params); sandbox/aida/modules/aida/controller/layout.js
r9130 r9132 23 23 ); 24 24 } 25 26 27 /** 28 * Set a layout for this controller, and override all prvious layout settings. 29 * 30 * @param {String} layout Name of template file, without extension. 31 * @param {Function} layout Functions which returns a template file name. 32 */ 33 this.setLayout = function(layout) { 34 this.layoutChain = [new Layout(this, layout)]; 35 } 25 36 26 37 this.renderLayout = function() { 27 helma.skin.render("app/views/layouts/" + getLayoutName() + ".skin", { "yield" : this.content }); 38 var name = getLayoutName.apply(this); 39 if (name === null) { 40 res.write(this.content); 41 return; 42 } 43 helma.skin.render("app/views/layouts/" + name + ".skin", { "yield" : this.content }); 28 44 } 29 45 … … 37 53 function Layout(controller, layout, param) { 38 54 this.controller = controller; 39 this.name = ( typeof layout === "string") ? layout : layout.apply(controller);55 this.name = (Object.isFunction(layout)) ? layout.apply(controller) : layout; 40 56 this.param = param || {}; 41 57 if (this.param.only && !Object.isArray(this.param.only)) this.param.only = [this.param.only]; sandbox/aida/modules/aida/controller/templates.js
r9130 r9132 92 92 res.calledRender = true; 93 93 var action = options.action || req.route.action; 94 var context = this.prepareContext(options.context); 94 var context = controller.prepareContext(options.context); 95 if (options.layout !== undefined) controller.setLayout(options.layout); 95 96 96 if (typeof options === "string" && options != "") { 97 delete options.layout; 98 99 if (typeof options === "string" && options !== "") { 97 100 res.writeln(options); 98 101 } else if (options && options.inline) { … … 145 148 { 146 149 request : req.data, 147 controller : this,150 controller : controller, 148 151 flash : req.flash, 149 152 headers : req.headers,