Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Demo, build exclusion, README, yay!

  • Loading branch information...
commit aa58cf633ec80391d9d4fa28ba95ca956185baf5 1 parent 1c52e03
@ZeeDev ZeeDev authored
View
39 README.md
@@ -1,15 +1,42 @@
-# RequireJS Template Plugin
-Returns a compiled template.
+# AMD Template Plugin
-Uses Underscore.js micro-templates
+Uses Underscore.js micro-templates implementation.
+
+As modules, templates are stand-alone files (not in the DOM…) and they are served already compiled.
+
+Underscore.js *IS NOT* required, this plugin already contains the template method plus some AMD stuffs.
+
+For more information on micro-templates :
http://documentcloud.github.com/underscore/#template
+http://ejohn.org/blog/javascript-micro-templating/
-I use to use the .tpl file extension but you can use what you want
+I use to use the .tpl file extension but you can use whatever you want, but you have to use the "tpl!" plugin prefix.
## Usage
```
define(['tpl!your-template-path.tpl'], function(tpl) {
- return tpl(yourData);
+ return tpl({your: 'data'});
});
```
-## More later...
+
+## Optimization
+
+There are some really good wins with templates optimization you should care about.
+
+With optimization ([r.js](http://requirejs.org/docs/optimization.html)), no more dynamic loading ! So templates are bundled within your code, saving some HTTP requests.
+
+Optimized, templates are still served compiled but most of all they're *written compiled*. This means they're real line of codes and not eval or new Function anymore, so this is less evil *and* clients won't have to compile them ! Double win.
+
+Ever have a hard time to debug a template with a console giving no error line ? With optimization (without minification) error lines are back !
+
+If you can/want avoid dynamic loading, the plugin can be excluded from the build, at least reduced to 64 bytes (empty plugin) instead of 2Ko. Can't be bad.
+
+Oh and of course, templates can be minified…
+
+## Support
+
+I did this plugin for my own needs and as far as I'm using it (almost everyday on many projects) it works well, on every browsers I know… Concerning Node.js, I only made one test which you can check inside the demo folder.
+
+The only AMD loader I tested with is RequireJS but it should work with others like curl.js theorically…
+
+Feel free to tell if it helped you in any way and of course if you have some time, contribution is open ! I didn't have much time for unit tests so…
View
1  demo-build/build.js
@@ -0,0 +1 @@
+({appDir:".",baseUrl:"lib",dir:"../demo-build",paths:{tpl:"../../tpl"},pragmasOnSave:{excludeTpl:!0},modules:[{name:"main"}]})
View
4 demo-build/build.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -rf ../demo-build
+node ../tools/r.js -o build.js
View
6 demo-build/build.txt
@@ -0,0 +1,6 @@
+
+lib/main.js
+----------------
+lib/../../tpl.js
+tpl!hello.tpl
+lib/main.js
View
4 demo-build/index.html
@@ -0,0 +1,4 @@
+<!doctype html>
+<title>RequireJS Micro-Template Plugin Demo</title>
+<body></body>
+<script src="lib/require.js" data-main="lib/main.js"></script>
View
3  demo-build/lib/hello.tpl
@@ -0,0 +1,3 @@
+<h1>
+ Hello <%= world %>
+</h1>
View
1  demo-build/lib/main.js
@@ -0,0 +1 @@
+(function(){define("tpl",[],function(){return function(){}})})(),define("tpl!hello.tpl",function(){return function(obj){var __p=[],print=function(){__p.push.apply(__p,arguments)};with(obj||{})__p.push("<h1>Hello ",world,"</h1>");return __p.join("")}}),require({paths:{tpl:"../../tpl"}},["tpl!hello.tpl"],function(a){document.body.innerHTML+=a({world:"Worrrrrld"})}),define("main",function(){})
View
1  demo-build/lib/node-test.js
@@ -0,0 +1 @@
+var requirejs=require("requirejs");requirejs.config({nodeRequire:require}),requirejs({paths:{tpl:"../../tpl"}},["tpl!hello.tpl"],function(a){console.log(a({world:"Worrrrrld"}))})
View
1  demo-build/lib/require.js
@@ -0,0 +1 @@
+var requirejs,require,define;(function(){function J(a){return M.call(a)==="[object Function]"}function E(a){return M.call(a)==="[object Array]"}function Z(a,b,c){for(var e in b)!(e in K)&&(!(e in a)||c)&&(a[e]=b[e]);return d}function N(a,b,c){return a=Error(b+"\nhttp://requirejs.org/docs/errors.html#"+a),c&&(a.originalError=c),a}function $(a,b,c){var d,e,f;for(d=0;f=b[d];d++)f=typeof f=="string"?{name:f}:f,e=f.location,c&&(!e||e.indexOf("/")!==0&&e.indexOf(":")===-1)&&(e=c+"/"+(e||f.name)),a[f.name]={name:f.name,location:e||f.name,main:(f.main||"main").replace(da,"").replace(aa,"")}}function V(a,b){a.holdReady?a.holdReady(b):b?a.readyWait+=1:a.ready(!0)}function ea(a){function b(a,b){var c,d;if(a&&a.charAt(0)==="."&&b){t.pkgs[b]?b=[b]:(b=b.split("/"),b=b.slice(0,b.length-1)),c=a=b.concat(a.split("/"));var e;for(d=0;e=c[d];d++)if(e===".")c.splice(d,1),d-=1;else if(e==="..")if(d!==1||c[2]!==".."&&c[0]!=="..")d>0&&(c.splice(d-1,2),d-=2);else break;d=t.pkgs[c=a[0]],a=a.join("/"),d&&a===c+"/"+d.main&&(a=c)}return a}function c(a,c){var d=a?a.indexOf("!"):-1,e=null,f=c?c.name:null,g=a,h,i;return d!==-1&&(e=a.substring(0,d),a=a.substring(d+1,a.length)),e&&(e=b(e,f)),a&&(e?h=(d=x[e])&&d.normalize?d.normalize(a,function(a){return b(a,f)}):b(a,f):(h=b(a,f),i=w[h],i||(i=r.nameToUrl(h,null,c),w[h]=i))),{prefix:e,name:h,parentMap:c,url:i,originalName:g,fullName:e?e+"!"+(h||""):h}}function e(){var a=!0,b=t.priorityWait,c,d;if(b){for(d=0;c=b[d];d++)if(!y[c]){a=!1;break}a&&delete t.priorityWait}return a}function f(a,b,c){return function(){var d=ga.call(arguments,0),e;return c&&J(e=d[d.length-1])&&(e.__requireJsBuild=!0),d.push(b),a.apply(null,d)}}function g(a,b){var c=f(r.require,a,b);return Z(c,{nameToUrl:f(r.nameToUrl,a),toUrl:f(r.toUrl,a),defined:f(r.requireDefined,a),specified:f(r.requireSpecified,a),isBrowser:d.isBrowser}),c}function h(a){var b,e,f;f=a.callback;var g=a.map,h=g.fullName,i=a.deps,j=a.listeners;if(f&&J(f)){if(t.catchError.define)try{e=d.execCb(h,a.callback,i,x[h])}catch(k){b=k}else e=d.execCb(h,a.callback,i,x[h]);h&&(a.cjsModule&&a.cjsModule.exports!==void 0?e=x[h]=a.cjsModule.exports:e===void 0&&a.usingExports?e=x[h]:(x[h]=e,F[h]&&(I[h]=!0)))}else h&&(e=x[h]=f,F[h]&&(I[h]=!0));z[a.id]&&(delete z[a.id],a.isDone=!0,r.waitCount-=1,r.waitCount===0&&(A=[])),delete D[h],d.onResourceLoad&&!a.placeholder&&d.onResourceLoad(r,g,a.depArray);if(b)return e=(h?c(h).url:"")||b.fileName||b.sourceURL,f=b.moduleTree,b=N("defineerror",'Error evaluating module "'+h+'" at location "'+e+'":\n'+b+"\nfileName:"+e+"\nlineNumber: "+(b.lineNumber||b.line),b),b.moduleName=h,b.moduleTree=f,d.onError(b);for(b=0;f=j[b];b++)f(e)}function i(a,b){return function(c){a.depDone[b]||(a.depDone[b]=!0,a.deps[b]=c,a.depCount-=1,a.depCount||h(a))}}function j(a,b){var c=b.map,e=c.fullName,f=c.name,i=E[a]||(E[a]=x[a]),j;b.loading||(b.loading=!0,j=function(a){b.callback=function(){return a},h(b),y[b.id]=!0,s()},j.fromText=function(a,b){var c=O;y[a]=!1,r.scriptCount+=1,r.fake[a]=!0,c&&(O=!1),d.exec(b),c&&(O=!0),r.completeLoad(a)},e in x?j(x[e]):i.load(f,g(c.parentMap,!0),j,t))}function k(a){z[a.id]||(z[a.id]=a,A.push(a),r.waitCount+=1)}function l(a){this.listeners.push(a)}function m(a,b){var d=a.fullName,e=a.prefix,f=e?E[e]||(E[e]=x[e]):null,g,i;return d&&(g=D[d]),!g&&(i=!0,g={id:(e&&!f?C++ +"__p@:":"")+(d||"__r@"+C++),map:a,depCount:0,depDone:[],depCallbacks:[],deps:[],listeners:[],add:l},v[g.id]=!0,d&&(!e||E[e]))&&(D[d]=g),e&&!f?(d=m(c(e),!0),d.add(function(){var b=c(a.originalName,a.parentMap),b=m(b,!0);g.placeholder=!0,b.add(function(a){g.callback=function(){return a},h(g)})})):i&&b&&(y[g.id]=!1,r.paused.push(g),k(g)),g}function n(a,b,d,e){var a=c(a,e),f=a.name,j=a.fullName,l=m(a),n=l.id,o=l.deps,p;if(j){if(j in x||y[n]===!0||j==="jquery"&&t.jQuery&&t.jQuery!==d().fn.jquery)return;v[n]=!0,y[n]=!0,j==="jquery"&&d&&S(d())}l.depArray=b,l.callback=d;for(d=0;d<b.length;d++)if(n=b[d])n=c(n,f?a:e),p=n.fullName,b[d]=p,p==="require"?o[d]=g(a):p==="exports"?(o[d]=x[j]={},l.usingExports=!0):p==="module"?l.cjsModule=o[d]={id:f,uri:f?r.nameToUrl(f,null,e):void 0,exports:x[j]}:!(p in x)||p in z||j in F&&!(j in F&&I[p])?(j in F&&(F[p]=!0,delete x[p],B[n.url]=!1),l.depCount+=1,l.depCallbacks[d]=i(l,d),m(n,!0).add(l.depCallbacks[d])):o[d]=x[p];l.depCount?k(l):h(l)}function o(a){n.apply(null,a)}function p(a,b){if(!a.isDone){var d=a.map.fullName,e=a.depArray,f,g,h,i;if(d){if(b[d])return x[d];b[d]=!0}if(e)for(f=0;f<e.length;f++)if(g=e[f])if((h=c(g).prefix)&&(i=z[h])&&p(i,b),(h=z[g])&&!h.isDone&&y[g])g=p(h,b),a.depCallbacks[f](g);return d?x[d]:void 0}}function q(){var a=t.waitSeconds*1e3,b=a&&r.startTime+a<(new Date).getTime(),a="",c=!1,f=!1,g;if(r.pausedCount<=0){if(t.priorityWait)if(e())s();else return;for(g in y)if(!(g in K)&&(c=!0,!y[g]))if(b)a+=g+" ";else{f=!0;break}if(c||r.waitCount){if(b&&a)return g=N("timeout","Load timeout for modules: "+a),g.requireType="timeout",g.requireModules=a,d.onError(g);if(f||r.scriptCount)(G||ba)&&!W&&(W=setTimeout(function(){W=0,q()},50));else{if(r.waitCount){for(H=0;a=A[H];H++)p(a,{});r.paused.length&&s(),X<5&&(X+=1,q())}X=0,d.checkReadyState()}}}}var r,s,t={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},catchError:{}},u=[],v={require:!0,exports:!0,module:!0},w={},x={},y={},z={},A=[],B={},C=0,D={},E={},F={},I={},L=0;return S=function(a){!r.jQuery&&(a=a||(typeof jQuery!="undefined"?jQuery:null))&&(!t.jQuery||a.fn.jquery===t.jQuery)&&("holdReady"in a||"readyWait"in a)&&(r.jQuery=a,o(["jquery",[],function(){return jQuery}]),r.scriptCount)&&(V(a,!0),r.jQueryIncremented=!0)},s=function(){var a,b,c,f,g,h;L+=1,r.scriptCount<=0&&(r.scriptCount=0);for(;u.length;){if(a=u.shift(),a[0]===null)return d.onError(N("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));o(a)}if(!t.priorityWait||e())for(;r.paused.length;){g=r.paused,r.pausedCount+=g.length,r.paused=[];for(f=0;a=g[f];f++)b=a.map,c=b.url,h=b.fullName,b.prefix?j(b.prefix,a):!B[c]&&!y[h]&&(d.load(r,h,c),B[c]=!0);r.startTime=(new Date).getTime(),r.pausedCount-=g.length}L===1&&q(),L-=1},r={contextName:a,config:t,defQueue:u,waiting:z,waitCount:0,specified:v,loaded:y,urlMap:w,urlFetched:B,scriptCount:0,defined:x,paused:[],pausedCount:0,plugins:E,needFullExec:F,fake:{},fullExec:I,managerCallbacks:D,makeModuleMap:c,normalize:b,configure:function(a){var b,c,d;a.baseUrl&&a.baseUrl.charAt(a.baseUrl.length-1)!=="/"&&(a.baseUrl+="/"),b=t.paths,d=t.pkgs,Z(t,a,!0);if(a.paths){for(c in a.paths)c in K||(b[c]=a.paths[c]);t.paths=b}if((b=a.packagePaths)||a.packages){if(b)for(c in b)c in K||$(d,b[c],c);a.packages&&$(d,a.packages),t.pkgs=d}a.priority&&(c=r.requireWait,r.requireWait=!1,r.takeGlobalQueue(),s(),r.require(a.priority),s(),r.requireWait=c,t.priorityWait=a.priority),(a.deps||a.callback)&&r.require(a.deps||[],a.callback)},requireDefined:function(a,b){return c(a,b).fullName in x},requireSpecified:function(a,b){return c(a,b).fullName in v},require:function(b,e,f){if(typeof b=="string")return J(e)?d.onError(N("requireargs","Invalid require call")):d.get?d.get(r,b,e):(e=c(b,e),b=e.fullName,b in x?x[b]:d.onError(N("notloaded","Module name '"+e.fullName+"' has not been loaded yet for context: "+a)));(b&&b.length||e)&&n(null,b,e,f);if(!r.requireWait)for(;!r.scriptCount&&r.paused.length;)r.takeGlobalQueue(),s();return r.require},takeGlobalQueue:function(){U.length&&(ha.apply(r.defQueue,[r.defQueue.length-1,0].concat(U)),U=[])},completeLoad:function(a){var b;for(r.takeGlobalQueue();u.length;){if(b=u.shift(),b[0]===null){b[0]=a;break}if(b[0]===a)break;o(b),b=null}b?o(b):o([a,[],a==="jquery"&&typeof jQuery!="undefined"?function(){return jQuery}:null]),S(),d.isAsync&&(r.scriptCount-=1),s(),d.isAsync||(r.scriptCount-=1)},toUrl:function(a,b){var c=a.lastIndexOf("."),d=null;return c!==-1&&(d=a.substring(c,a.length),a=a.substring(0,c)),r.nameToUrl(a,d,b)},nameToUrl:function(a,c,e){var f,g,h,i,j=r.config,a=b(a,e&&e.fullName);if(d.jsExtRegExp.test(a))c=a+(c?c:"");else{f=j.paths,g=j.pkgs,e=a.split("/");for(i=e.length;i>0;i--){if(h=e.slice(0,i).join("/"),f[h]){e.splice(0,i,f[h]);break}if(h=g[h]){a=a===h.name?h.location+"/"+h.main:h.location,e.splice(0,i,a);break}}c=e.join("/")+(c||".js"),c=(c.charAt(0)==="/"||c.match(/^\w+:/)?"":j.baseUrl)+c}return j.urlArgs?c+((c.indexOf("?")===-1?"?":"&")+j.urlArgs):c}},r.jQueryCheck=S,r.resume=s,r}function ia(){var a,b,c;if(m&&m.readyState==="interactive")return m;a=document.getElementsByTagName("script");for(b=a.length-1;b>-1&&(c=a[b]);b--)if(c.readyState==="interactive")return m=c;return null}var ja=/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,ka=/require\(\s*["']([^'"\s]+)["']\s*\)/g,da=/^\.\//,aa=/\.js$/,M=Object.prototype.toString,r=Array.prototype,ga=r.slice,ha=r.splice,G=typeof window!="undefined"&&!!navigator&&!!document,ba=!G&&typeof importScripts!="undefined",la=G&&navigator.platform==="PLAYSTATION 3"?/^complete$/:/^(complete|loaded)$/,ca=typeof opera!="undefined"&&opera.toString()==="[object Opera]",K={},u={},U=[],m=null,X=0,O=!1,d,r={},I,w,y,z,v,A,B,H,C,S,W;if(typeof define=="undefined"){if(typeof requirejs!="undefined"){if(J(requirejs))return;r=requirejs,requirejs=void 0}typeof require!="undefined"&&!J(require)&&(r=require,require=void 0),d=requirejs=function(a,b,c){var d="_",e;return!E(a)&&typeof a!="string"&&(e=a,E(b)?(a=b,b=c):a=[]),e&&e.context&&(d=e.context),c=u[d]||(u[d]=ea(d)),e&&c.configure(e),c.require(a,b)},d.config=function(a){return d(a)},require||(require=d),d.toUrl=function(a){return u._.toUrl(a)},d.version="1.0.0",d.jsExtRegExp=/^\/|:|\?|\.js$/,w=d.s={contexts:u,skipAsync:{}};if(d.isAsync=d.isBrowser=G)if(y=w.head=document.getElementsByTagName("head")[0],z=document.getElementsByTagName("base")[0])y=w.head=z.parentNode;d.onError=function(a){throw a},d.load=function(a,b,c){d.resourcesReady(!1),a.scriptCount+=1,d.attach(c,a,b),a.jQuery&&!a.jQueryIncremented&&(V(a.jQuery,!0),a.jQueryIncremented=!0)},define=function(a,b,c){var d,e;typeof a!="string"&&(c=b,b=a,a=null),E(b)||(c=b,b=[]),!b.length&&J(c)&&c.length&&(c.toString().replace(ja,"").replace(ka,function(a,c){b.push(c)}),b=(c.length===1?["require"]:["require","exports","module"]).concat(b)),O&&(d=I||ia())&&(a||(a=d.getAttribute("data-requiremodule")),e=u[d.getAttribute("data-requirecontext")]),(e?e.defQueue:U).push([a,b,c])},define.amd={multiversion:!0,plugins:!0,jQuery:!0},d.exec=function(b){return eval(b)},d.execCb=function(a,b,c,d){return b.apply(d,c)},d.addScriptToDom=function(a){I=a,z?y.insertBefore(a,z):y.appendChild(a),I=null},d.onScriptLoad=function(a){var b=a.currentTarget||a.srcElement,c;if(a.type==="load"||b&&la.test(b.readyState))m=null,a=b.getAttribute("data-requirecontext"),c=b.getAttribute("data-requiremodule"),u[a].completeLoad(c),b.detachEvent&&!ca?b.detachEvent("onreadystatechange",d.onScriptLoad):b.removeEventListener("load",d.onScriptLoad,!1)},d.attach=function(a,b,c,e,f,g){var h;return G?(e=e||d.onScriptLoad,h=b&&b.config&&b.config.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),h.type=f||"text/javascript",h.charset="utf-8",h.async=!w.skipAsync[a],b&&h.setAttribute("data-requirecontext",b.contextName),h.setAttribute("data-requiremodule",c),h.attachEvent&&!ca?(O=!0,g?h.onreadystatechange=function(){h.readyState==="loaded"&&(h.onreadystatechange=null,h.attachEvent("onreadystatechange",e),g(h))}:h.attachEvent("onreadystatechange",e)):h.addEventListener("load",e,!1),h.src=a,g||d.addScriptToDom(h),h):(ba&&(importScripts(a),b.completeLoad(c)),null)};if(G){v=document.getElementsByTagName("script");for(H=v.length-1;H>-1&&(A=v[H]);H--){y||(y=A.parentNode);if(B=A.getAttribute("data-main")){r.baseUrl||(v=B.split("/"),A=v.pop(),v=v.length?v.join("/")+"/":"./",r.baseUrl=v,B=A.replace(aa,"")),r.deps=r.deps?r.deps.concat(B):[B];break}}}d.checkReadyState=function(){var a=w.contexts,b;for(b in a)if(!(b in K)&&a[b].waitCount)return;d.resourcesReady(!0)},d.resourcesReady=function(a){var b,c;d.resourcesDone=a;if(d.resourcesDone)for(c in a=w.contexts,a)!(c in K)&&(b=a[c],b.jQueryIncremented)&&(V(b.jQuery,!1),b.jQueryIncremented=!1)},d.pageLoaded=function(){document.readyState!=="complete"&&(document.readyState="complete")},G&&document.addEventListener&&!document.readyState&&(document.readyState="loading",window.addEventListener("load",d.pageLoaded,!1)),d(r),d.isAsync&&typeof setTimeout!="undefined"&&(C=w.contexts[r.context||"_"],C.requireWait=!0,setTimeout(function(){C.requireWait=!1,C.takeGlobalQueue(),C.jQueryCheck(),C.scriptCount||C.resume(),d.checkReadyState()},0))}})()
View
40 demo/build.js
@@ -0,0 +1,40 @@
+({
+ appDir: '.',
+
+ baseUrl: 'lib',
+
+ /**
+ * Uncomment to turn off uglify minification.
+ *
+ * This can help for debugging templates...
+ * /
+ optimize: 'none',
+ /**/
+
+ dir: '../demo-build',
+
+ paths: {
+ tpl: '../../tpl'
+ },
+
+ /**
+ * This removes the plugin from the build
+ * As templates are functions and don't really need the plugin to work,
+ * you can choose to exclude it and save some Ko
+ *
+ * The plugin will actually become an empty function and take about 64 bytes minified...
+ *
+ * Comment to turn off exclusion if you plan to use dynamic loading/compiling of templates
+ *
+ */
+ pragmasOnSave: {
+ excludeTpl: true
+ },
+ /**/
+
+ modules: [
+ {
+ name: "main"
+ }
+ ]
+})
View
4 demo/build.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+rm -rf ../demo-build
+node ../tools/r.js -o build.js
View
4 demo/index.html
@@ -0,0 +1,4 @@
+<!doctype html>
+<title>RequireJS Micro-Template Plugin Demo</title>
+<body></body>
+<script src="lib/require.js" data-main="lib/main.js"></script>
View
3  demo/lib/hello.tpl
@@ -0,0 +1,3 @@
+<h1>
+ Hello <%= world %>
+</h1>
View
9 demo/lib/main.js
@@ -0,0 +1,9 @@
+require({
+ paths: {
+ tpl: '../../tpl'
+ }
+}, ['tpl!hello.tpl'], function(helloTpl) {
+
+ document.body.innerHTML += helloTpl({world: 'Worrrrrld'});
+
+});
View
13 demo/lib/node-test.js
@@ -0,0 +1,13 @@
+var requirejs = require('requirejs');
+
+requirejs.config({nodeRequire: require});
+
+requirejs({
+ paths: {
+ tpl: '../../tpl'
+ }
+}, ['tpl!hello.tpl'], function(helloTpl) {
+
+ console.log(helloTpl({world: 'Worrrrrld'}));
+
+});
View
31 demo/lib/require.js
@@ -0,0 +1,31 @@
+/*
+ RequireJS 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
+ Available via the MIT or new BSD license.
+ see: http://github.com/jrburke/requirejs for details
+*/
+var requirejs,require,define;
+(function(){function J(b){return M.call(b)==="[object Function]"}function E(b){return M.call(b)==="[object Array]"}function Z(b,c,i){for(var j in c)if(!(j in K)&&(!(j in b)||i))b[j]=c[j];return d}function N(b,c,d){b=Error(c+"\nhttp://requirejs.org/docs/errors.html#"+b);if(d)b.originalError=d;return b}function $(b,c,d){var j,l,q;for(j=0;q=c[j];j++){q=typeof q==="string"?{name:q}:q;l=q.location;if(d&&(!l||l.indexOf("/")!==0&&l.indexOf(":")===-1))l=d+"/"+(l||q.name);b[q.name]={name:q.name,location:l||
+q.name,main:(q.main||"main").replace(da,"").replace(aa,"")}}}function V(b,c){b.holdReady?b.holdReady(c):c?b.readyWait+=1:b.ready(!0)}function ea(b){function c(a,h){var e,s;if(a&&a.charAt(0)==="."&&h){p.pkgs[h]?h=[h]:(h=h.split("/"),h=h.slice(0,h.length-1));e=a=h.concat(a.split("/"));var b;for(s=0;b=e[s];s++)if(b===".")e.splice(s,1),s-=1;else if(b==="..")if(s===1&&(e[2]===".."||e[0]===".."))break;else s>0&&(e.splice(s-1,2),s-=2);s=p.pkgs[e=a[0]];a=a.join("/");s&&a===e+"/"+s.main&&(a=e)}return a}function i(a,
+h){var e=a?a.indexOf("!"):-1,b=null,d=h?h.name:null,f=a,k,i;e!==-1&&(b=a.substring(0,e),a=a.substring(e+1,a.length));b&&(b=c(b,d));a&&(b?k=(e=n[b])&&e.normalize?e.normalize(a,function(a){return c(a,d)}):c(a,d):(k=c(a,d),i=E[k],i||(i=g.nameToUrl(k,null,h),E[k]=i)));return{prefix:b,name:k,parentMap:h,url:i,originalName:f,fullName:b?b+"!"+(k||""):k}}function j(){var a=!0,h=p.priorityWait,e,b;if(h){for(b=0;e=h[b];b++)if(!t[e]){a=!1;break}a&&delete p.priorityWait}return a}function l(a,h,e){return function(){var b=
+ga.call(arguments,0),c;if(e&&J(c=b[b.length-1]))c.__requireJsBuild=!0;b.push(h);return a.apply(null,b)}}function q(a,h){var e=l(g.require,a,h);Z(e,{nameToUrl:l(g.nameToUrl,a),toUrl:l(g.toUrl,a),defined:l(g.requireDefined,a),specified:l(g.requireSpecified,a),isBrowser:d.isBrowser});return e}function o(a){var h,e,b;b=a.callback;var c=a.map,f=c.fullName,k=a.deps,fa=a.listeners;if(b&&J(b)){if(p.catchError.define)try{e=d.execCb(f,a.callback,k,n[f])}catch(j){h=j}else e=d.execCb(f,a.callback,k,n[f]);if(f)a.cjsModule&&
+a.cjsModule.exports!==void 0?e=n[f]=a.cjsModule.exports:e===void 0&&a.usingExports?e=n[f]:(n[f]=e,F[f]&&(Q[f]=!0))}else f&&(e=n[f]=b,F[f]&&(Q[f]=!0));if(D[a.id])delete D[a.id],a.isDone=!0,g.waitCount-=1,g.waitCount===0&&(I=[]);delete R[f];if(d.onResourceLoad&&!a.placeholder)d.onResourceLoad(g,c,a.depArray);if(h)return e=(f?i(f).url:"")||h.fileName||h.sourceURL,b=h.moduleTree,h=N("defineerror",'Error evaluating module "'+f+'" at location "'+e+'":\n'+h+"\nfileName:"+e+"\nlineNumber: "+(h.lineNumber||
+h.line),h),h.moduleName=f,h.moduleTree=b,d.onError(h);for(h=0;b=fa[h];h++)b(e)}function r(a,h){return function(b){a.depDone[h]||(a.depDone[h]=!0,a.deps[h]=b,a.depCount-=1,a.depCount||o(a))}}function v(a,h){var b=h.map,c=b.fullName,i=b.name,f=L[a]||(L[a]=n[a]),k;if(!h.loading)h.loading=!0,k=function(a){h.callback=function(){return a};o(h);t[h.id]=!0;x()},k.fromText=function(a,h){var b=O;t[a]=!1;g.scriptCount+=1;g.fake[a]=!0;b&&(O=!1);d.exec(h);b&&(O=!0);g.completeLoad(a)},c in n?k(n[c]):f.load(i,q(b.parentMap,
+!0),k,p)}function w(a){D[a.id]||(D[a.id]=a,I.push(a),g.waitCount+=1)}function C(a){this.listeners.push(a)}function u(a,b){var e=a.fullName,c=a.prefix,d=c?L[c]||(L[c]=n[c]):null,f,k;e&&(f=R[e]);if(!f&&(k=!0,f={id:(c&&!d?M++ +"__p@:":"")+(e||"__r@"+M++),map:a,depCount:0,depDone:[],depCallbacks:[],deps:[],listeners:[],add:C},z[f.id]=!0,e&&(!c||L[c])))R[e]=f;c&&!d?(e=u(i(c),!0),e.add(function(){var b=i(a.originalName,a.parentMap),b=u(b,!0);f.placeholder=!0;b.add(function(a){f.callback=function(){return a};
+o(f)})})):k&&b&&(t[f.id]=!1,g.paused.push(f),w(f));return f}function y(a,b,e,c){var a=i(a,c),d=a.name,f=a.fullName,k=u(a),j=k.id,l=k.deps,m;if(f){if(f in n||t[j]===!0||f==="jquery"&&p.jQuery&&p.jQuery!==e().fn.jquery)return;z[j]=!0;t[j]=!0;f==="jquery"&&e&&S(e())}k.depArray=b;k.callback=e;for(e=0;e<b.length;e++)if(j=b[e])j=i(j,d?a:c),m=j.fullName,b[e]=m,m==="require"?l[e]=q(a):m==="exports"?(l[e]=n[f]={},k.usingExports=!0):m==="module"?k.cjsModule=l[e]={id:d,uri:d?g.nameToUrl(d,null,c):void 0,exports:n[f]}:
+m in n&&!(m in D)&&(!(f in F)||f in F&&Q[m])?l[e]=n[m]:(f in F&&(F[m]=!0,delete n[m],T[j.url]=!1),k.depCount+=1,k.depCallbacks[e]=r(k,e),u(j,!0).add(k.depCallbacks[e]));k.depCount?w(k):o(k)}function m(a){y.apply(null,a)}function A(a,b){if(!a.isDone){var e=a.map.fullName,c=a.depArray,d,f,g,j;if(e){if(b[e])return n[e];b[e]=!0}if(c)for(d=0;d<c.length;d++)if(f=c[d])if((g=i(f).prefix)&&(j=D[g])&&A(j,b),(g=D[f])&&!g.isDone&&t[f])f=A(g,b),a.depCallbacks[d](f);return e?n[e]:void 0}}function B(){var a=p.waitSeconds*
+1E3,b=a&&g.startTime+a<(new Date).getTime(),a="",e=!1,c=!1,i;if(!(g.pausedCount>0)){if(p.priorityWait)if(j())x();else return;for(i in t)if(!(i in K)&&(e=!0,!t[i]))if(b)a+=i+" ";else{c=!0;break}if(e||g.waitCount){if(b&&a)return i=N("timeout","Load timeout for modules: "+a),i.requireType="timeout",i.requireModules=a,d.onError(i);if(c||g.scriptCount){if((G||ba)&&!W)W=setTimeout(function(){W=0;B()},50)}else{if(g.waitCount){for(H=0;a=I[H];H++)A(a,{});g.paused.length&&x();X<5&&(X+=1,B())}X=0;d.checkReadyState()}}}}
+var g,x,p={waitSeconds:7,baseUrl:"./",paths:{},pkgs:{},catchError:{}},P=[],z={require:!0,exports:!0,module:!0},E={},n={},t={},D={},I=[],T={},M=0,R={},L={},F={},Q={},Y=0;S=function(a){if(!g.jQuery&&(a=a||(typeof jQuery!=="undefined"?jQuery:null))&&!(p.jQuery&&a.fn.jquery!==p.jQuery)&&("holdReady"in a||"readyWait"in a))if(g.jQuery=a,m(["jquery",[],function(){return jQuery}]),g.scriptCount)V(a,!0),g.jQueryIncremented=!0};x=function(){var a,b,e,c,i,f;Y+=1;if(g.scriptCount<=0)g.scriptCount=0;for(;P.length;)if(a=
+P.shift(),a[0]===null)return d.onError(N("mismatch","Mismatched anonymous define() module: "+a[a.length-1]));else m(a);if(!p.priorityWait||j())for(;g.paused.length;){i=g.paused;g.pausedCount+=i.length;g.paused=[];for(c=0;a=i[c];c++)b=a.map,e=b.url,f=b.fullName,b.prefix?v(b.prefix,a):!T[e]&&!t[f]&&(d.load(g,f,e),T[e]=!0);g.startTime=(new Date).getTime();g.pausedCount-=i.length}Y===1&&B();Y-=1};g={contextName:b,config:p,defQueue:P,waiting:D,waitCount:0,specified:z,loaded:t,urlMap:E,urlFetched:T,scriptCount:0,
+defined:n,paused:[],pausedCount:0,plugins:L,needFullExec:F,fake:{},fullExec:Q,managerCallbacks:R,makeModuleMap:i,normalize:c,configure:function(a){var b,e,c;a.baseUrl&&a.baseUrl.charAt(a.baseUrl.length-1)!=="/"&&(a.baseUrl+="/");b=p.paths;c=p.pkgs;Z(p,a,!0);if(a.paths){for(e in a.paths)e in K||(b[e]=a.paths[e]);p.paths=b}if((b=a.packagePaths)||a.packages){if(b)for(e in b)e in K||$(c,b[e],e);a.packages&&$(c,a.packages);p.pkgs=c}if(a.priority)e=g.requireWait,g.requireWait=!1,g.takeGlobalQueue(),x(),
+g.require(a.priority),x(),g.requireWait=e,p.priorityWait=a.priority;if(a.deps||a.callback)g.require(a.deps||[],a.callback)},requireDefined:function(a,b){return i(a,b).fullName in n},requireSpecified:function(a,b){return i(a,b).fullName in z},require:function(a,c,e){if(typeof a==="string"){if(J(c))return d.onError(N("requireargs","Invalid require call"));if(d.get)return d.get(g,a,c);c=i(a,c);a=c.fullName;return!(a in n)?d.onError(N("notloaded","Module name '"+c.fullName+"' has not been loaded yet for context: "+
+b)):n[a]}(a&&a.length||c)&&y(null,a,c,e);if(!g.requireWait)for(;!g.scriptCount&&g.paused.length;)g.takeGlobalQueue(),x();return g.require},takeGlobalQueue:function(){U.length&&(ha.apply(g.defQueue,[g.defQueue.length-1,0].concat(U)),U=[])},completeLoad:function(a){var b;for(g.takeGlobalQueue();P.length;)if(b=P.shift(),b[0]===null){b[0]=a;break}else if(b[0]===a)break;else m(b),b=null;b?m(b):m([a,[],a==="jquery"&&typeof jQuery!=="undefined"?function(){return jQuery}:null]);S();d.isAsync&&(g.scriptCount-=
+1);x();d.isAsync||(g.scriptCount-=1)},toUrl:function(a,b){var c=a.lastIndexOf("."),d=null;c!==-1&&(d=a.substring(c,a.length),a=a.substring(0,c));return g.nameToUrl(a,d,b)},nameToUrl:function(a,b,e){var i,j,f,k,l=g.config,a=c(a,e&&e.fullName);if(d.jsExtRegExp.test(a))b=a+(b?b:"");else{i=l.paths;j=l.pkgs;e=a.split("/");for(k=e.length;k>0;k--)if(f=e.slice(0,k).join("/"),i[f]){e.splice(0,k,i[f]);break}else if(f=j[f]){a=a===f.name?f.location+"/"+f.main:f.location;e.splice(0,k,a);break}b=e.join("/")+(b||
+".js");b=(b.charAt(0)==="/"||b.match(/^\w+:/)?"":l.baseUrl)+b}return l.urlArgs?b+((b.indexOf("?")===-1?"?":"&")+l.urlArgs):b}};g.jQueryCheck=S;g.resume=x;return g}function ia(){var b,c,d;if(m&&m.readyState==="interactive")return m;b=document.getElementsByTagName("script");for(c=b.length-1;c>-1&&(d=b[c]);c--)if(d.readyState==="interactive")return m=d;return null}var ja=/(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,ka=/require\(\s*["']([^'"\s]+)["']\s*\)/g,da=/^\.\//,aa=/\.js$/,M=Object.prototype.toString,r=Array.prototype,
+ga=r.slice,ha=r.splice,G=!!(typeof window!=="undefined"&&navigator&&document),ba=!G&&typeof importScripts!=="undefined",la=G&&navigator.platform==="PLAYSTATION 3"?/^complete$/:/^(complete|loaded)$/,ca=typeof opera!=="undefined"&&opera.toString()==="[object Opera]",K={},u={},U=[],m=null,X=0,O=!1,d,r={},I,w,y,z,v,A,B,H,C,S,W;if(typeof define==="undefined"){if(typeof requirejs!=="undefined")if(J(requirejs))return;else r=requirejs,requirejs=void 0;typeof require!=="undefined"&&!J(require)&&(r=require,
+require=void 0);d=requirejs=function(b,c,d){var j="_",l;!E(b)&&typeof b!=="string"&&(l=b,E(c)?(b=c,c=d):b=[]);if(l&&l.context)j=l.context;d=u[j]||(u[j]=ea(j));l&&d.configure(l);return d.require(b,c)};d.config=function(b){return d(b)};require||(require=d);d.toUrl=function(b){return u._.toUrl(b)};d.version="1.0.0";d.jsExtRegExp=/^\/|:|\?|\.js$/;w=d.s={contexts:u,skipAsync:{}};if(d.isAsync=d.isBrowser=G)if(y=w.head=document.getElementsByTagName("head")[0],z=document.getElementsByTagName("base")[0])y=
+w.head=z.parentNode;d.onError=function(b){throw b;};d.load=function(b,c,i){d.resourcesReady(!1);b.scriptCount+=1;d.attach(i,b,c);if(b.jQuery&&!b.jQueryIncremented)V(b.jQuery,!0),b.jQueryIncremented=!0};define=function(b,c,d){var j,l;typeof b!=="string"&&(d=c,c=b,b=null);E(c)||(d=c,c=[]);!c.length&&J(d)&&d.length&&(d.toString().replace(ja,"").replace(ka,function(b,d){c.push(d)}),c=(d.length===1?["require"]:["require","exports","module"]).concat(c));if(O&&(j=I||ia()))b||(b=j.getAttribute("data-requiremodule")),
+l=u[j.getAttribute("data-requirecontext")];(l?l.defQueue:U).push([b,c,d])};define.amd={multiversion:!0,plugins:!0,jQuery:!0};d.exec=function(b){return eval(b)};d.execCb=function(b,c,d,j){return c.apply(j,d)};d.addScriptToDom=function(b){I=b;z?y.insertBefore(b,z):y.appendChild(b);I=null};d.onScriptLoad=function(b){var c=b.currentTarget||b.srcElement,i;if(b.type==="load"||c&&la.test(c.readyState))m=null,b=c.getAttribute("data-requirecontext"),i=c.getAttribute("data-requiremodule"),u[b].completeLoad(i),
+c.detachEvent&&!ca?c.detachEvent("onreadystatechange",d.onScriptLoad):c.removeEventListener("load",d.onScriptLoad,!1)};d.attach=function(b,c,i,j,l,m){var o;if(G)return j=j||d.onScriptLoad,o=c&&c.config&&c.config.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script"),o.type=l||"text/javascript",o.charset="utf-8",o.async=!w.skipAsync[b],c&&o.setAttribute("data-requirecontext",c.contextName),o.setAttribute("data-requiremodule",i),o.attachEvent&&
+!ca?(O=!0,m?o.onreadystatechange=function(){if(o.readyState==="loaded")o.onreadystatechange=null,o.attachEvent("onreadystatechange",j),m(o)}:o.attachEvent("onreadystatechange",j)):o.addEventListener("load",j,!1),o.src=b,m||d.addScriptToDom(o),o;else ba&&(importScripts(b),c.completeLoad(i));return null};if(G){v=document.getElementsByTagName("script");for(H=v.length-1;H>-1&&(A=v[H]);H--){if(!y)y=A.parentNode;if(B=A.getAttribute("data-main")){if(!r.baseUrl)v=B.split("/"),A=v.pop(),v=v.length?v.join("/")+
+"/":"./",r.baseUrl=v,B=A.replace(aa,"");r.deps=r.deps?r.deps.concat(B):[B];break}}}d.checkReadyState=function(){var b=w.contexts,c;for(c in b)if(!(c in K)&&b[c].waitCount)return;d.resourcesReady(!0)};d.resourcesReady=function(b){var c,i;d.resourcesDone=b;if(d.resourcesDone)for(i in b=w.contexts,b)if(!(i in K)&&(c=b[i],c.jQueryIncremented))V(c.jQuery,!1),c.jQueryIncremented=!1};d.pageLoaded=function(){if(document.readyState!=="complete")document.readyState="complete"};if(G&&document.addEventListener&&
+!document.readyState)document.readyState="loading",window.addEventListener("load",d.pageLoaded,!1);d(r);if(d.isAsync&&typeof setTimeout!=="undefined")C=w.contexts[r.context||"_"],C.requireWait=!0,setTimeout(function(){C.requireWait=!1;C.takeGlobalQueue();C.jQueryCheck();C.scriptCount||C.resume();d.checkReadyState()},0)}})();
View
9,042 tools/r.js
9,042 additions, 0 deletions not shown
View
48 tpl.js
@@ -1,8 +1,9 @@
/**
- * Made from the plugin text.js
+ * Adapted from the official plugin text.js
+ *
* Uses UnderscoreJS micro-templates : http://documentcloud.github.com/underscore/#template
* @author Julien Cabanès <julien@zeeagency.com>
- * @version 0.1
+ * @version 0.2
*
* @license RequireJS text 0.24.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
@@ -14,18 +15,25 @@
java: false */
(function () {
+//>>excludeStart('excludeTpl', pragmas.excludeTpl)
var progIds = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'],
+
xmlRegExp = /^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im,
+
bodyRegExp = /<body[^>]*>\s*([\s\S]+)\s*<\/body>/im,
+
buildMap = [],
+
templateSettings = {
evaluate : /<%([\s\S]+?)%>/g,
interpolate : /<%=([\s\S]+?)%>/g
},
- // JavaScript micro-templating, similar to John Resig's implementation.
- // Underscore templating handles arbitrary delimiters, preserves whitespace,
- // and correctly escapes quotes within interpolated code.
+ /**
+ * JavaScript micro-templating, similar to John Resig's implementation.
+ * Underscore templating handles arbitrary delimiters, preserves whitespace,
+ * and correctly escapes quotes within interpolated code.
+ */
template = function(str, data) {
var c = templateSettings;
var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' +
@@ -44,17 +52,22 @@
.replace(/\t/g, '')
+ "');}return __p.join('');";
return tmpl;
+
/** /
var func = new Function('obj', tmpl);
return data ? func(data) : func;
/**/
};
-
+//>>excludeEnd('excludeTpl')
+
define(function () {
- var tpl, get, fs;
+//>>excludeStart('excludeTpl', pragmas.excludeTpl)
+ var tpl;
+ var get, fs;
if (typeof window !== "undefined" && window.navigator && window.document) {
get = function (url, callback) {
+
var xhr = tpl.createXhr();
xhr.open('GET', url, true);
xhr.onreadystatechange = function (evt) {
@@ -73,13 +86,12 @@
fs = require.nodeRequire('fs');
get = function (url, callback) {
+
callback(fs.readFileSync(url, 'utf8'));
};
}
-
- tpl = {
+ return tpl = {
version: '0.24.0',
-
strip: function (content) {
//Strips <?xml ...?> declarations so that external SVG and XML
//documents can be added to a document without worry. Also, if the string
@@ -135,6 +147,7 @@
get: get,
load: function (name, req, onLoad, config) {
+
//Name has format: some.module.filext!strip
//The strip part is optional.
//if strip is present, then that means only get the string contents
@@ -159,28 +172,33 @@
url = req.nameToUrl(modName, "." + ext);
tpl.get(url, function (content) {
content = template(content);
- if (typeof window !== "undefined" && window.navigator && window.document) {
+
+ if(!config.isBuild) {
+ //if(typeof window !== "undefined" && window.navigator && window.document) {
content = new Function('obj', content);
}
content = strip ? tpl.strip(content) : content;
+
if (config.isBuild && config.inlineText) {
buildMap[name] = content;
}
onLoad(content);
});
+
},
write: function (pluginName, moduleName, write) {
if (moduleName in buildMap) {
var content = tpl.jsEscape(buildMap[moduleName]);
write("define('" + pluginName + "!" + moduleName +
- "', function() {return function (obj) { " +
+ "', function() {return function(obj) { " +
content.replace(/(\\')/g, "'").replace(/(\\\\)/g, "\\")+
"}});\n");
}
}
};
-
- return tpl;
+//>>excludeEnd('excludeTpl')
+ return function() {};
});
-}());
+//>>excludeEnd('excludeTpl')
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.