diff --git a/tasks/handlebars.js b/tasks/handlebars.js index aade262..89b7a0c 100644 --- a/tasks/handlebars.js +++ b/tasks/handlebars.js @@ -98,6 +98,11 @@ module.exports = function(grunt) { // nsdeclare options when fetching namespace info var nsDeclareOptions = {response: 'details', declared: nsDeclarations}; + // if 'disableGlobal' option is true prevent the templates to be declared in the global namespace + if (options.disableGlobal) { + nsDeclareOptions.root = 'templates'; + } + // Just get the namespace info for a given template var getNamespaceInfo = _.memoize(function(filepath) { if (!useNamespace) { @@ -182,7 +187,11 @@ module.exports = function(grunt) { output.push(nodeExport); } + } + // if the 'disableGlobal' option is true create a local root variable to contain the templates + if (options.disableGlobal) { + output.unshift('var ' + nsDeclareOptions.root + ' = {};'); } if (options.amd) {