Make all mustache templates available as partials

// FREEBIE
This commit is contained in:
lilia 2015-09-03 13:22:52 -07:00
parent 9566f10ca4
commit 5d9965a60e

View file

@ -26,9 +26,7 @@
return _.result(this.model, 'attributes', {}); return _.result(this.model, 'attributes', {});
}, },
render_partials: function() { render_partials: function() {
return { return Whisper.View.Templates;
avatar: this.avatar_template
};
}, },
render: function() { render: function() {
var attrs = _.result(this, 'render_attributes', {}); var attrs = _.result(this, 'render_attributes', {});
@ -37,7 +35,6 @@
this.$el.html(Mustache.render(template, attrs, partials)); this.$el.html(Mustache.render(template, attrs, partials));
return this; return this;
}, },
avatar_template: $('#avatar').html(),
confirm: function(message) { confirm: function(message) {
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
var dialog = new Whisper.ConfirmationDialogView({ var dialog = new Whisper.ConfirmationDialogView({
@ -48,5 +45,16 @@
this.$el.append(dialog.el); this.$el.append(dialog.el);
}.bind(this)); }.bind(this));
} }
},{
// Class attributes
Templates: (function() {
var templates = {};
$('script[type="text/x-tmpl-mustache"]').each(function(i, el) {
var $el = $(el);
var id = $el.attr('id').replace('-','_');
templates[id] = $el.html();
});
return templates;
}())
}); });
})(); })();