Skip to content

Commit

Permalink
Merge pull request #59 from brian-hall/fix_partial_view_nesting
Browse files Browse the repository at this point in the history
fix nested partial view client render issue
  • Loading branch information
saponifi3d committed Feb 24, 2016
2 parents 7b3b7a6 + 7e92d65 commit a3e81fd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
12 changes: 9 additions & 3 deletions shared/helpers/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;

Expand All @@ -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 instanceof Handlebars.SafeString) {
value = value.string;
} else {
value = JSON.stringify(value);
}
}
return memo += " data-" + key + "=\"" + _.escape(value) + "\"";
}, '');

Expand Down
16 changes: 16 additions & 0 deletions test/shared/helpers/view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,22 @@ describe('view', function () {
'<div data-render="true" data-generic_object="{&quot;a&quot;:1,&quot;b&quot;:2,&quot;c&quot;:3}" data-fetch_summary="{}" data-view="test"></div>'
);
});

context('when the key is _block and is of type Handlebars.SafeString', function () {
it('extracts the string correctly', function () {
var html = '<div>something</div>',
result = subject.call({
_app: app()
}, 'test', {
hash: {
_block: new Handlebars.SafeString(html)
}
});
expect(result.string).to.eq(
'<div data-render="true" data-_block="&lt;div&gt;something&lt;/div&gt;" data-fetch_summary="{}" data-view="test"></div>'
);
});
});
});
});
});

0 comments on commit a3e81fd

Please sign in to comment.