Skip to content

Commit

Permalink
Some fixes for template-rendering.
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Nov 21, 2011
1 parent f7905e9 commit 1b53f29
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
20 changes: 7 additions & 13 deletions lib/base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,12 @@ controller.BaseController = function () {
has been sent to the client.
*/
this.completed = false;
/*
// The template root to look in for partials when rendering templates
// Gets created programmatically based on controller name -- see renderTemplate
this.template = undefined;
// Should the layout be rendered
this.layout = true;
this.template = null;
// The template layout directory to look in when rendering templates
// Gets created programmatically based on controller name -- see renderTemplate
this.layoutpath = undefined;
*/
this.layout = null;

};

Expand Down Expand Up @@ -608,11 +604,9 @@ controller.BaseController.prototype = new (function () {
this.template = this.template ||
'app/views/' + dirName + '/' + this.params.action;

if (this.layout) {
// Calculate the layout if not set
this.layoutpath = this.layoutpath ||
'app/views/layouts/' + dirName;
}
// Calculate the layout if not set
this.layout = this.layout ||
'app/views/layouts/' + dirName;

var templater = new Templater();
var content = '';
Expand All @@ -623,11 +617,11 @@ controller.BaseController.prototype = new (function () {
});

templater.addListener('end', function () {
_this.respond(content);
_this.respond(content, 'html');
});

templater.render(data, {
layout: this.layoutpath
layout: this.layout
, template: this.template
, controller: this.name
, action: this.params.action
Expand Down
17 changes: 11 additions & 6 deletions lib/template/adapters/ejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Templater.prototype = new TemplaterBase();
// Override the TempaterBase render method
Templater.prototype.render = function (data, config) {

// Rendering a layout
if (config.layout) {

this.isLayout = true;
this.templateRoot = getDirname(config.layout);

Expand All @@ -53,15 +53,19 @@ Templater.prototype.render = function (data, config) {
});

templaterContent.addListener('end', function () {
data.yield = function () { return contentPartial; };
// Define the `yield` method
data.yield = function () {
return contentPartial;
};
_this.partial(getFilename(config.layout), data);
});

templaterContent.render(data, {template: config.template});
}

// Rendering a regular template
else {
// Set the base path to look for template partials
// Set the base path to look for partials called in this template
this.templateRoot = getDirname(config.template);
filename = getFilename(config.template);
this.partial(filename, data);
Expand Down Expand Up @@ -89,9 +93,10 @@ var getTemplateUrl = function (templateRoot, partialUrl, parentNode, isLayout) {
if (parentNode) {
dirs.push(parentNode.dirname);
}

// Or look in the specified templateRoot
// Also look in the specified templateRoot
dirs.push(templateRoot);
// Also look in the base views dir
dirs.push('app/views');

// Look through the directory list until you find a registered
// template path -- these are registered during app init so we're
Expand All @@ -105,7 +110,7 @@ var getTemplateUrl = function (templateRoot, partialUrl, parentNode, isLayout) {
}
}

// No template
// No template found
if (!templateUrl) {
// If it's a layout, use the default one for the app
if (isLayout) {
Expand Down

0 comments on commit 1b53f29

Please sign in to comment.