Skip to content

Instantly share code, notes, and snippets.

@tschieggm
Created September 5, 2012 04:58
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tschieggm/3630782 to your computer and use it in GitHub Desktop.
Trying to learn Marionette
(function (app, $, backbone, marionette, options, undefined) {
app = new marionette.Application();
app.addInitializer(function () {
app.Log("configuring marionette template compiler");
marionette.TemplateCache.prototype.compileTemplate = function (rawTemplate) {
return Hogan.compile(rawTemplate);
};
});
app.addInitializer(function () {
app.Log("configuring marionette template renderer");
marionette.Renderer = {
render: function (template, data) {
var templateFunc = typeof template === 'function' ? template : marionette.TemplateCache.get(template);
var html = templateFunc.render(data); //hogan rendering
return html;
}
};
});
app.addInitializer(function () {
app.Log("precompiling templates");
$("#templates script").each(function (index, value) {
var templateSelector = "#" + value.id;
marionette.TemplateCache.get(templateSelector);
});
});
app.Log = function (msg) {
if (options.IsDebug) {
if (typeof console !== 'undefined')
console.log(msg);
} else {
//eat the log msg
}
};
app.addRegions({
MainRegion: "#main-content",
TopNavigationRegion: "#top-nav"
});
app.Log("Starting App");
app.start(options);
app.vent.on("routing:started", function () {
if (!backbone.History.started)
backbone.history.start({ hashChange: options.SupportsHistoryApi, silent: true });
});
//var regView = new RegisterView();
//app.MainRegion.show(regView);
} (window.MyApp = window.MyApp || {}, jQuery, Backbone, Backbone.Marionette, window.ApplicationOptions));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment