Skip to content

Instantly share code, notes, and snippets.

@benhowdle89
Created July 15, 2014 13:49
Show Gist options
  • Save benhowdle89/929b567105e1c663793c to your computer and use it in GitHub Desktop.
Save benhowdle89/929b567105e1c663793c to your computer and use it in GitHub Desktop.
CommonJS Backbone inheritence
var Backbone = require('backbone');
var $ = require('jquery');
var Handlebars = require('handlebars');
var HandlebarsHelpers = require('base/utils/template-helpers');
var templateCache = require('base/utils/template-cache');
module.exports = Backbone.View.extend({
initialize: function(options) {
this.templates = templateCache.get();
},
render: function() {
var template = Handlebars.compile(this.templates[this.template]),
templateData = $.extend({}, this.templateData);
this.$el.html(template(templateData));
if (this.renderAfter) {
setTimeout(this.renderAfter.bind(this), 0);
}
return this;
}
});
var baseView = require('base/views/view');
module.exports = baseView.extend({
initialize: function(options) {
baseView.prototype.initialize.apply(this);
this.menu = options.menu;
this.templateData = {
menu: this.menu
};
},
template: 'base.universal.layout/_menu',
className: "menu"
});
module.exports = {
set: function(obj){
this.templates = obj;
},
get: function(){
return this.templates;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment