From afe3c41766526fba9088a71b428ab6a56be6ce54 Mon Sep 17 00:00:00 2001 From: Brian Hall Date: Thu, 11 Feb 2016 14:31:59 -0800 Subject: [PATCH 1/2] fix nested partial view client render issue --- shared/helpers/view.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/shared/helpers/view.js b/shared/helpers/view.js index c5d67b3..e2de6ee 100644 --- a/shared/helpers/view.js +++ b/shared/helpers/view.js @@ -32,7 +32,7 @@ module.exports = function (Handlebars) { var parentView = getProperty('_view', this, options); html = getServerHtml(viewName, viewOptions, parentView); } else { - html = getClientPlaceholder(viewName, viewOptions); + html = getClientPlaceholder(viewName, viewOptions, Handlebars); } return new Handlebars.SafeString(html); @@ -55,7 +55,7 @@ function getServerHtml(viewName, viewOptions, parentView) { return view.getHtml(); } -function getClientPlaceholder(viewName, viewOptions) { +function getClientPlaceholder(viewName, viewOptions, Handlebars) { if (!BaseView) { BaseView = require('rendr/shared/base/view'); } var fetchSummary; @@ -67,7 +67,13 @@ function getClientPlaceholder(viewName, viewOptions) { // create a list of data attributes var attrString = _.inject(viewOptions, function(memo, value, key) { - if (_.isArray(value) || _.isObject(value)) { value = JSON.stringify(value); } + if (_.isArray(value) || _.isObject(value)) { + if (key === '_block' && value.contructor === Handlebars.SafeString) { + value = value.string; + } else { + value = JSON.stringify(value); + } + } return memo += " data-" + key + "=\"" + _.escape(value) + "\""; }, ''); From 7e92d651ba0b0b2fad984cf89bdc93c21829189c Mon Sep 17 00:00:00 2001 From: Brian Hall Date: Mon, 22 Feb 2016 17:27:19 -0800 Subject: [PATCH 2/2] changed type compare to instanceof and added test --- shared/helpers/view.js | 2 +- test/shared/helpers/view.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/shared/helpers/view.js b/shared/helpers/view.js index e2de6ee..c53c93b 100644 --- a/shared/helpers/view.js +++ b/shared/helpers/view.js @@ -68,7 +68,7 @@ function getClientPlaceholder(viewName, viewOptions, Handlebars) { // create a list of data attributes var attrString = _.inject(viewOptions, function(memo, value, key) { if (_.isArray(value) || _.isObject(value)) { - if (key === '_block' && value.contructor === Handlebars.SafeString) { + if (key === '_block' && value instanceof Handlebars.SafeString) { value = value.string; } else { value = JSON.stringify(value); diff --git a/test/shared/helpers/view.test.js b/test/shared/helpers/view.test.js index 6fc0ded..79e5e6a 100644 --- a/test/shared/helpers/view.test.js +++ b/test/shared/helpers/view.test.js @@ -175,6 +175,22 @@ describe('view', function () { '
' ); }); + + context('when the key is _block and is of type Handlebars.SafeString', function () { + it('extracts the string correctly', function () { + var html = '
something
', + result = subject.call({ + _app: app() + }, 'test', { + hash: { + _block: new Handlebars.SafeString(html) + } + }); + expect(result.string).to.eq( + '
' + ); + }); + }); }); }); });