File: src/js/GrammarTemplate.min.js

Recommend this page to a friend!
  Classes of Nikos M.  >  Grammar Template  >  src/js/GrammarTemplate.min.js  >  Download  
File: src/js/GrammarTemplate.min.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Grammar Template
Template engine in PHP and other languages
Author: By
Last change:
Date: 1 year ago
Size: 8,704 bytes
 

Contents

Class file image Download
/**
*   GrammarTemplate, 
*   versatile and intuitive grammar-based templating for PHP, Python, Node/XPCOM/JS, ActionScript
* 
*   @version: 3.0.0
*   https://github.com/foo123/GrammarTemplate
*
**/
!function(l,n,e){"use strict";"undefined"!=typeof Components&&"object"==typeof Components.classes&&"object"==typeof Components.classesByID&&Components.utils&&"function"==typeof Components.utils.import?(l.$deps=l.$deps||{})&&(l.EXPORTED_SYMBOLS=[n])&&(l[n]=l.$deps[n]=e.call(l)):"object"==typeof module&&module.exports?(module.$deps=module.$deps||{})&&(module.exports=module.$deps[n]=e.call(l)):"undefined"!=typeof System&&"function"==typeof System.register&&"function"==typeof System.import?System.register(n,[],function(t){t(n,e.call(l))}):"function"==typeof define&&define.amd&&"function"==typeof require&&"function"==typeof require.specified&&require.specified(n)?define(n,["module"],function(n){return e.moduleUri=n.uri,e.call(l)}):n in l||(l[n]=e.call(l)||1)&&"function"==typeof define&&define.amd&&define(function(){return l[n]})}("undefined"!=typeof self?self:this,"GrammarTemplate",function(l){"use strict";function n(l,n){return l&&y.call(l,n)?1:0}function e(l,n,e,t){var u=String(l);if(e=e||"0",t)for(;u.length<n;)u+=e;else for(;u.length<n;)u=e+u;return u}function t(){return t.GUID+=1,e((new Date).getTime().toString(16),12)+"--"+e(t.GUID.toString(16),4)}function u(l){return l instanceof Array||"[object Array]"===m.call(l)}function o(l,n,e){for(var t,u="";n<e&&(" "===(t=l[v](n))||"\r"===t||"\t"===t||"\v"===t||"\0"===t);)u+=t,n+=1;return u}function a(l,n){var e,t,u,o=l.length;if(o&&n.length)for(e="",u=0;u<o;u++)e+=t=l[v](u),"\n"===t&&(e+=n);else e=l;return e}function r(l,n,e,t){var u,o,a,r,i=0;if(n)for(u=l,o=n.length,a=0,i=1;a<o;){if(r=n[a++],null==u||null==u[r]){i=0;break}u=u[r]}if(!i&&e)for(u=l,o=e.length,a=0,i=1;a<o;){if(r=e[a++],null==u||null==u[r]){i=0;break}u=u[r]}if(!i&&null!=t&&t!==l){if(n)for(u=t,o=n.length,a=0,i=1;a<o;){if(r=n[a++],null==u||null==u[r]){i=0;break}u=u[r]}if(!i&&e)for(u=t,o=e.length,a=0,i=1;a<o;){if(r=e[a++],null==u||null==u[r]){i=0;break}u=u[r]}}return i?u:null}function i(l,n){this.prev=l||null,this.value=n||null}function s(l,n){n&&(n.next=this),this.node=l||null,this.prev=n||null,this.next=null}function f(l,n,e,t,o,a,i){var s,f,p,g,c,v,y,m,h=null,b="";if(-1===n.type){if((s=n.opt_args)&&s.value[5])for(;s;){if(f=s.value,p=r(l,f[1],[String(f[0])],f[6]?null:i),null===h&&n.name===f[0]&&(h=p),0===f[2]&&null==p||1===f[2]&&null!=p)return"";s=s.prev}}else h=r(l,n.key,[String(n.name)],n.loc?null:i);if(g=u(h),m=g?h.length:-1,g&&m>n.start)for(c=n.start,v=-1===n.end?m-1:Math.min(n.end,m-1),y=c;y<=v;y++)b+=d(l,n.tpl,e,t,y,a,i);else g||n.start!==n.end||(b=d(l,n.tpl,e,t,null,a,i));return b}function p(l,e,t,o,i,s,p){var d,c,v,y,m="";return e.stpl&&(n(t,e.stpl)||n(g.subGlobal,e.stpl)||n(o,e.stpl)||n(o,"*")||n(g.fnGlobal,e.stpl)||n(g.fnGlobal,"*"))?(d=r(l,e.key,[String(e.name)],e.loc?null:p),n(t,e.stpl)||n(g.subGlobal,e.stpl)?(null==i||0===i&&e.start===e.end&&e.opt||!u(d)||(d=i<d.length?d[i]:null),null==d&&null!==e.dval?m=e.dval:(v=n(t,e.stpl)?t[e.stpl].node:g.subGlobal[e.stpl].node,c={},null!=d&&(u(d)?c[v.name]=d:c=d),m=f(c,v,t,o,null,e.algn?s:"",null==p?l:p))):(y=null,n(o,e.stpl)?y=o[e.stpl]:n(o,"*")?y=o["*"]:n(g.fnGlobal,e.stpl)?y=g.fnGlobal[e.stpl]:g.fnGlobal["*"]&&(y=g.fnGlobal["*"]),u(d)&&(d=(i=null!=i?i:e.start)<d.length?d[i]:null),m=null==(d="function"==typeof y?y(d,{symbol:e,index:i,currentArguments:l,originalArguments:p,alignment:s}):String(y))&&null!==e.dval?e.dval:String(d),e.algn&&(m=a(m,s)))):e.opt&&null!==e.dval?m=e.dval:(u(d=r(l,e.key,[String(e.name)],e.loc?null:p))&&(d=(i=null!=i?i:e.start)<d.length?d[i]:null),m=null==d&&null!==e.dval?e.dval:String(d),e.algn&&(m=a(m,s))),m}function d(l,n,e,t,u,o,a){for(var r,i=o=o||"",s="";n;)-1===(r=n.node.type)?s+=f(l,n.node,e,t,u,n.node.algn?i:o,a):1===r?s+=p(l,n.node,e,t,u,n.node.algn?i:o,a):0===r?(i+=n.node.algn,s+=n.node.val):100===r&&(i=o,s+="\n"+o),n=n.next;return s}function g(l,n,e){var t=this;if(!(t instanceof g))return new g(l,n,e);t.id=null,t.tpl=null,t.fn={},t._args=[l||"",n||g.defaultDelimiters,e||!1]}var c="prototype",v="charAt",y=Object[c].hasOwnProperty,m=Object[c].toString,h=/^\s+|\s+$/g,b=String[c].trim?function(l){return l.trim()}:function(l){return l.replace(h,"")};return t.GUID=0,g.VERSION="3.0.0",g.defaultDelimiters=["<",">","[","]"],g.fnGlobal={},g.subGlobal={},g.guid=t,g.multisplit=function(l,e,u){var a,r,f,p,d,g,c,y,m,h,w,S,k,G,_,x,O,D,$,j,A,C,I,U,q,E,T=e[0],B=e[1],M=e[2],P=e[3],R=T.length,L=B.length,N=M.length,V=P.length,X="#"+P,Y=null,z=0,F=0,H=0,J=0,K=l.length,Q=[T,R,B,L],W=[M,N,P,V],Z=[null,0,null,0,null,0,null,0];for(u=!0===u,$={type:1,name:null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},A=m=new s({type:0,val:"",algn:""}),C=null,j=null,_={},O=null,x={},D=null,Q[1]<Q[3]&&(w=Q[0],Q[2]=Q[0],Q[0]=w,S=Q[1],Q[3]=Q[1],Q[1]=S),W[1]<W[3]&&(w=W[0],W[2]=W[0],W[0]=w,S=W[1],W[3]=W[1],W[1]=S),r=0,f=0,S=0;4>r&&4>f;)Q[r+1]<W[f+1]?(Z[S]=W[f],Z[S+1]=W[f+1],f+=2):(Z[S]=Q[r],Z[S+1]=Q[r+1],r+=2),S+=2;for(;4>r;)Z[S]=Q[r],Z[S+1]=Q[r+1],r+=2,S+=2;for(;4>f;)Z[S]=W[f],Z[S+1]=W[f+1],f+=2,S+=2;for(c=null,w="",S=0;S<K;)if("\\"!==(y=l[v](S)))if(E=null,Z[0]===l.substr(S,Z[1])?E=Z[0]:Z[2]===l.substr(S,Z[3])?E=Z[2]:Z[4]===l.substr(S,Z[5])?E=Z[4]:Z[6]===l.substr(S,Z[7])&&(E=Z[6]),T===E)S+=R,w.length&&(0===m.node.type?m.node.val+=w:m=new s({type:0,val:w,algn:""},m)),w="";else if(B===E){if(S+=L,d=w,w="",-1<(g=d.indexOf("|"))?(Y=d.slice(g+1),d=d.slice(0,g)):Y=null,"?"===(y=u?S<K?l[v](S):"":d[v](0))||"*"===y)F=1,"*"===y?(r=1,f=-1):(r=0,f=0),u?(S+=1)<K&&"!"===l[v](S)?(z=1,S+=1):z=0:"!"===d[v](1)?(z=1,d=d.slice(2)):(z=0,d=d.slice(1));else if("{"===y){if(u){for(w="",k=S+1,G=K;k<G&&"}"!==l[v](k);)w+=l[v](k++);S=k+1}else{for(w="",k=1,G=d.length;k<G&&"}"!==d[v](k);)w+=d[v](k++);d=d.slice(k+1)}(w=w.split(",")).length>1?(r=(r=b(w[0])).length?0|+r:0,f=(f=b(w[1])).length?0|+f:-1,F=1):(f=r=(r=b(w[0])).length?0|+r:0,F=0),w="",z=0}else F=0,z=0,r=0,f=0;if(z&&null===Y&&(Y=""),"@"===(y=d[v](0))?(H=1,d=d.slice(1)):H=0,"."===(y=d[v](0))?(J=1,d=d.slice(1)):J=0,p=-1<d.indexOf(":")?d.split(":"):[d,null],d=p[0],p=p[1],a=-1<d.indexOf(".")?d.split("."):null,O&&!n(x,O)&&(x[O]={}),":="+M===l.substr(S,2+N)&&(S+=2,D=p=p&&p.length?p:"grtpl--"+t(),O&&d.length&&(x[O][d]=p)),!d.length)continue;null==p&&O&&n(x,O)&&n(x[O],d)&&(p=x[O][d]),F&&!$.opt?($.name=d,$.key=a,$.stpl=p,$.dval=Y,$.opt=F,$.neg=z,$.algn=H,$.loc=J,$.start=r,$.end=f,j=new i(null,[d,a,z,r,f,F,J])):F?(r!==f&&$.start===$.end&&($.name=d,$.key=a,$.stpl=p,$.dval=Y,$.opt=F,$.neg=z,$.algn=H,$.loc=J,$.start=r,$.end=f),j=new i(j,[d,a,z,r,f,F,J])):F||null!==$.name||($.name=d,$.key=a,$.stpl=p,$.dval=Y,$.opt=0,$.neg=z,$.algn=H,$.loc=J,$.start=r,$.end=f,j=new i(null,[d,a,z,r,f,0,J])),0===m.node.type&&(m.node.algn=o(m.node.val,0,m.node.val.length)),m=new s({type:1,name:d,key:a,stpl:p,dval:Y,opt:F,algn:H,loc:J,start:r,end:f},m)}else if(M===E){if(S+=N,w.length&&(0===m.node.type?m.node.val+=w:m=new s({type:0,val:w,algn:""},m)),w="","#"===l[v](S)){for(k=S+1,G=K;k<G&&X!==l.substr(k,V+1);)w+=l[v](k++);S=k+V+1,0===m.node.type&&(m.node.algn=o(m.node.val,0,m.node.val.length)),m=new s({type:-100,val:w},m),w="";continue}c=new i(c,[m,C,$,j,O,D]),D&&(O=D),D=null,$={type:1,name:null,key:null,stpl:null,dval:null,opt:0,neg:0,algn:0,loc:0,start:0,end:0},j=null,C=m=new s({type:0,val:"",algn:""})}else P===E?(S+=V,h=m,I=C,U=$,q=j,c?(m=c.value[0],C=c.value[1],$=c.value[2],j=c.value[3],O=c.value[4],D=c.value[5],c=c.prev):m=null,w.length&&(0===h.node.type?h.node.val+=w:h=new s({type:0,val:w,algn:""},h)),w="",D?(_[D]=new s({type:2,name:U.name,key:U.key,loc:U.loc,algn:U.algn,start:U.start,end:U.end,opt_args:null,tpl:I}),D=null):(0===m.node.type&&(m.node.algn=o(m.node.val,0,m.node.val.length)),m=new s({type:-1,name:U.name,key:U.key,loc:U.loc,algn:U.algn,start:U.start,end:U.end,opt_args:q,tpl:I},m))):"\n"===(y=l[v](S++))?(w.length&&(0===m.node.type?m.node.val+=w:m=new s({type:0,val:w,algn:""},m)),w="",0===m.node.type&&(m.node.algn=o(m.node.val,0,m.node.val.length)),m=new s({type:100,val:"\n"},m)):w+=y;else w+=S+1<K?l[v](S+1):"",S+=2;return w.length&&(0===m.node.type?m.node.val+=w:m=new s({type:0,val:w,algn:""},m)),0===m.node.type&&(m.node.algn=o(m.node.val,0,m.node.val.length)),[A,_]},g.align=a,g.main=d,g[c]={constructor:g,id:null,tpl:null,fn:null,_args:null,dispose:function(){var l=this;return l.id=null,l.tpl=null,l.fn=null,l._args=null,l},parse:function(){var l=this;return null===l.tpl&&null!==l._args&&(l.tpl=g.multisplit(l._args[0],l._args[1],l._args[2]),l._args=null),l},render:function(l){var n=this;return null===n.tpl&&n.parse(),g.main(null==l?{}:l,n.tpl[0],n.tpl[1],n.fn)}},g});
For more information send a message to info at phpclasses dot org.