/*
 * Copyright (c) 2013, Yahoo! Inc.  All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE.txt file for terms.
 */

/*jslint nomen:true, node:true */

"use strict";

module.exports = function (bundleName, templateName, moduleName, precompiled, partials, prefix) {

    // base dependency
    var dependencies = ["template-base", "handlebars-base"];

    // each partial should be provisioned thru another yui module
    // and the name of the partial should translate into a yui module
    // to become a dependency
    partials = partials || [];
    // transform paths to custom naming convention
    partials = partials.map(function (name) {
        return name.replace(/\//g, '-');
    });
    partials.forEach(function (name) {
        // adding prefix to each partial
        dependencies.push((prefix || bundleName + '-tmpl-') + name);
    });

    return [
        'YUI.add("' + moduleName + '",function(Y, NAME) {',
        '   var fn = Y.Template.Handlebars.revive(' + precompiled + '),',
        '       partials = {};',
        '',
        '   Y.Array.each(' + JSON.stringify(partials) + ', function (name) {',
        '       var fn = Y.Template.get("' + bundleName + '/" + name);',
        '       if (fn) {',
        '           partials[name] = fn;',
        '       }',
        '   });',
        '',
        '   Y.Template.register("' + bundleName + '/' + templateName + '", function (data, options) {',
        '       options = options || {};',
        '       options.partials = options.partials ? Y.merge(partials, options.partials) : partials;',
        '       return fn(data, options);',
        '   });',
        '}, "", {requires: ' + JSON.stringify(dependencies) + '});'
    ].join('\n');

};

@@ -1,171 +1,4 @@
-/*%0A * Copyright (c) 2013, Yahoo! Inc.  All rights reserved.%0A * Copyrights licensed under the New BSD License.%0A * See the accompanying LICENSE.txt file for terms.%0A */%0A%0A
 /*js
@@ -224,16 +224,126 @@
 s-base%22%5D
+,%0A        // Used to store both the original file path and the dashed name%0A        partialModuleToPathMap = %7B%7D
 ;%0A%0A    /
@@ -534,16 +534,59 @@
  %7C%7C %5B%5D;%0A
+    partials.map(function (filePath) %7B%0A    
     // t
@@ -636,137 +636,118 @@
     
-partials = partials.map(function (name) %7B%0A        return name.replace(/%5C//g, '-');%0A    %7D);%0A    partials.forEach(function (
+    var moduleSuffix = filePath.replace(/%5C//g, '-');%0A        // map dashed module suffix to original file 
 name
-) %7B
 %0A   
@@ -758,37 +758,148 @@
  // 
-adding prefix to each partial
+Ex: %7B %22path-to-mustache-file%22 : %22path/to/mustache/file%22 %7D%0A        partialModuleToPathMap%5BmoduleSuffix%5D = filePath;%0A        // add dependency
 %0A   
@@ -957,20 +957,28 @@
 pl-') + 
-name
+moduleSuffix
 );%0A    %7D
@@ -1191,13 +1191,14 @@
   Y.
-Array
+Object
 .eac
@@ -1225,17 +1225,31 @@
 (partial
-s
+ModuleToPathMap
 ) + ', f
@@ -1257,20 +1257,38 @@
 nction (
-name
+filePath, moduleSuffix
 ) %7B',%0A  
@@ -1349,20 +1349,28 @@
 + '/%22 + 
-name
+moduleSuffix
 );',%0A   
@@ -1423,20 +1423,75 @@
 artials%5B
-name
+filePath%5D = fn;',%0A        '           partials%5BmoduleSuffix
 %5D = fn;'

Add both the mustache path and mustache module suffix to the list of partials