jtl
Version:
JTL templating language and engine
16 lines (15 loc) • 3.32 kB
JavaScript
/*!
------------------------------------------------------------------------------
jiro debugger v1.0.0
Written by Darius Aseriskis
Licensed under MIT
------------------------------------------------------------------------------
*/
var e=null,f=jiro,j={};
f.debug={error:function(a,b){var c=[];f.a(b)||(c=this.e(b));console.error&&console.error("ERROR: "+a+"\n\t"+c.join("\n\t"))},warn:function(a,b){var c=[];f.a(b)||(c=this.e(b));console.warn&&console.warn("WARNING: "+a+"\n\t"+c.join("\n\t"))},e:function(a){var b=a.f.replace(/\n\r/g,"\n").split("\n");result=[];for(var c=0;c<b.length;c++){var d=b[c].lastIndexOf(a.match);-1!=d&&result.push(a.match+" || Matched at line "+(c+1)+" column "+d)}return result},push:function(a,b){f.a(j[a])&&(j[a]=[]);j[a].push(b)},
pop:function(a){return j[a].pop(data)},clear:function(a){j[a]=[]},l:function(a){var b="";if(j[a]!=e&&0<j[a].length)for(var c=0;c<j[a].length;c++)b+=j[a][c];return b},j:function(a){for(var b=[],c=0;c<j[a].length;c++)b.push({key:a,value:j[a][c],full:a.replace("{code}",j[a][c])});return b},k:function(a){for(var b={},c=0;c<a.length;c++)b[a[c]]=b[a[c]]!=e?b[a[c]]++:1;return b["{"]==b["}"]&&b["("]==b[")"]},c:[],finish:function(a,b){for(var c in j)if(j[c]!=e&&0!=j[c].length){var d=this.j(c),h="\n\t";if(d!=
e)for(var g=0;g<d.length;g++)h+=this.e({code:d[g].value,match:d[g].value,f:b}).join("\n\t");this.c.push("There are not closed statements in "+c+h)}for(c in this.b)if(this.b[c]!=e&&0!=this.b[c].length){h="\n\t";for(g=0;g<this.b[c].length;g++)h+=this.e(this.b[c][g](!1)).join("\n\t");this.c.push("There is conditional, iterational or partials template not closed. "+c+h)}if(0<this.c.length){for(c=0;c<this.c.length;c++)this.error(this.c[c]);return!1}return!0},m:function(a,b,c){this.push(a,b);b=this.l(a);
if(this.k(b)){stack=this.j(a);this.clear(a);try{new Function(f.n,b)}catch(d){a="\n\t";if(stack!=e)for(b=0;b<stack.length;b++)a+=this.e({code:stack[b].value,match:stack[b].o,f:c}).join("\n\t");this.c.push("There seems to be an error in pattern: "+d.toString()+a)}}},b:{},d:function(a){this.b[a]&&this.b[a].pop()(!0)},i:function(a,b){f.a(this.b[a])&&(this.b[a]=[]);this.b[a].push(b)},h:function(a,b,c){try{new Function(f.n,b)}catch(d){that.c.push("There template code fails to compile. \n\t"+that.e({code:b,
match:a,f:c}).join("\n\t"))}}};f.g("{{{code}}}",function(a,b,c){var d=f.debug;f.a(d)||(d.d(a),d.m(a,b,c))});f.g("{{~{code}}}",function(a,b,c){var d=f.debug;f.a(d)||(d.d(a),d.i("{{~}}",function(d){if(!d)return{code:b,match:a,f:c}}),2<b.split(":").length&&d.c.push('There is a problem with ":" in template pattern. \n\t'+d.e({code:b,match:a,f:c}).join("\n\t")),d.h(a,b.split(":")[0],c))});f.g("{{~}}",function(a){var b=f.debug;f.a(b)||b.d(a)});
f.g("{{?{code}}}",function(a,b,c){var d=f.debug;f.a(d)||(d.d(a),d.i("{{?}}",function(d){if(!d)return{code:b,match:a,f:c}}),d.h(a,b,c))});f.g("{{?}}",function(a){var b=f.debug;f.a(b)||b.d(a)});f.g("{{??{code}}}",function(a,b,c){var d=f.debug;f.a(d)||(d.d(a),d.h(a,b,c))});
f.g("{{#{code}}}",function(a,b,c){var d=f.debug;f.a(d)||(d.d(a),d.i("{{#}}",function(d){if(!d)return{code:b,match:a,f:c}}),2<b.split(":").length&&d.c.push('There is a problem with ":" in template pattern. \n\t'+d.e({code:b,match:a,f:c}).join("\n\t")))});f.g("{{#}}",function(a){var b=f.debug;f.a(b)||b.d(a)});