Rename Whisper.View#attributes

Avoid colliding with Backbone.View attributes, which is a list of attrs
to set on the html element for a view.
This commit is contained in:
lilia 2015-03-06 17:05:36 -08:00
parent dc1b09f59d
commit 1321a90667
6 changed files with 11 additions and 11 deletions

View file

@ -20,7 +20,7 @@
Whisper.AttachmentPreviewView = Whisper.View.extend({ Whisper.AttachmentPreviewView = Whisper.View.extend({
className: 'attachment-preview', className: 'attachment-preview',
template: $('#attachment-preview').html(), template: $('#attachment-preview').html(),
attributes: function() { render_attributes: function() {
return {source: this.src}; return {source: this.src};
} }
}); });

View file

@ -22,7 +22,7 @@
return [ 'conversation', this.model.get('type') ].join(' '); return [ 'conversation', this.model.get('type') ].join(' ');
}, },
template: $('#conversation').html(), template: $('#conversation').html(),
attributes: function() { render_attributes: function() {
return { group: this.model.get('type') === 'group' }; return { group: this.model.get('type') === 'group' };
}, },
initialize: function() { initialize: function() {

View file

@ -33,7 +33,7 @@
}); });
}, },
attributes: function() { render_attributes: function() {
return { return {
your_key: this.splitKey(this.model.your_key), your_key: this.splitKey(this.model.your_key),
their_key: this.splitKey(this.model.their_key) their_key: this.splitKey(this.model.their_key)

View file

@ -46,7 +46,7 @@
this.$el.trigger('remove', {modelId: this.model.id}); this.$el.trigger('remove', {modelId: this.model.id});
this.remove(); this.remove();
}, },
attributes: function() { render_attributes: function() {
return { name: this.model.getTitle() }; return { name: this.model.getTitle() };
} }
}); });

View file

@ -22,11 +22,11 @@
Backbone.View.apply(this, arguments); Backbone.View.apply(this, arguments);
Mustache.parse(_.result(this, 'template')); Mustache.parse(_.result(this, 'template'));
}, },
attributes: function() { render_attributes: function() {
return _.result(this.model, 'attributes', {}); return _.result(this.model, 'attributes', {});
}, },
render: function() { render: function() {
var attrs = _.result(this, 'attributes', {}); var attrs = _.result(this, 'render_attributes', {});
var template = _.result(this, 'template', ''); var template = _.result(this, 'template', '');
this.$el.html(Mustache.render(template, attrs)); this.$el.html(Mustache.render(template, attrs));
return this; return this;

View file

@ -1,8 +1,8 @@
describe('Whisper.View', function() { describe('Whisper.View', function() {
it('renders a template with attributes', function() { it('renders a template with render_attributes', function() {
var viewClass = Whisper.View.extend({ var viewClass = Whisper.View.extend({
template: '<div>{{ variable }}</div>', template: '<div>{{ variable }}</div>',
attributes: { render_attributes: {
variable: 'value' variable: 'value'
} }
}); });
@ -11,7 +11,7 @@ describe('Whisper.View', function() {
view.render(); view.render();
assert.strictEqual(view.$el.html(), '<div>value</div>'); assert.strictEqual(view.$el.html(), '<div>value</div>');
}); });
it('renders a template with no attributes', function() { it('renders a template with no render_attributes', function() {
var viewClass = Whisper.View.extend({ var viewClass = Whisper.View.extend({
template: '<div>static text</div>' template: '<div>static text</div>'
}); });
@ -20,10 +20,10 @@ describe('Whisper.View', function() {
view.render(); view.render();
assert.strictEqual(view.$el.html(), '<div>static text</div>'); assert.strictEqual(view.$el.html(), '<div>static text</div>');
}); });
it('renders a template function with attributes function', function() { it('renders a template function with render_attributes function', function() {
var viewClass = Whisper.View.extend({ var viewClass = Whisper.View.extend({
template: function() { return '<div>{{ variable }}</div>'; }, template: function() { return '<div>{{ variable }}</div>'; },
attributes: function() { render_attributes: function() {
return { variable: 'value' }; return { variable: 'value' };
} }
}); });