Skip to content

Commit

Permalink
changed the getBootstrappedData function to add each model to the sto…
Browse files Browse the repository at this point in the history
…re as well.
  • Loading branch information
Josh Callender committed Jul 14, 2014
1 parent 38dc8be commit 1c332e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
21 changes: 11 additions & 10 deletions server/viewEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,17 @@ ViewEngine.prototype.getBootstrappedData = function getBootstrappedData(locals,
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));
}
})
}

var list = (app.modelUtils.isModel(modelOrCollection)) ? modelOrCollection.attributes: modelOrCollection.models;
_.each(list, function (value, key) {
if (app.modelUtils.isModel(value) || app.modelUtils.isCollection(value)) {
var tempObject = {},
key = (key !== value.cid && isNaN(parseInt(key))) ? key : value.cid;

tempObject[key] = value;
_.defaults(bootstrappedData, scope.getBootstrappedData(tempObject, app));
}
})
}
});
return bootstrappedData;
Expand Down
10 changes: 10 additions & 0 deletions test/server/viewEngine.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ describe('ViewEngine', function() {
},
data;

expectedData[locals.bar.models[0].cid] = {
data: { foo: 'bar', id: 123 },
summary: { model: 'model', id: 123 }
}

data = viewEngine.getBootstrappedData(locals, app);
data.should.deep.equal(expectedData);
});
Expand Down Expand Up @@ -153,6 +158,11 @@ describe('ViewEngine', function() {
},
data;

expectedData[baz.models[0].cid] = {
data: { foo: 'foo', id: 321 },
summary: { model: 'model', id: 321 }
};

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

0 comments on commit 1c332e1

Please sign in to comment.