Created
April 6, 2013 19:45
-
-
Save mleavitt/5327358 to your computer and use it in GitHub Desktop.
Revisions
-
mleavitt created this gist
Apr 6, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,40 @@ wrapAMD: function (output) { var dependencies = ['handlebars']; for ( var i = 0; i < output.length; i++ ) { // find partials defined as partials['partial-name'] var template = output[i] , partialStart = 'partials\\[\'' , partialEnd = '\\\']' , partialsRegex = new RegExp( partialStart + '[^\n]*' + partialEnd, 'g') , dependency = template.match(partialsRegex) , l = dependency ? dependency.length-1 : -1; // isolate the partial name and add it to the dependencies array while( l > -1 ) { dependencies.push(dependency[l].replace(new RegExp(partialStart), '').replace(new RegExp(partialEnd), '').replace(/\s/g, '')); l--; } // find partials defined as partials.partialName partialStart = 'partials\\.'; partialEnd = ','; partialsRegex = /partials\.[^\s]*/g; dependency = template.match(partialsRegex); l = dependency ? dependency.length-1 : -1; // isolate the partial name and add it to the dependencies array while( l > -1 ) { dependencies.push(dependency[l].replace(new RegExp(partialStart), '').replace(new RegExp(partialEnd), '').replace(/\s/g, '')); l--; } } // remove redundant dependencies dependencies = _.uniq(dependencies) output.unshift("define(['" + dependencies.join("','") + "'], function(Handlebars) {"); output.push("});"); return output; }