Skip to content

Commit

Permalink
added template cacher param to the renderer signature, and before/aft…
Browse files Browse the repository at this point in the history
…er render event arguments.

Updated the default mustache renderer to work with the new signature.
  • Loading branch information
Davis Clark committed Jan 13, 2012
1 parent 4df21ac commit 9ffa2c9
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/view.js
Expand Up @@ -57,6 +57,16 @@ ViewEngine.prototype.cacheView = function(path) {
}.bind(this));
};

/**
* @api private
*/
ViewEngine.prototype.getCacher = function(path) {
var self = this;
return function(val) {
self.viewCache[path] = val;
}
}

ViewEngine.prototype.respond = function(view, opts) {
opts = opts || {};

Expand Down Expand Up @@ -88,8 +98,9 @@ ViewEngine.prototype.render = function(view, opts) {
layout = layout === true ? 'layout' + ext : layout;

return when(this.viewCache[viewPath] || this.cacheView(viewPath),
function success(str) {
function success(template) {
var renderedView
, cacher
, jsName = setting('shared js name') || 'javascript'
, namespace = setting('shared js namespace') || 'bogart';

Expand All @@ -115,11 +126,12 @@ ViewEngine.prototype.render = function(view, opts) {
opts._renderedShared = true;
}

self.emit('beforeRender', self, opts, str);

renderedView = renderer(str, opts, self);
self.emit('beforeRender', self, opts, template, cacher);

cacher = self.getCacher(viewPath);
renderedView = renderer(template, opts, cacher, self);

self.emit('afterRender', self, opts, str);
self.emit('afterRender', self, opts, template, cacher);

return when(renderedView, function(renderedView) {
if (layout) {
Expand Down Expand Up @@ -208,7 +220,7 @@ exports.viewEngine.engine = function(engineName) {
return engines[engineName];
};

exports.viewEngine.addEngine('mustache', function(str, opts, viewEngine) {
exports.viewEngine.addEngine('mustache', function(str, opts, cache, viewEngine) {
var partialPromises = []
, partials = {}
, viewPath;
Expand Down

0 comments on commit 9ffa2c9

Please sign in to comment.