From c5322b0e13584fd8d2110129d433748b4ba50250 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa?= Date: Fri, 25 Mar 2016 17:42:06 -0300 Subject: [PATCH 1/2] Add an option to prevent the templates to be added to the global namespace --- tasks/handlebars.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tasks/handlebars.js b/tasks/handlebars.js index aade262..1de4b2d 100644 --- a/tasks/handlebars.js +++ b/tasks/handlebars.js @@ -97,6 +97,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) { @@ -184,6 +189,11 @@ module.exports = function(grunt) { } } + + // 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) { // Wrap the file in an AMD define fn. From d49cc85a7cbd38cd7d60881111accaa6ddd5e0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa?= Date: Fri, 25 Mar 2016 17:49:51 -0300 Subject: [PATCH 2/2] Fix code style --- tasks/handlebars.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tasks/handlebars.js b/tasks/handlebars.js index 1de4b2d..89b7a0c 100644 --- a/tasks/handlebars.js +++ b/tasks/handlebars.js @@ -97,10 +97,10 @@ 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"; + nsDeclareOptions.root = 'templates'; } // Just get the namespace info for a given template @@ -187,13 +187,12 @@ 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 + ' = {};'); - } + output.unshift('var ' + nsDeclareOptions.root + ' = {};'); + } if (options.amd) { // Wrap the file in an AMD define fn.