From be6a9309a23bd6c919e634a18a8c3bce88a5e74b Mon Sep 17 00:00:00 2001 From: Adam Baldwin Date: Fri, 31 Jan 2014 23:49:33 -0800 Subject: [PATCH 1/2] allow passing in context to view handler via bind, and tests --- lib/views.js | 2 +- test/unit/views.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/views.js b/lib/views.js index a986d3284..ca84333a8 100755 --- a/lib/views.js +++ b/lib/views.js @@ -347,7 +347,7 @@ exports.handler = function (route, viewFilePath) { query: request.query }; - reply.view(viewFilePath, context); + reply.view(viewFilePath, request.route.bind || context); }; }; diff --git a/test/unit/views.js b/test/unit/views.js index d971f4b2b..79a4b1094 100755 --- a/test/unit/views.js +++ b/test/unit/views.js @@ -272,5 +272,25 @@ describe('Views', function () { done(); }); }); + + it('handles bind context', function (done) { + var options = { + views: { + engines: { 'jade': 'jade' }, + path: viewsPath + } + }; + + var server = new Hapi.Server(options); + + server.route({ method: 'GET', path: '/', handler: {view: 'valid/index'}, config: {bind: {message: 'heyloo'}}}); + server.inject({ + method: 'GET', + url: '/' + }, function (res) { + expect(res.result).to.contain('heyloo'); + done(); + }); + }); }); }); From c29064831ac2b05313a89e6ecdb960dd202ad5b6 Mon Sep 17 00:00:00 2001 From: Adam Baldwin Date: Sat, 1 Feb 2014 22:24:46 -0800 Subject: [PATCH 2/2] changes to try and conform to style guide --- test/unit/views.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/views.js b/test/unit/views.js index 79a4b1094..eb8bb1458 100755 --- a/test/unit/views.js +++ b/test/unit/views.js @@ -274,6 +274,7 @@ describe('Views', function () { }); it('handles bind context', function (done) { + var options = { views: { engines: { 'jade': 'jade' },