gruntjs/grunt-contrib-handlebars — pull request #128 by ball-hayden (2014-12-10 17:13:34+00:00)
Title: AMD with a namespace function

I came across an issue when using `amd: true` and a function for namespaces.

As proved by the failing test, an incorrect namespace is being used in the return statement.
Currently, the namespace for the last file is used. This is fine if there is only a single file, but when trying to compile multiple files this is an issue.

I propose adding a `returnNamespace` option, which allows the user to specify the namespace that should be returned. I feel that trying to "work out" what this should be would add unnecessary complexity.

Old Behaviour:
```
// Gruntfile.js
options: {
processName: function(filename) {
return filename.replace(/.*\/(\w+)\.hbs/, '$1');
},
namespace: function(filename) {
var names = filename.replace(/.*modules\/(.*)(\/\w+\.hbs)/, '$1');
return 'JST.' + names.split('/').join('.');
}
},

// Output
define(['handlebars'], function(Handlebars) {
...
return this["JST"]["treeNav"]["leaves"];
})
```

New Behaviour:
```
// Gruntfile.js
options: {
processName: function(filename) {
return filename.replace(/.*\/(\w+)\.hbs/, '$1');
},
returnNamespace: 'JST',
namespace: function(filename) {
var names = filename.replace(/.*modules\/(.*)(\/\w+\.hbs)/, '$1');
return 'JST.' + names.split('/').join('.');
}
},

// Output
define(['handlebars'], function(Handlebars) {
...
return this["JST"];
})
```