-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.min.js
6 lines (6 loc) · 2.14 KB
/
template.min.js
1
2
3
4
5
6
/* Meliantchenkov Pavel | @license MIT https://github.com/m13p4/template/blob/master/LICENSE */
var Template=function(){function p(k,h,e){for(var f=e||"p"+Math.floor(1E6*Math.random()),b=e?"":"'use strict';var "+f+"='',print=function(s){"+f+"+=s;};\n",c,a,d,g,l=0,m=0,n=RegExp("<\\/?\\s*\\{([\\s\\S]*?)\\}\\s*\\/?>","g");(c=n.exec(h))&&1E4>m++;)b+=f+"+="+JSON.stringify(h.substring(l,c.index))+";",d="",a=c[1].trim(),l=c.index+c[0].length,-1<(g=a.indexOf(":"))?(d=a.substr(0,g).trim(),a=a.substr(g+1).trim()):q.test(a.toLowerCase())&&(d=a,a=""),d=d.toLowerCase(),"</"==c[0].substr(0,2)?b+="}":""==
d?b+=f+"+="+a+";//*/\n":q.test(d)&&(r.test(d)?"for"==d&&-1<(g=a.indexOf("=>"))?(d=a.substr(0,g).trim(),a=a.substr(g+2).split(",",2),g="i"+Math.floor(1E6*Math.random()),b+=" var "+a.join("//*/\n,")+"//*/\nfor(var "+g+" in "+d+"//*/\n){",b=1==a.length?b+(a[0]+"//*/\n="+d+"//*/\n["+g+"];"):b+(a[1]+"//*/\n="+d+"//*/\n["+g+"];"+a[0]+"//*/\n="+g+";")):b="else"==d?b+"}else{":b+((0==d.indexOf("else")?"}":"")+d+"("+a+"//*/\n){"):t.test(d)?b+=a+"//*/\n":u.test(d)&&(b+=k[a]?p(k,k[a].t,f):""));return b+=f+"+="+
JSON.stringify(h.substr(l))+";"+(e?"":" return "+f+";")}function m(){var k={},h=function(e){if(this&&this.constructor===h)return m()(e);if(e){var f=new RegExp("<\\/?\\s*\\{\\s*("+n.source+")\\s*:?\\s*([\\s\\S]*?)\\}\\s*\\/?>","gi"),b=0,c,a;"string"!=typeof e&&e.toString&&(e=e.toString());if("string"!=(c=typeof e))throw'need a "string", "'+c+'" was given.';for(;(a=f.exec(e))&&1E3>b++;)if(c=a[0],"</"==c.substr(0,2))c=e.substring(l+g.length,a.index),k[d]={t:c};else{var d=a[2].trim();var g=c;var l=a.index}}return h};
h.render=function(e,f){var b=e;var c=f;"object"==typeof b&&(c=b,b="");c=c||{};b=k[b||""];if(b){b.f||(b.f=p(k,b.t));var a=[null].concat(Object.keys(c));a.push(b.f);c=(new (Function.prototype.bind.apply(Function,a))).apply(null,Object.values(c))}else c="";return c};h.parse=function(e){return h(e)};h.add=function(e,f){k[e]={t:f};return h};return h}var n=/tmpl|template/,t=/js|code/,r=/if|else(\s*if)?|for|while/,u=/imp(ort)?|inc(lude)?|req(uire)?/,q=new RegExp("^"+t.source+"|"+r.source+"|"+u.source+"$");
return m()}();"object"==typeof module&&(module.exports=Template);