var Hogan={};(function(Hogan,useArrayBuffer){Hogan.Template=function(renderFunc,text,compiler,options){this.r=renderFunc||this.r;this.c=compiler;this.options=options;this.text=text||'';this.buf=(useArrayBuffer)?[]:'';} Hogan.Template.prototype={r:function(context,partials,indent){return'';},v:hoganEscape,t:coerceToString,render:function render(context,partials,indent){return this.ri([context],partials||{},indent);},ri:function(context,partials,indent){return this.r(context,partials,indent);},rp:function(name,context,partials,indent){var partial=partials[name];if(!partial){return'';} if(this.c&&typeof partial=='string'){partial=this.c.compile(partial,this.options);} return partial.ri(context,partials,indent);},rs:function(context,partials,section){var tail=context[context.length- 1];if(!isArray(tail)){section(context,partials,this);return;} for(var i=0;i=0;i--){v=ctx[i];if(v&&typeof v=='object'&&key in v){val=v[key];found=true;break;}} if(!found){return(returnFound)?false:"";} if(!returnFound&&typeof val=='function'){val=this.lv(val,ctx,partials);} return val;},ho:function(val,cx,partials,text,tags){var compiler=this.c;var options=this.options;options.delimiters=tags;var text=val.call(cx,text);text=(text==null)?String(text):text.toString();this.b(compiler.compile(text,options).render(cx,partials));return false;},b:(useArrayBuffer)?function(s){this.buf.push(s);}:function(s){this.buf+=s;},fl:(useArrayBuffer)?function(){var r=this.buf.join('');this.buf=[];return r;}:function(){var r=this.buf;this.buf='';return r;},ls:function(val,ctx,partials,inverted,start,end,tags){var cx=ctx[ctx.length- 1],t=null;if(!inverted&&this.c&&val.length>0){return this.ho(val,cx,partials,this.text.substring(start,end),tags);} t=val.call(cx);if(typeof t=='function'){if(inverted){return true;}else if(this.c){return this.ho(t,cx,partials,this.text.substring(start,end),tags);}} return t;},lv:function(val,ctx,partials){var cx=ctx[ctx.length- 1];var result=val.call(cx);if(typeof result=='function'){result=coerceToString(result.call(cx));if(this.c&&~result.indexOf("{\u007B")){return this.c.compile(result,this.options).render(cx,partials);}} return coerceToString(result);}};var rAmp=/&/g,rLt=//g,rApos=/\'/g,rQuot=/\"/g,hChars=/[&<>\"\']/;function coerceToString(val){return String((val===null||val===undefined)?'':val);} function hoganEscape(str){str=coerceToString(str);return hChars.test(str)?str.replace(rAmp,'&').replace(rLt,'<').replace(rGt,'>').replace(rApos,''').replace(rQuot,'"'):str;} var isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)==='[object Array]';};})(typeof exports!=='undefined'?exports:Hogan);(function(Hogan){var rIsWhitespace=/\S/,rQuot=/\"/g,rNewline=/\n/g,rCr=/\r/g,rSlash=/\\/g,tagTypes={'#':1,'^':2,'/':3,'!':4,'>':5,'<':6,'=':7,'_v':8,'{':9,'&':10};Hogan.scan=function scan(text,delimiters){var len=text.length,IN_TEXT=0,IN_TAG_TYPE=1,IN_TAG=2,state=IN_TEXT,tagType=null,tag=null,buf='',tokens=[],seenTag=false,i=0,lineStart=0,otag='{{',ctag='}}';function addBuf(){if(buf.length>0){tokens.push(new String(buf));buf='';}} function lineIsWhitespace(){var isAllWhitespace=true;for(var j=lineStart;j'){next.indent=tokens[j].toString()} tokens.splice(j,1);}}}else if(!noNewLine){tokens.push({tag:'\n'});} seenTag=false;lineStart=tokens.length;} function changeDelimiters(text,index){var close='='+ ctag,closeIndex=text.indexOf(close,index),delimiters=trim(text.substring(text.indexOf('=',index)+ 1,closeIndex)).split(' ');otag=delimiters[0];ctag=delimiters[1];return closeIndex+ close.length- 1;} if(delimiters){delimiters=delimiters.split(' ');otag=delimiters[0];ctag=delimiters[1];} for(i=0;i0){token=tokens.shift();if(token.tag=='#'||token.tag=='^'||isOpener(token,customTags)){stack.push(token);token.nodes=buildTree(tokens,token.tag,stack,customTags);instructions.push(token);}else if(token.tag=='/'){if(stack.length===0){throw new Error('Closing tag without opener: /'+ token.n);} opener=stack.pop();if(token.n!=opener.n&&!isCloser(token.n,opener.n,customTags)){throw new Error('Nesting error: '+ opener.n+' vs. '+ token.n);} opener.end=token.i;return instructions;}else{instructions.push(token);}} if(stack.length>0){throw new Error('missing closing tag: '+ stack.pop().n);} return instructions;} function isOpener(token,tags){for(var i=0,l=tags.length;i'){code+=partial(tree[i]);}else if(tag=='{'||tag=='&'){code+=tripleStache(tree[i].n,chooseMethod(tree[i].n));}else if(tag=='\n'){code+=text('"\\n"'+(tree.length-1==i?'':' + i'));}else if(tag=='_v'){code+=variable(tree[i].n,chooseMethod(tree[i].n));}else if(tag===undefined){code+=text('"'+ esc(tree[i])+'"');}} return code;} function section(nodes,id,method,start,end,tags){return'if(_.s(_.'+ method+'("'+ esc(id)+'",c,p,1),'+'c,p,0,'+ start+','+ end+',"'+ tags+'")){'+'_.rs(c,p,'+'function(c,p,_){'+ walk(nodes)+'});c.pop();}';} function invertedSection(nodes,id,method){return'if(!_.s(_.'+ method+'("'+ esc(id)+'",c,p,1),c,p,1,0,0,"")){'+ walk(nodes)+'};';} function partial(tok){return'_.b(_.rp("'+ esc(tok.n)+'",c,p,"'+(tok.indent||'')+'"));';} function tripleStache(id,method){return'_.b(_.t(_.'+ method+'("'+ esc(id)+'",c,p,0)));';} function variable(id,method){return'_.b(_.v(_.'+ method+'("'+ esc(id)+'",c,p,0)));';} function text(id){return'_.b('+ id+');';} Hogan.parse=function(tokens,text,options){options=options||{};return buildTree(tokens,'',[],options.sectionTags||[]);},Hogan.cache={};Hogan.compile=function(text,options){options=options||{};var key=text+'||'+!!options.asString;var t=this.cache[key];if(t){return t;} t=this.generate(this.parse(this.scan(text,options.delimiters),text,options),text,options);return this.cache[key]=t;};})(typeof exports!=='undefined'?exports:Hogan);