(function(n){(function(n,t){if(typeof exports=="object"&&exports)t(exports);else{var i={};t(i);typeof define=="function"&&define.amd?define(i):n.Mustache=i}})(this,function(n){function w(n,t){return p.call(n,t)}function b(n){return!w(a,n)}function u(n){return typeof n=="function"}function o(n){return n.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g,"\\$&")}function g(n){return String(n).replace(/[&<>"'\/]/g,function(n){return d[n]})}function c(n){if(!e(n)||n.length!==2)throw new Error("Invalid tags: "+n);return[new RegExp(o(n[0])+"\\s*"),new RegExp("\\s*"+o(n[1]))]}function nt(t,i){function st(){if(ft&&!g)while(d.length)delete k[d.pop()];else d=[];ft=!1;g=!1}var p,f,e,nt,et,w,rt,ot;i=i||n.tags;t=t||"";typeof i=="string"&&(i=i.split(s));for(var a=c(i),u=new r(t),ut=[],k=[],d=[],ft=!1,g=!1;!u.eos();){if(p=u.pos,e=u.scanUntil(a[0]),e)for(rt=0,ot=e.length;rt<ot;++rt)nt=e.charAt(rt),b(nt)?d.push(k.length):g=!0,k.push(["text",nt,p,p+1]),p+=1,nt==="\n"&&st();if(!u.scan(a[0]))break;if(ft=!0,f=u.scan(y)||"name",u.scan(l),f==="="?(e=u.scanUntil(h),u.scan(h),u.scanUntil(a[1])):f==="{"?(e=u.scanUntil(new RegExp("\\s*"+o("}"+i[1]))),u.scan(v),u.scanUntil(a[1]),f="&"):e=u.scanUntil(a[1]),!u.scan(a[1]))throw new Error("Unclosed tag at "+u.pos);if(et=[f,e,p,u.pos],k.push(et),f==="#"||f==="^")ut.push(et);else if(f==="/"){if(w=ut.pop(),!w)throw new Error('Unopened section "'+e+'" at '+p);if(w[1]!==e)throw new Error('Unclosed section "'+w[1]+'" at '+p);}else f==="name"||f==="{"||f==="&"?g=!0:f==="="&&(a=c(i=e.split(s)))}if(w=ut.pop(),w)throw new Error('Unclosed section "'+w[1]+'" at '+u.pos);return it(tt(k))}function tt(n){for(var u=[],t,i,r=0,f=n.length;r<f;++r)t=n[r],t&&(t[0]==="text"&&i&&i[0]==="text"?(i[1]+=t[1],i[3]=t[3]):(u.push(t),i=t));return u}function it(n){for(var u=[],r=u,i=[],t,e,f=0,o=n.length;f<o;++f){t=n[f];switch(t[0]){case"#":case"^":r.push(t);i.push(t);r=t[4]=[];break;case"/":e=i.pop();e[5]=t[2];r=i.length>0?i[i.length-1][4]:u;break;default:r.push(t)}}return u}function r(n){this.string=n;this.tail=n;this.pos=0}function t(n,t){this.view=n==null?{}:n;this.cache={".":this.view};this.parent=t}function i(){this.cache={}}var l=/\s*/,s=/\s+/,a=/\S/,h=/\s*=/,v=/\s*\}/,y=/#|\^|\/|>|\{|&|=|!/,p=RegExp.prototype.test,k=Object.prototype.toString,e=Array.isArray||function(n){return k.call(n)==="[object Array]"},d={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"},f;r.prototype.eos=function(){return this.tail===""};r.prototype.scan=function(n){var i=this.tail.match(n),t;return i&&i.index===0?(t=i[0],this.tail=this.tail.substring(t.length),this.pos+=t.length,t):""};r.prototype.scanUntil=function(n){var i=this.tail.search(n),t;switch(i){case-1:t=this.tail;this.tail="";break;case 0:t="";break;default:t=this.tail.substring(0,i);this.tail=this.tail.substring(i)}return this.pos+=t.length,t};t.prototype.push=function(n){return new t(n,this)};t.prototype.lookup=function(n){var t,i,r,f;if(n in this.cache)t=this.cache[n];else{for(i=this;i;){if(n.indexOf(".")>0)for(t=i.view,r=n.split("."),f=0;t!=null&&f<r.length;)t=t[r[f++]];else t=i.view[n];if(t!=null)break;i=i.parent}this.cache[n]=t}return u(t)&&(t=t.call(this.view)),t};i.prototype.clearCache=function(){this.cache={}};i.prototype.parse=function(n,t){var r=this.cache,i=r[n];return i==null&&(i=r[n]=nt(n,t)),i};i.prototype.render=function(n,i,r){var u=this.parse(n),f=i instanceof t?i:new t(i);return this.renderTokens(u,f,r,n)};i.prototype.renderTokens=function(t,i,r,f){function y(n){return v.render(n,i,r)}for(var c,a,h="",v=this,s,o,l=0,p=t.length;l<p;++l){s=t[l];switch(s[0]){case"#":if(o=i.lookup(s[1]),!o)continue;if(e(o))for(c=0,a=o.length;c<a;++c)h+=this.renderTokens(s[4],i.push(o[c]),r,f);else if(typeof o=="object"||typeof o=="string")h+=this.renderTokens(s[4],i.push(o),r,f);else if(u(o)){if(typeof f!="string")throw new Error("Cannot use higher-order sections without the original template");o=o.call(i.view,f.slice(s[3],s[5]),y);o!=null&&(h+=o)}else h+=this.renderTokens(s[4],i,r,f);break;case"^":o=i.lookup(s[1]);(!o||e(o)&&o.length===0)&&(h+=this.renderTokens(s[4],i,r,f));break;case">":if(!r)continue;o=this.parse(u(r)?r(s[1]):r[s[1]]);o!=null&&(h+=this.renderTokens(o,i,r,f));break;case"&":o=i.lookup(s[1]);o!=null&&(h+=o);break;case"name":o=i.lookup(s[1]);o!=null&&(h+=n.escape(o));break;case"text":h+=s[1]}}return h};n.name="mustache.js";n.version="0.8.0";n.tags=["{{","}}"];f=new i;n.clearCache=function(){return f.clearCache()};n.parse=function(n,t){return f.parse(n,t)};n.render=function(n,t,i){return f.render(n,t,i)};n.to_html=function(t,i,r,f){var e=n.render(t,i,r);if(u(f))f(e);else return e};n.escape=g;n.Scanner=r;n.Context=t;n.Writer=i});n.mustache=function(n,t,i){return Mustache.render(n,t,i)};n.fn.mustache=function(t,i){return n(this).map(function(r,u){var f=n.trim(n(u).html()),e=n.mustache(f,t,i);return n(e).get()})};n.fn.mustacheparse=function(){return n(this).map(function(t,i){var r=n.trim(n(i).html()),u=Mustache.parse(r);return n(u).get()})}})(jQuery)