Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

view engine renderer signature changes #42

Merged
merged 3 commits into from

2 participants

@jdc0589

added the "cache" function param to the view engine renderer signature as well as the before/after render events. Updated the default mustache renderer to work with the new signature. Also fixed the view test which has been broken for a bit.

Davis Clark added some commits
Davis Clark bumped version 3008b10
Davis Clark added template cacher param to the renderer signature, and before/aft…
…er render event arguments.

Updated the default mustache renderer to work with the new signature.
9ffa2c9
Davis Clark fixed view test (has been broken since at least commit 4df21ac efdb431
@nrstott nrstott closed this
@nrstott nrstott reopened this
@nrstott nrstott merged commit dcd4041 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 24, 2011
  1. bumped version

    Davis Clark authored
Commits on Jan 13, 2012
  1. added template cacher param to the renderer signature, and before/aft…

    Davis Clark authored
    …er render event arguments.
    
    Updated the default mustache renderer to work with the new signature.
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 8 deletions.
  1. +18 −6 lib/view.js
  2. +1 −1  package.json
  3. +1 −1  test/view.test.js
View
24 lib/view.js
@@ -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 || {};
@@ -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';
@@ -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) {
@@ -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;
View
2  package.json
@@ -1,7 +1,7 @@
{
"name": "bogart",
"description": "Fast JSGI web framework taking inspiration from Sinatra",
- "version": "0.3.36",
+ "version": "0.3.37",
"keywords": ["bogart", "framework", "sinatra", "REST"],
"author": "Nathan Stott <nrstott@gmail.com>",
"email": "nathan.stott@whiteboard-it.com",
View
2  test/view.test.js
@@ -22,7 +22,7 @@ test('test render mustache with partials', function(t) {
var viewEngine = bogart.viewEngine('mustache', fixturesPath);
when(viewEngine.render('partial-test.mustache', { layout: false, locals: { greeting: {} }, partials: { greeting: 'greeting.mustache' } }), function(str) {
- t.equal(renderedText, '<h1>Hello World from Mustache</h1>');
+ t.equal(str, "<h1>Hello World from Mustache</h1><p>With Partial</p>");
t.end();
}, function(err) {
t.fail(err);
Something went wrong with that request. Please try again.