From 4a4e1734bf2a5f925aa7fba6dbbf66724cc73460 Mon Sep 17 00:00:00 2001 From: Adrien Antoine Date: Wed, 6 Mar 2013 11:44:15 +0000 Subject: [PATCH] Improved AMD support when namespace = false --- tasks/jst.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/tasks/jst.js b/tasks/jst.js index 84b14f0..f2810fd 100644 --- a/tasks/jst.js +++ b/tasks/jst.js @@ -30,7 +30,10 @@ module.exports = function(grunt) { grunt.verbose.writeflags(options, 'Options'); - var nsInfo = helpers.getNamespaceDeclaration(options.namespace); + var nsInfo; + if (options.namespace !== false) { + nsInfo = helpers.getNamespaceDeclaration(options.namespace); + } this.files.forEach(function(f) { var output = f.src.filter(function(filepath) { @@ -58,13 +61,18 @@ module.exports = function(grunt) { } filename = processName(filepath); + if (options.amdWrapper && options.namespace === false) { + return 'return ' + compiled; + } return nsInfo.namespace+'['+JSON.stringify(filename)+'] = '+compiled+';'; }); if (output.length < 1) { grunt.log.warn('Destination not written because compiled files were empty.'); } else { - output.unshift(nsInfo.declaration); + if (options.namespace !== false) { + output.unshift(nsInfo.declaration); + } if (options.amdWrapper) { if (options.prettify) { output.forEach(function(line, index) { @@ -72,7 +80,12 @@ module.exports = function(grunt) { }); } output.unshift("define(function(){"); - output.push(" return " + nsInfo.namespace + ";" + lf + "});"); + if (options.namespace !== false) { + // Namespace has not been explicitly set to false; the AMD + // wrapper will return the object containing the template. + output.push(" return " + nsInfo.namespace + ";" + lf); + } + output.push("});"); } grunt.file.write(f.dest, output.join(grunt.util.normalizelf(options.separator))); grunt.log.writeln('File "' + f.dest + '" created.');