From 7c483e2db9f122265e8d9d777b9193b23bb8b295 Mon Sep 17 00:00:00 2001 From: Keivan Beigi Date: Fri, 14 Jun 2013 16:36:59 -0700 Subject: [PATCH] handlebars and templates are loaded with require.js --- Gruntfile.js | 5 +++-- UI/AddSeries/RootFolders/RootFolderTemplateHelper.js | 2 +- UI/Form/FormBuilder.js | 8 ++++---- UI/Index.html | 4 ---- UI/Mixins/backbone.marionette.templates.js | 4 ++-- UI/Quality/QualityProfileTemplateHelper.js | 2 +- UI/Shared/TemplateHelpers.js | 2 +- UI/app.js | 6 +----- 8 files changed, 13 insertions(+), 20 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index da73604c0..8fe0c7a3c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -76,9 +76,10 @@ module.exports = function (grunt) { handlebars: { options: { - namespace : "Templates", + namespace : "Templates", partialRegex: /Partial.html/, - wrapped : true, + wrapped : true, + amd : true, processName: function (fileName) { return fileName .replace('UI/', '') diff --git a/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js b/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js index fba47008f..85f6a7aeb 100644 --- a/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js +++ b/UI/AddSeries/RootFolders/RootFolderTemplateHelper.js @@ -1,6 +1,6 @@ 'use strict'; -define(['app', 'AddSeries/RootFolders/RootFolderCollection'], function (app, rootFolders) { +define(['app', 'AddSeries/RootFolders/RootFolderCollection','handlebars'], function (app, rootFolders, Handlebars) { Handlebars.registerHelper('rootFolderSelection', function () { //TODO: We should be able to pass in the context, either an object or a property diff --git a/UI/Form/FormBuilder.js b/UI/Form/FormBuilder.js index 266b66566..423d2b38e 100644 --- a/UI/Form/FormBuilder.js +++ b/UI/Form/FormBuilder.js @@ -1,15 +1,15 @@ 'use strict'; -define(['app'], function () { - Handlebars.registerHelper('formBuilder', function (){ +define(['app', 'handlebars'], function (App,Handlebars) { + Handlebars.registerHelper('formBuilder', function () { var ret = ""; - _.each(this.fields, function(field){ + _.each(this.fields, function (field) { ret += NzbDrone.Form.FieldBuilder(field); }); return new Handlebars.SafeString(ret); }); - NzbDrone.Form.FieldBuilder = function(field) { + NzbDrone.Form.FieldBuilder = function (field) { if (!field.type) { return Handlebars.helpers.partial.apply(field, ['Form/TextboxTemplate']); } diff --git a/UI/Index.html b/UI/Index.html index 548798ea5..7b9eddf43 100644 --- a/UI/Index.html +++ b/UI/Index.html @@ -78,12 +78,8 @@ - - - diff --git a/UI/Mixins/backbone.marionette.templates.js b/UI/Mixins/backbone.marionette.templates.js index d14fc8f47..d6207dbfb 100644 --- a/UI/Mixins/backbone.marionette.templates.js +++ b/UI/Mixins/backbone.marionette.templates.js @@ -1,11 +1,11 @@ "use strict"; -define(['app', 'marionette'], function (App, Marionette) { +define(['app', 'marionette', 'handlebars', 'templates'], function (App, Marionette, HandleBars, Templates) { Marionette.TemplateCache.get = function (templateId) { var templateKey = templateId.toLowerCase(); - var templateFunction = window.Templates[templateKey]; + var templateFunction = Templates[templateKey]; if (!templateFunction) { throw 'couldn\'t find pre-compiled template ' + templateKey; diff --git a/UI/Quality/QualityProfileTemplateHelper.js b/UI/Quality/QualityProfileTemplateHelper.js index 4f63a0574..98e800b60 100644 --- a/UI/Quality/QualityProfileTemplateHelper.js +++ b/UI/Quality/QualityProfileTemplateHelper.js @@ -1,6 +1,6 @@ 'use strict'; -define(['app', 'Quality/QualityProfileCollection'], function (app, qualityProfiles) { +define(['app', 'Quality/QualityProfileCollection','handlebars'], function (app, qualityProfiles,Handlebars) { Handlebars.registerHelper('qualityProfileSelection', function () { diff --git a/UI/Shared/TemplateHelpers.js b/UI/Shared/TemplateHelpers.js index e6d8daeb0..2865974d3 100644 --- a/UI/Shared/TemplateHelpers.js +++ b/UI/Shared/TemplateHelpers.js @@ -1,6 +1,6 @@ "use strict"; -define(['app'], function () { +define(['app','handlebars'], function (App,Handlebars) { Handlebars.registerHelper('partial', function (templateName) { //TODO: We should be able to pass in the context, either an object or a property diff --git a/UI/app.js b/UI/app.js index 780593f5a..73c4a6a8f 100644 --- a/UI/app.js +++ b/UI/app.js @@ -3,6 +3,7 @@ require.config({ paths: { 'backbone' : 'JsLibraries/backbone', + 'handlebars' : 'JsLibraries/handlebars.runtime', 'bootstrap' : 'JsLibraries/bootstrap', 'bootstrap.slider' : 'JsLibraries/bootstrap.slider', 'backbone.mutators' : 'JsLibraries/backbone.mutators', @@ -15,7 +16,6 @@ require.config({ '$' : 'JsLibraries/jquery', 'underscore' : 'JsLibraries/underscore', 'marionette' : 'JsLibraries/backbone.marionette', - 'handlebars' : 'JsLibraries/handlebars', 'signalR' : 'JsLibraries/jquery.signalR', 'libs' : 'JsLibraries/' }, @@ -62,10 +62,6 @@ require.config({ } }, - handlebars: { - exports: 'Handlebars' - }, - signalR: { dep: ['$'] },