Created
January 11, 2013 09:24
-
-
Save menacestudio/4509238 to your computer and use it in GitHub Desktop.
Handlebars: Load template with RequireJS
This file contains 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 characters
define(['handlebars','text'], function (Handlebars, text) { | |
var _buildMap = {}; | |
var _buildTemplate = Handlebars.compile( | |
'define("{{pluginName}}!{{moduleName}}", ["handlebars"], function(Handlebars){'+ | |
' return {{fn}}'+ | |
'});\n' | |
); | |
return { | |
load: function (name, req, onLoad, config) { | |
fileName = name+'.hbs'; | |
text.get(req.toUrl(fileName), function(data) { | |
if (config.isBuild) { | |
_buildMap[name] = Handlebars.precompile(data); | |
} | |
onLoad(Handlebars.compile(data)); | |
}); | |
}, | |
write: function (pluginName, moduleName, writeModule) { | |
if(moduleName in _buildMap) { | |
var fn = _buildMap[moduleName]; | |
writeModule(_buildTemplate({ | |
pluginName : pluginName, | |
moduleName : moduleName, | |
fn : fn | |
})); | |
} | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment