Skip to content

Instantly share code, notes, and snippets.

View mleavitt's full-sized avatar

Micheal Leavitt mleavitt

View GitHub Profile
@mleavitt
mleavitt / wrapAMD
Created April 6, 2013 19:45
Sample "wrapAMD" function for finding the partials dependencies in a compiled Handlebars template function and wrapping it in an AMD definition function with the partials inserted into the dependencies array.
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)