Skip to content

Commit cd83109

Browse files
committed
Merge pull request #385 from change/md_client_side_parse
add parse option to fetcher
2 parents ad38fe2 + d6bd6d7 commit cd83109

File tree

4 files changed

+7
-68
lines changed

4 files changed

+7
-68
lines changed

server/viewEngine.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,14 @@ ViewEngine.prototype.getViewHtml = function getViewHtml(viewPath, locals, app) {
7070
};
7171

7272
ViewEngine.prototype.getBootstrappedData = function getBootstrappedData(locals, app) {
73-
var bootstrappedData = {},
74-
scope = this;
73+
var bootstrappedData = {};
7574

7675
_.each(locals, function(modelOrCollection, name) {
7776
if (app.modelUtils.isModel(modelOrCollection) || app.modelUtils.isCollection(modelOrCollection)) {
7877
bootstrappedData[name] = {
7978
summary: app.fetcher.summarize(modelOrCollection),
8079
data: modelOrCollection.toJSON()
8180
};
82-
83-
if (app.modelUtils.isModel(modelOrCollection)) {
84-
_.each(modelOrCollection.attributes, function (value, key) {
85-
if (app.modelUtils.isModel(value) || app.modelUtils.isCollection(value)) {
86-
var tempObject = {};
87-
tempObject[key] = value;
88-
89-
_.defaults(bootstrappedData, scope.getBootstrappedData(tempObject, app));
90-
}
91-
})
92-
}
9381
}
9482
});
9583
return bootstrappedData;

shared/fetcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function Fetcher(options) {
2626
}
2727

2828
Fetcher.prototype.buildOptions = function(additionalOptions, params) {
29-
var options = {app: this.app};
29+
var options = {app: this.app, parse: true};
3030
_.defaults(options, additionalOptions);
3131
_.defaults(options, params);
3232
return options;

test/server/viewEngine.test.js

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -107,55 +107,5 @@ describe('ViewEngine', function() {
107107

108108
data.should.deep.equal({});
109109
});
110-
111-
it('should create a flat bootstrap object if a model has a nested model', function () {
112-
var bar = new Model({ id: 123 }),
113-
locals = {
114-
foo: new Model({ id: 321, bar: bar }, { app: app })
115-
},
116-
expectedData = {
117-
foo: {
118-
data: { bar: bar, id: 321 },
119-
summary: { model: 'model', id: 321 }
120-
},
121-
bar: {
122-
data: { id: 123 },
123-
summary: { model: 'model', id: 123 }
124-
}
125-
},
126-
data;
127-
128-
data = viewEngine.getBootstrappedData(locals, app);
129-
data.should.deep.equal(expectedData);
130-
});
131-
132-
it('should create a flat bootstrap object if a model has a nested collection', function () {
133-
var foo = new Model({ id: 321, foo: 'foo' }, { app: app }),
134-
baz = new Collection([foo], { app: app }),
135-
bar = new Model({ id: 123, foo: 'bar', items: baz }, { app: app }),
136-
locals = {
137-
foo: foo,
138-
bar: bar
139-
},
140-
expectedData = {
141-
foo: {
142-
data: { foo: 'foo', id: 321 },
143-
summary: { model: 'model', id: 321 }
144-
},
145-
bar: {
146-
data: { foo: 'bar', id: 123, items: baz },
147-
summary: { model: 'model', id: 123 }
148-
},
149-
items: {
150-
data: [ { foo: 'foo', id: 321 } ],
151-
summary: { collection: 'collection', ids: [ 321 ], meta: {}, params: {} }
152-
}
153-
},
154-
data;
155-
156-
data = viewEngine.getBootstrappedData(locals, app);
157-
data.should.deep.equal(expectedData);
158-
});
159-
160110
});
161111
});

test/shared/fetcher.test.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,24 @@ describe('fetcher', function() {
112112
});
113113

114114
describe('buildOptions', function () {
115-
it('should merge the app with custom options', function () {
116-
fetcher.buildOptions().should.be.deep.equal({app: this.app});
115+
it('should merge the app and parse with custom options', function () {
116+
fetcher.buildOptions().should.be.deep.equal({app: this.app, parse: true});
117117
});
118118

119119
it('should append specified additional options', function () {
120-
fetcher.buildOptions({foo: 'bar'}).should.be.deep.equal({foo: 'bar', app: this.app});
120+
fetcher.buildOptions({foo: 'bar'}).should.be.deep.equal({foo: 'bar', app: this.app, parse: true});
121121
});
122122

123123
it('should merge specified params with specified options that are empty', function () {
124-
fetcher.buildOptions(null, {foo: 'bar'}).should.be.deep.equal({foo: 'bar', app: this.app});
124+
fetcher.buildOptions(null, {foo: 'bar'}).should.be.deep.equal({foo: 'bar', app: this.app, parse: true});
125125
});
126126

127127
it('should merge specified params with the specified options', function () {
128128
var additionalOptions = {anyOption: 'withValue'},
129129
params = {anyParam: 'paramValue'},
130130
expected = {
131131
app: this.app,
132+
parse: true,
132133
anyOption: 'withValue',
133134
anyParam: 'paramValue'
134135
};

0 commit comments

Comments
 (0)