Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions server/viewEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,14 @@ ViewEngine.prototype.getViewHtml = function getViewHtml(viewPath, locals, app) {
};

ViewEngine.prototype.getBootstrappedData = function getBootstrappedData(locals, app) {
var bootstrappedData = {},
scope = this;
var bootstrappedData = {};

_.each(locals, function(modelOrCollection, name) {
if (app.modelUtils.isModel(modelOrCollection) || app.modelUtils.isCollection(modelOrCollection)) {
bootstrappedData[name] = {
summary: app.fetcher.summarize(modelOrCollection),
data: modelOrCollection.toJSON()
};

if (app.modelUtils.isModel(modelOrCollection)) {
_.each(modelOrCollection.attributes, function (value, key) {
if (app.modelUtils.isModel(value) || app.modelUtils.isCollection(value)) {
var tempObject = {};
tempObject[key] = value;

_.defaults(bootstrappedData, scope.getBootstrappedData(tempObject, app));
}
})
}
}
});
return bootstrappedData;
Expand Down
2 changes: 1 addition & 1 deletion shared/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function Fetcher(options) {
}

Fetcher.prototype.buildOptions = function(additionalOptions, params) {
var options = {app: this.app};
var options = {app: this.app, parse: true};
_.defaults(options, additionalOptions);
_.defaults(options, params);
return options;
Expand Down
50 changes: 0 additions & 50 deletions test/server/viewEngine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,55 +107,5 @@ describe('ViewEngine', function() {

data.should.deep.equal({});
});

it('should create a flat bootstrap object if a model has a nested model', function () {
var bar = new Model({ id: 123 }),
locals = {
foo: new Model({ id: 321, bar: bar }, { app: app })
},
expectedData = {
foo: {
data: { bar: bar, id: 321 },
summary: { model: 'model', id: 321 }
},
bar: {
data: { id: 123 },
summary: { model: 'model', id: 123 }
}
},
data;

data = viewEngine.getBootstrappedData(locals, app);
data.should.deep.equal(expectedData);
});

it('should create a flat bootstrap object if a model has a nested collection', function () {
var foo = new Model({ id: 321, foo: 'foo' }, { app: app }),
baz = new Collection([foo], { app: app }),
bar = new Model({ id: 123, foo: 'bar', items: baz }, { app: app }),
locals = {
foo: foo,
bar: bar
},
expectedData = {
foo: {
data: { foo: 'foo', id: 321 },
summary: { model: 'model', id: 321 }
},
bar: {
data: { foo: 'bar', id: 123, items: baz },
summary: { model: 'model', id: 123 }
},
items: {
data: [ { foo: 'foo', id: 321 } ],
summary: { collection: 'collection', ids: [ 321 ], meta: {}, params: {} }
}
},
data;

data = viewEngine.getBootstrappedData(locals, app);
data.should.deep.equal(expectedData);
});

});
});
9 changes: 5 additions & 4 deletions test/shared/fetcher.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,24 @@ describe('fetcher', function() {
});

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

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

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

it('should merge specified params with the specified options', function () {
var additionalOptions = {anyOption: 'withValue'},
params = {anyParam: 'paramValue'},
expected = {
app: this.app,
parse: true,
anyOption: 'withValue',
anyParam: 'paramValue'
};
Expand Down