(functiondefineMustache(global,factory){if(typeofexports==="object"&&exports&&typeofexports.nodeName!=="string"){factory(exports)}elseif(typeofdefine==="function"&&define.amd){define(["exports"],factory)}else{global.Mustache={};factory(global.Mustache)}})(this,functionmustacheFactory(mustache){varobjectToString=Object.prototype.toString;varisArray=Array.isArray||functionisArrayPolyfill(object){returnobjectToString.call(object)==="[object Array]"};functionisFunction(object){returntypeofobject==="function"}functiontypeStr(obj){returnisArray(obj)?"array":typeofobj}functionescapeRegExp(string){returnstring.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}functionhasProperty(obj,propName){returnobj!=null&&typeofobj==="object"&&propNameinobj}varregExpTest=RegExp.prototype.test;functiontestRegExp(re,string){returnregExpTest.call(re,string)}varnonSpaceRe=/\S/;functionisWhitespace(string){return!testRegExp(nonSpaceRe,string)}varentityMap={"&":"&","<":"<",">":">",'"':""","'":"'","/":"/","`":"`","=":"="};functionescapeHtml(string){returnString(string).replace(/[&<>"'`=\/]/g,functionfromEntityMap(s){returnentityMap[s]})}varwhiteRe=/\s*/;varspaceRe=/\s+/;varequalsRe=/\s*=/;varcurlyRe=/\s*\}/;vartagRe=/#|\^|\/|>|\{|&|=|!/;functionparseTemplate(template,tags){if(!template)return[];varsections=[];vartokens=[];varspaces=[];varhasTag=false;varnonSpace=false;functionstripSpace(){if(hasTag&&!nonSpace){while(spaces.length)deletetokens[spaces.pop()]}else{spaces=[]}hasTag=false;nonSpace=false}varopeningTagRe,closingTagRe,closingCurlyRe;functioncompileTags(tagsToCompile){if(typeoftagsToCompile==="string")tagsToCompile=tagsToCompile.split(spaceRe,2);if(!isArray(tagsToCompile)||tagsToCompile.length!==2)thrownewError("Invalid tags: "+tagsToCompile);openingTagRe=newRegExp(escapeRegExp(tagsToCompile[0])+"\\s*");closingTagRe=newRegExp("\\s*"+escapeRegExp(tagsToCompile[1]));closingCurlyRe=newRegExp("\\s*"+escapeRegExp("}"+tagsToCompile[1]))}compileTags(tags||mustache.tags);varscanner=newScanner(template);varstart,type,value,chr,token,openSection;while(!scanner.eos()){start=scanner.pos;value=scanner.scanUntil(openingTagRe);if(value){for(vari=0,valueLength=value.length;i<valueLength;++i){chr=value.charAt(i);if(isWhitespace(chr)){spaces.push(tokens.length)}else{nonSpace=true}tokens.push(["text",chr,start,start+1]);start+=1;if(chr==="\n")stripSpace()}}if(!scanner.scan(openingTagRe))break;hasTag=true;type=scanner.scan(tagRe)||"name";scanner.scan(whiteRe);if(type==="="){value=scanner.scanUntil(equalsRe);scanner.scan(equalsRe);scanner.scanUntil(closingTagRe)}elseif(type==="{"){value=scanner.scanUntil(closingCurlyRe);scanner.scan(curlyRe);scanner.scanUntil(closingTagRe);type="&"}else{value=scanner.scanUntil(closingTagRe)}if(!scanner.scan(closingTagRe))thrownewError("Unclosed tag at "+scanner.pos);token=[type,value,start,scanner.pos];tokens.push(token);if(type==="#"||type==="^"){sections.push(token)}elseif(type==="/"){openSection=sections.pop();if(!openSection)thrownewError('Unopened section "'+value+'" at '+start);if(openSection[1]!==value)thrownewError('Unclosed section "'+openSection[1]+'" at '+start)}elseif(type==="name"||type==="{"||type==="&"){nonSpace=true}elseif(type==="="){compileTags(value)}}openSection=sections.pop();if(openSection)thrownewError('Unclosed section "'+openSection[1]+'" at '+scanner.pos);returnnestTokens(squashTokens(tokens))}functionsquashTokens(tokens){varsquashedTokens=[];vartoken,lastToken;for(vari=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];if(token){if(token[0]==="text"&&lastToken&&lastToken[0]==="text"){lastToken[1]+=token[1];lastToken[3]=token[3]}else{squashedTokens.push(token);lastToken=token}}}returnsquashedTokens}functionnestTokens(tokens){varnestedTokens=[];varcollector=nestedTokens;varsections=[];vartoken,section;for(vari=0,numTokens=tokens.length;i<numTokens;++i){token=tokens[i];switch(token[0]){case"#":case"^":collector.push(token);sections.push(token);collector=token[4]=[];break;case"/":section=sections.pop();section[5]=token[2];collector=sections.length>0?sections[sections.length-1][4]:nestedTokens;break;default:collector.push(token)}}returnnestedTokens}functionScanner(string){this.string=string;this.tail=string;this.pos=0}Scanner.prototype.eos=functioneos(){returnthis.tail===""};Scanner.prototype.scan=functionscan(re){varmatch=this.tail.match(re);if(!match||match.index!==0)return"";varstring=match[0];this.tail=this.tail.substring(string.length);this.pos+=string.length;returnstring};Scanner.prototype.scanUntil=functionscanUntil(re){varindex=this.tail.search(re),match;switch(index){case-1:match=this.tail;this.tail="";break;case0:match="";break;default:match=this.tail.substring(0,index);this.tail=this.tail.substring(index)}this.pos+=match.length;returnmatch};functionContext(view,parentContext){this.view=view;this.cache={".":this.view};this.parent=parentContext}Context.prototype.push=functionpush(view){returnnewContext(view,this)};Context.prototype.lookup=functionlookup(name){varcache=this.cache;varvalue;if(cache.hasOwnProperty(name)){value=cache[name]}else{varcontext=this,names,index,lookupHit=false;while(context){if(name.indexOf(".")>0){value=context.view;names=name.split(".");index=0;while(value!=null&&index<names.length){if(index===names.length-1)lookupHit=hasProperty(value,names[index]);value=value[names[index++]]}}else{value=context.view[name];lookupHit=hasProperty(context.view,name)}if(lookupHit)break;context=context.parent}cache[name]=value}if(isFunction(value))value=value.call(this.view);returnvalue};functionWriter(){this.cache={}}Writer.prototype.clearCache=functionclearCache(){this.cache={}};Writer.prototype.parse=functionparse(template,tags){varcache=this.cache;varcacheKey=template+":"+(tags||mustache.tags).join(":");vartokens=cache[cacheKey];if(tokens==null)tokens=cache[cacheKey]=parseTemplate(template,tags);returntokens};Writer.prototype.render=functionrender(template,view,partials){vartokens=this.parse(template);varcontext=viewinstanceofContext?view:newContext(view);returnthis.renderTokens(tokens,context,partials,template)};Writer.prototype.renderTokens=functionrenderTokens(tokens,context,partials,originalTemplate){varbuffer="";vartoken,symbol,value;for(vari=0,numTokens=tokens.length;i<numTokens;++i){value=undefined;token=tokens[i];symbol=token[0];if(symbol==="#")value=this.renderSection(token,context,partials,originalTemplate);elseif(symbol==="^")value=this.renderInverted(token,context,partials,originalTemplate);elseif(symbol===">")value=this.renderPartial(token,context,partials,originalTemplate);elseif(symbol==="&")value=this.unescapedValue(token,context);elseif(symbol==="name")value=this.escapedValue(token,context);elseif(symbol==="text")value=this.rawValue(token);if(value!==undefined)buffer+=value}returnbuffer};Writer.prototype.renderSection=functionrenderSection(token,context,partials,originalTemplate){varself=this;varbuffer="";varvalue=context.lookup(token[1]);functionsubRender(template){returnself.render(template,context,partials)}if(!value)return;if(isArray(value)){for(varj=0,valueLength=value.length;j<valueLength;++j){buffer+=this.renderTokens(token[4],context.push(value[j]),partials,originalTemplate)}}elseif(typeofvalue==="object"||typeofvalue==="string"||typeofvalue==="number"){buffer+=this.renderTokens(token[4],context.push(value),partials,originalTemplate)}elseif(isFunction(value)){if(typeoforiginalTemplate!=="string")thrownewError("Cannot use higher-order sections without the original template");value=value.call(context.view,originalTemplate.slice(token[3],token[5]),subRender);if(value!=null)buffer+=value}else{buffer+=this.renderTokens(token[4],context,partials,originalTemplate)}returnbuffer};Writer.prototype.renderInverted=functionrenderInverted(token,context,partials,originalTemplate){varvalue=context.lookup(token[1]);if(!value||isArray(value)&&value.length===0)returnthis.renderTokens(token[4],context,partials,originalTemplate)};Writer.prototype.renderPartial=functionrenderPartial(token,context,partials){if(!partials)return;varvalue=isFunction(partials)?partials(token[1]):partials[token[1]];if(value!=null)returnthis.renderTokens(this.parse(value),context,partials,value)};Writer.prototype.unescapedValue=functionunescapedValue(token,context){varvalue=context.lookup(token[1]);if(value!=null)returnvalue};Writer.prototype.escapedValue=functionescapedValue(token,context){varvalue=context.lookup(token[1]);if(value!=null)returnmustache.escape(value)};Writer.prototype.rawValue=functionrawValue(token){returntoken[1]};mustache.name="mustache.js";mustache.version="2.3.1";mustache.tags=["{{","}}"];vardefaultWriter=newWriter;mustache.clearCache=functionclearCache(){returndefaultWriter.clearCache()};mustache.parse=functionparse(template,tags){returndefaultWriter.parse(template,tags)};mustache.render=functionrender(template,view,partials){if(typeoftemplate!=="string"){thrownewTypeError('Invalid template! Template should be a "string" '+'but "'+typeStr(template)+'" was given as the first '+"argument for mustache#render(template, view, partials)")}returndefaultWriter.render(template,view,partials)};mustache.to_html=functionto_html(template,view,partials,send){varresult=mustache.render(template,view,partials);if(isFunction(send)){send(result)}else{returnresult}};mustache.escape=escapeHtml;mustache.Scanner=Scanner;mustache.Context=Context;mustache.Writer=Writer;returnmustache});