/* MIT License https://github.com/isabo/DubStash/blob/master/LICENSE | Copyright (c) 2013 Itzy Sabo */(function() {var j=!0,m=null,q=!1; (function(){function n(a,b,c){this.o=a;this.d=b;this.c=c}function p(a){this.f=a;this.i=[]}function k(a,b){this.f=a;this.j=b;this.H=q;this.z=[];this.t=[]}function s(a,b,c){this.f=a;this.j=b;this.s=c}function h(a){this.h=a}function f(a){this.h=a;this.a=[];this.w=0;this.k=[]}var r={VERSION:"1.0.0.rc7",compile:function(a){return(new f(a)).e()},precompile:function(a){return(new f(a)).b()},registerGlobalTemplate:function(a,b){e.K(a,r.compile(b));this.v[a]=b},v:{},precompileGlobalTemplates:function(){var a=[""], b;for(b in this.v)a.push("DubStash.R.G('"+b+"', "+(new f(this.v[b])).b()+");");return a.join("\n")},registerGlobalData:function(a,b){e.registerGlobalData(a,b)},createContext:function(a,b,c){return new n(a,b,c)}};f.prototype.e=function(){this.D();var a=this.da();return function(b,c,d){return e.O(a,b,c,d)}};f.prototype.b=function(){this.D();return["function(d, i, s){","\tvar r = ["+this.ca().toString()+"];","\treturn DubStash.R.T(r, d, i, s);\n}"].join("\n")};f.prototype.da=function(){var a=[],b;for(b in this.k)a.push(this.k[b].e()); return a};f.prototype.ca=function(){var a=[],b;for(b in this.k)a.push(this.k[b].b());return a};f.prototype.D=function(){f.l.lastIndex=0;for(var a;(a=f.l.exec(this.h))!==m;)if(a[1].length===a[5].length){var b;this.n(a);switch(a[2]){case "if":a[3]?(b="/r"===a[4],a=new k(a[3],b),this.m(a),this.a.push(a)):console.log("Bad condition: "+a[0]);break;case "foreach":a[3]&&(a=new p(a[3]),this.m(a),this.a.push(a));break;case "else":b=q;if(this.a.length){var c=this.a[this.a.length-1];c instanceof k?c.aa():b= j}else b=j;b&&(this.n(a[0]),console.log("Unexpected {{else}} encountered!"));break;case "end":b=q;this.a.length?a[3]&&(c=this.a[this.a.length-1],b="if"===a[3]?!(c instanceof k):"foreach"===a[3]?!(c instanceof p):j):b=j;b?(this.n(a[0]),console.log("Unexpected {{end}} encountered!")):this.a.pop();break;default:c=2===a[1].length,b="/r"===a[3],a=new s(a[2],b,c),this.m(a)}}else console.log("Unbalanced brackets encountered: "+a[0]);a=[];a.index=this.h.length;this.n(a);this.a.length&&console.log("Missing {{end}}!")}; f.prototype.n=function(a){a="string"===typeof a?a:this.h.slice(this.w,a.index);a.length?this.m(new h(a)):this.w=f.l.lastIndex};f.prototype.m=function(a){this.a.length?this.a[this.a.length-1].A(a):this.k.push(a);this.w=f.l.lastIndex};f.l=/(\{{2,3})\s*([^\}\s]*)\s*([^\}\s]*)?\s*([^\}\s]*)?(\}{2,3})/g;h.prototype.e=function(){var a=this.h;return function(){return a}};h.prototype.b=function(){return["function(){",'\treturn "'+this.ea(this.h)+'";',"}"].join("\n")};h.V=/"/g;h.Y=/\r?\n/g;h.U=/\\/g;h.prototype.ea= function(a){return a.replace(h.U,"\\\\").replace(h.V,'\\"').replace(h.Y,"\\n")};s.prototype.e=function(){var a=this;return function(b,c){return e.N(a.f,a.j,a.s,b,c)}};s.prototype.b=function(){return["function(c, i){","\treturn DubStash.R.P("+['"'+this.f+'"',this.j,this.s].join(", ")+", c, i);","}"].join("\n")};k.prototype.aa=function(){this.H=j};k.prototype.A=function(a){(this.H?this.t:this.z).push(a)};k.prototype.e=function(){var a=this.f,b=this.j,c=this.q(this.z),d=this.q(this.t);return function(g, l){return e.L(a,b,c,d,g,l)}};k.prototype.b=function(){return["function(c, i){",'\tvar n = "'+this.f+'";',"\tvar r = "+this.j+";","\tvar t = ["+this.p(this.z).toString()+"];","\tvar f = ["+this.p(this.t).toString()+"];","\treturn DubStash.R.C(n, r, t, f, c, i);\n}"].join("\n")};k.prototype.q=function(a){var b=[],c;for(c in a)b.push(a[c].e());return b};k.prototype.p=function(a){var b=[],c;for(c in a)b.push(a[c].b());return b};p.prototype.e=function(){var a=this;return function(b,c){return e.M(a.f,a.q(), b,c)}};p.prototype.b=function(){return["function(c, i){",'\tvar n = "'+this.f+'";',"\tvar s = ["+this.p().toString()+"];","\treturn DubStash.R.I(n, s, c, i);\n}"].join("\n")};p.prototype.A=function(a){this.i.push(a)};p.prototype.q=function(){var a=[],b;for(b in this.i)a.push(this.i[b].e());return a};p.prototype.p=function(){var a=[],b;for(b in this.i)a.push(this.i[b].b());return a};var e={K:function(a,b){this.J[a]=b},J:{},registerGlobalData:function(a,b){this.u[a]=b},u:{},O:function(a,b,c,d){b=d|| new n(b,"",b);d=[];for(var g in a)d.push(a[g].call(m,b,c));return d.join("")},N:function(a,b,c,d,g){var l=e.g(a,d);if(g&&void 0===l)return c?"{{"+a+"}}":"{{{"+a+"}}}";if(void 0===l||l===m)return"";a=c?e.s(""+l):""+l;b&&-1!==a.indexOf("{{")&&(a=this.B(a).call(m,d.c,g,d));return a},L:function(a,b,c,d,g,l){(a=e.g(a,g))&&(b&&"{{"===a.slice(0,2)&&"}}"===a.slice(-2))&&(a=this.B(a).call(m,g.c,q,g));b=a?c:d;c=[];for(var f in b)c.push(b[f].call(m,g,l));return c.join("")},M:function(a,b,c,d){var g=e.g(a,c), f=[];if(g){a=c.d.length?c.d+"."+a:a;var h=new n(m,a+".[item]",c.c);this.$(g,function(a){for(var c in b)h.o=a,f.push(b[c].call(m,h,d))})}return f.join("")},B:function(a){var b;a&&(b=this.Q[a]);b||(b=r.compile(a),this.Q[a]=b);return b},Q:{},g:function(a,b){b=this.ba(a,b);if(b.name){a=b.name;var c=j}for(var d=new n(b.o,b.d,b.c),g=a.split("."),e=g.length-1,f=0;fe&&(console.log("Too many levels to climb from "+b.d+" to "+a+". Will stop at the top."),e=-1);-1!== e?(d=d.slice(0,e+1).join("."),e=this.g(d,new n(b.c,"",b.c))):(d="",e=b.c);d=new n(e,d,b.c);d.name=a.slice(3*c);return d}return b},$:function(a,b){if("function"===typeof a.forEach)a.forEach(b);else if("function"===typeof a.__iterator__)for(var c=a.__iterator__(q),d=q;!d;){try{var e=c.next()}catch(f){d=j}d||b.call(this,e)}else if("object"===typeof a)for(c in a)b.call(this,a[c]);else b.call(this,a)},s:function(a){return a.replace(e.S,"&").replace(e.X,"<").replace(e.W,">").replace(e.Z,""")}, X://g,S:/&/g,Z:/\"/g};e.r=new n(e.u,"",e.u);r.R=e;e.T=e.O;e.P=e.N;e.C=e.L;e.I=e.M;e.G=e.K;this.DubStash=r;try{module.exports=r}catch(t){}})();})();