/app/examples/public/friendlycode/js/require-plugins/template.js
JavaScript | 31 lines | 27 code | 3 blank | 1 comment | 3 complexity | 4da2e9cb36d96541be23c0bc6ed17e5f MD5 | raw file
- // This is a simple RequireJS plugin that loads an underscore.js template.
- define(["module", "text", "underscore"], function (module, text, _) {
- var buildMap = {},
- masterConfig = module.config();
- return {
- load: function(name, req, onLoad, config) {
- var url = req.toUrl("templates/" + name).replace(".js", ".html");
- text.get(url, function (data) {
- var template;
- if (config.isBuild) {
- template = buildMap[name] = "_.template(" + JSON.stringify(data) +
- ")";
- } else {
- template = _.template(data);
- }
- onLoad(template);
- });
- },
- write: function (pluginName, moduleName, write) {
- if (buildMap[moduleName]) {
- var content = buildMap[moduleName];
- write.asModule(pluginName + "!" + moduleName,
- "define(['underscore'], function (_) { \n return " + content +
- ";});\n");
- }
- }
- };
- });