Skip to content

Commit a3e81fd

Browse files
committed
Merge pull request #59 from brian-hall/fix_partial_view_nesting
fix nested partial view client render issue
2 parents 7b3b7a6 + 7e92d65 commit a3e81fd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

shared/helpers/view.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = function (Handlebars) {
3232
var parentView = getProperty('_view', this, options);
3333
html = getServerHtml(viewName, viewOptions, parentView);
3434
} else {
35-
html = getClientPlaceholder(viewName, viewOptions);
35+
html = getClientPlaceholder(viewName, viewOptions, Handlebars);
3636
}
3737

3838
return new Handlebars.SafeString(html);
@@ -55,7 +55,7 @@ function getServerHtml(viewName, viewOptions, parentView) {
5555
return view.getHtml();
5656
}
5757

58-
function getClientPlaceholder(viewName, viewOptions) {
58+
function getClientPlaceholder(viewName, viewOptions, Handlebars) {
5959
if (!BaseView) { BaseView = require('rendr/shared/base/view'); }
6060
var fetchSummary;
6161

@@ -67,7 +67,13 @@ function getClientPlaceholder(viewName, viewOptions) {
6767

6868
// create a list of data attributes
6969
var attrString = _.inject(viewOptions, function(memo, value, key) {
70-
if (_.isArray(value) || _.isObject(value)) { value = JSON.stringify(value); }
70+
if (_.isArray(value) || _.isObject(value)) {
71+
if (key === '_block' && value instanceof Handlebars.SafeString) {
72+
value = value.string;
73+
} else {
74+
value = JSON.stringify(value);
75+
}
76+
}
7177
return memo += " data-" + key + "=\"" + _.escape(value) + "\"";
7278
}, '');
7379

test/shared/helpers/view.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,22 @@ describe('view', function () {
175175
'<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>'
176176
);
177177
});
178+
179+
context('when the key is _block and is of type Handlebars.SafeString', function () {
180+
it('extracts the string correctly', function () {
181+
var html = '<div>something</div>',
182+
result = subject.call({
183+
_app: app()
184+
}, 'test', {
185+
hash: {
186+
_block: new Handlebars.SafeString(html)
187+
}
188+
});
189+
expect(result.string).to.eq(
190+
'<div data-render="true" data-_block="&lt;div&gt;something&lt;/div&gt;" data-fetch_summary="{}" data-view="test"></div>'
191+
);
192+
});
193+
});
178194
});
179195
});
180196
});

0 commit comments

Comments
 (0)