mirror of
https://github.com/wahyd4/cdnjs.git
synced 2026-08-15 15:56:28 +10:00
Merge pull request #2103 from jfparadis/requirejs-tpl
[AUTHOR] Add requirejs-tpl 0.0.2
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
// RequireJS UnderscoreJS template plugin
|
||||
// http://github.com/jfparadis/requirejs-tpl
|
||||
//
|
||||
// An alternative to http://github.com/ZeeAgency/requirejs-tpl
|
||||
//
|
||||
// Using UnderscoreJS micro-templates at http://underscorejs.org/#template
|
||||
// Using and RequireJS text.js at http://requirejs.org/docs/api.html#text
|
||||
// @author JF Paradis
|
||||
// @version 0.0.2
|
||||
//
|
||||
// Released under the MIT license
|
||||
//
|
||||
// Usage:
|
||||
// require(['backbone', 'tpl!mytemplate'], function (Backbone, mytemplate) {
|
||||
// return Backbone.View.extend({
|
||||
// initialize: function(){
|
||||
// this.render();
|
||||
// },
|
||||
// render: function(){
|
||||
// this.$el.html(mytemplate({message: 'hello'}));
|
||||
// });
|
||||
// });
|
||||
//
|
||||
// Configuration: (optional)
|
||||
// require.config({
|
||||
// tpl: {
|
||||
// extension: '.tpl' // default = '.html'
|
||||
// }
|
||||
// });
|
||||
|
||||
/*jslint nomen: true */
|
||||
/*global define: false */
|
||||
|
||||
define(['text', 'underscore'], function (text, _) {
|
||||
'use strict';
|
||||
|
||||
var buildMap = {},
|
||||
buildTemplateSource = "define('{pluginName}!{moduleName}', function () { return {source}; });\n";
|
||||
|
||||
return {
|
||||
version: '0.0.2',
|
||||
|
||||
load: function (moduleName, parentRequire, onload, config) {
|
||||
if (buildMap[moduleName]) {
|
||||
onload(buildMap[moduleName]);
|
||||
|
||||
} else {
|
||||
var ext = (config.tpl && config.tpl.extension) || '.html';
|
||||
var path = (config.tpl && config.tpl.path) || '';
|
||||
text.load(path + moduleName + ext, parentRequire, function (source) {
|
||||
buildMap[moduleName] = _.template(source);
|
||||
onload(buildMap[moduleName]);
|
||||
}, config);
|
||||
}
|
||||
},
|
||||
|
||||
write: function (pluginName, moduleName, write) {
|
||||
var build = buildMap[moduleName],
|
||||
source = build && build.source;
|
||||
if (source) {
|
||||
write.asModule(pluginName + '!' + moduleName,
|
||||
buildTemplateSource
|
||||
.replace('{pluginName}', pluginName)
|
||||
.replace('{moduleName}', moduleName)
|
||||
.replace('{source}', source));
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// RequireJS UnderscoreJS template plugin
|
||||
// http://github.com/jfparadis/requirejs-tpl
|
||||
//
|
||||
// An alternative to http://github.com/ZeeAgency/requirejs-tpl
|
||||
//
|
||||
// Using UnderscoreJS micro-templates at http://underscorejs.org/#template
|
||||
// Using and RequireJS text.js at http://requirejs.org/docs/api.html#text
|
||||
// @author JF Paradis
|
||||
// @version 0.0.2
|
||||
//
|
||||
// Released under the MIT license
|
||||
define(["text","underscore"],function(text,_){var buildMap={},buildTemplateSource="define('{pluginName}!{moduleName}', function () { return {source}; });\n";return{version:"0.0.2",load:function(moduleName,parentRequire,onload,config){if(buildMap[moduleName])onload(buildMap[moduleName]);else{var ext=config.tpl&&config.tpl.extension||".html";var path=config.tpl&&config.tpl.path||"";text.load(path+moduleName+ext,parentRequire,function(source){buildMap[moduleName]=_.template(source);onload(buildMap[moduleName])},
|
||||
config)}},write:function(pluginName,moduleName,write){var build=buildMap[moduleName],source=build&&build.source;if(source)write.asModule(pluginName+"!"+moduleName,buildTemplateSource.replace("{pluginName}",pluginName).replace("{moduleName}",moduleName).replace("{source}",source))}}});
|
||||
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"name": "requirejs-tpl",
|
||||
"filename": "tpl.js",
|
||||
"version": "0.0.2",
|
||||
"description": "A RequireJS/AMD loader plugin for Underscore.js micro-templates",
|
||||
"homepage": "http://github.com/jfparadis/requirejs-tpl",
|
||||
"keywords": [
|
||||
"require",
|
||||
"requirejs",
|
||||
"underscore",
|
||||
"template"
|
||||
],
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "jfparadis",
|
||||
"email": "jf@jeanfrancoisparadis.com",
|
||||
"web": "http://jeanfrancoisparadis.com/"
|
||||
}
|
||||
],
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/jfparadis/requirejs-tpl"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user