Created
November 14, 2012 15:30
-
-
Save cmsd2/4072773 to your computer and use it in GitHub Desktop.
Server-side handlebar template compilation in a requirejs plugin
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(["text","hbs"], function(text,hbs) { | |
"use strict"; | |
var buildMap = {}; | |
var module = { | |
load: function(name, parentRequire, load, config) { | |
parentRequire(["hbs!" + name], function(hbsTemplate) { | |
var rawText = hbsTemplate({}); | |
buildMap[name] = rawText; | |
load(rawText); | |
}); | |
}, | |
write: function(pluginName, moduleName, write) { | |
if(moduleName in buildMap && buildMap[moduleName]) { | |
var rawText = buildMap[moduleName]; | |
var escapedText = text.jsEscape(rawText); | |
write("define('" + pluginName + "!" + moduleName + | |
"', function() { return '" + escapedText + "';});\n"); | |
} | |
} | |
}; | |
return module; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment