-
Notifications
You must be signed in to change notification settings - Fork 5
/
thunder.min.js
17 lines (17 loc) · 1.67 KB
/
thunder.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*!
* thunder
* Copyright(c) 2012 dreamerslab <[email protected]>
* MIT Licensed
*
* @fileoverview
* A lightning fast JavaScript template engine.
*/
(function(a){var b={};
var c={rules:{"&":"&","<":"<",">":">",'"':"""},fn:function(e){return typeof(e)!="string"?e:e.replace(/[&<>"]/g,function(f){return c.rules[f];
});}};var d={version:"0.2.0",settings:{open:"<?",close:"?>"},compiled_text:function(f,h){f=f.replace(/\s*<!\[CDATA\[\s*|\s*\]\]>\s*/g,"\n");var e=(h&&h.compress===true?f.replace(/\r\n\t|\s+/g," "):f.replace(/\r\n|\r/g,"\n")).split(d.settings.open).join(d.settings.close+"\x1b").split(d.settings.close);
var m="";var l=0;var g=e.length;var k="";for(;l<g;l++){k=e[l];m+=k.charAt(0)!="\x1b"?"_buf+='"+k.replace(/(\\|[\"\'])/g,"\\$1").replace(/\n/g,"\\n\\\n")+"'":(k.charAt(1)=="="?";_buf+="+k.substr(2).replace(/[\;\s]+$/,"")+";":(k.charAt(1)=="-"?";_buf+=e("+k.substr(2).replace(/[\;\s]+$/,"")+");":";"+k.substr(1).replace(/^\s+|\s+$/g,"").replace(/[\w\'\"\)\$]$/,"$&;")));
}return('var _buf="";'+m+";return _buf;").replace(/_buf\+\=\'\'\;/g,"").replace(/var _buf\=\"\"\;_buf\+\=/g,"var _buf=");},compile:function(e,f){var i=d.compiled_text(e,f);
var g;try{g=new Function("it","e",i);}catch(h){console.log("[thunder] Having trouble with creating a template function: \n"+i);throw h;}return function(j){return g(j,c.fn);
};},cached:function(e,f,g){g=g||e;if(!b[g]){b[g]=d.compile(e,f);}return b[g];},render:function(e,g,f){var h=f&&f.cached===true?"cached":"compile";return d[h](e,f)(g);
},clear:function(){b={};}};if(typeof define!=="undefined"){return define(function(f,e,g){g.exports=d;});}if(typeof exports==="undefined"){a.thunder=d;return;
}module.exports=d;})(this);