forked from jser-cc/ccTpl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcc-template.min.js
1 lines (1 loc) · 2.05 KB
/
cc-template.min.js
1
!function(e,t){"undefined"!=typeof module&&module&&module.exports?module.exports=t():"function"==typeof define&&define.amd?define(function(){return t()}):"function"==typeof define&&define.cmd?define(function(e,n,r){r.exports=t()}):(e.cc=e.cc||{},e.cc.Template=t())}(this,function(){function e(e,t){for(var n in e)e.hasOwnProperty(n)&&void 0!==t[n]&&(e[n]=t[n]);return e}function t(n){n=n||{},n.escapeMap&&(this.escape=this.createEscaper(n.escapeMap)),n.unescapeMap&&(this.unescape=this.createEscaper(n.unescapeMap)),this.options=e(t.getDefaultOptions(),n)}var n={"&":"&","<":"<",">":">",'"':""","'":"'","`":"`"},r=function(e){return Object.keys(e).reduce(function(t,n,r){return t[e[n]]=n,t},{})}(n);return t.getDefaultOptions=function(){return{scope:"scope",regexpHead:"<%",regexpTail:"%>"}},t.createEscaper=function(e){var t=function(t){return e[t]},n="(?:"+Object.keys(e).join("|")+")",r=RegExp(n),c=RegExp(n,"g");return function(e){return e=null==e?"":""+e,r.test(e)?e.replace(c,t):e}},t.prototype.escape=t.createEscaper(n),t.prototype.unescape=t.createEscaper(r),t.prototype.createEscaper=t.createEscaper,t.prototype._getTemplateRegExp=function(){return new RegExp(this.options.regexpHead+"([\\s\\S]+?)"+this.options.regexpTail,"g")},t.prototype.match=function(e){for(var t,n=this._getTemplateRegExp(),r=[];t=n.exec(e);)r.push(t);return r},t.prototype.compile=function(e){for(var t,n,r,c=this.match(e),p='var _ret = "";\n',o=0;t=c.shift();){switch(n=t[1][0],r=t[1].slice(1).trim(),p+='_ret += "'+e.slice(o,t.index).replace(/\n/g,"\\n")+'";',n){case"=":p+="_ret += this.escape("+r+");\n";break;case"-":p+="_ret += this.unescape("+r+");\n";break;case"!":p+="_ret += (("+r+' || "") + "");\n';break;default:p+=r+"\n"}o=t.index+t[0].length}p+='_ret += "'+e.slice(o).replace(/\n/g,"\\n")+'";\n',p+="return _ret;\n";var a;try{a=new Function(this.options.scope,p)}catch(e){throw e.source=p,e}var s=this,i=function(e,t){return t&&(t.escape||(t.escape=s.escape),t.unescape||(t.unescape=s.unescape)),a.call(t||s,e)};return i.source="function("+this.options.scope+"){\n"+p+"}",i},t});