Skip to content

Instantly share code, notes, and snippets.

@adamwdraper
Created November 3, 2013 02:19
Show Gist options
  • Save adamwdraper/7285783 to your computer and use it in GitHub Desktop.
Save adamwdraper/7285783 to your computer and use it in GitHub Desktop.
Require.js Plugin to load uncompiled Handlebars templates
/**
* @appular hbs v0.0.1 - include file as text and convert it to a handlebars template
* @define hbs!
*/
// hbtemplate.js plugin for requirejs / text.js
// it loads and compiles Handlebars templates
define([
'handlebars'
], function (Handlebars) {
return {
load: function (name, req, onload, config) {
req([
'text!' + name
], function (template) {
if (config.isBuild) {
//Indicate that the optimizer should not wait
//for this resource any more and complete optimization.
//This resource will be resolved dynamically during
//run time in the web browser.
onload();
} else {
onload(Handlebars.compile(template));
}
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment