Skip to content

Commit

Permalink
correctly pass data to the template
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Mar 9, 2014
1 parent 6d3e63a commit 6bdcedf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions lib/View.js
Expand Up @@ -23,19 +23,19 @@ View.prototype.getCompiledTemplate = function (templateName) {
};

View.prototype.render = function () {
return this.module.data ? this.renderViewWithData() : this.renderViewWithoutData();
return !_.isEmpty(this.module.attributes) ? this.renderViewWithData() : this.renderViewWithoutData();
};

View.prototype.getViewData = function () {
return { json: JSON.stringify(this.module.data) };
return { json: JSON.stringify(this.module.attributes) };
};

View.prototype.renderViewWithData = function () {
return this.template(_.extend({
id: this.module.id,
title: this.module.title,
lastUpdated: new Date()
}, this.module.data, this.getViewData()));
}, this.module.attributes, this.getViewData()));
};

View.prototype.renderViewWithoutData = function () {
Expand Down
4 changes: 2 additions & 2 deletions test/specs/lib/View.js
Expand Up @@ -66,7 +66,7 @@ describe('View', function () {
id: 'foo',
template: 'json',
title: 'bar',
data: { some: 'json', data: 'of', the: 'module' }
attributes: { some: 'json', data: 'of', the: 'module' }
},
view = new View(module);

Expand All @@ -78,7 +78,7 @@ describe('View', function () {
expect(view.template).to.have.been.calledWithMatch({
id: module.id,
title: module.title,
json: JSON.stringify(module.data),
json: JSON.stringify(module.attributes),
some: 'json',
data: 'of',
the: 'module'
Expand Down

0 comments on commit 6bdcedf

Please sign in to comment.