Files
liquidjs/dist/liquid.min.js
T
2019-02-22 19:56:16 +00:00

3 lines
34 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Liquid=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function e(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var v=function(){return(v=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function h(o,s,u,a){return new(u||(u=Promise))(function(t,e){function n(t){try{i(a.next(t))}catch(t){e(t)}}function r(t){try{i(a.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new u(function(t){t(e.value)}).then(n,r)}i((a=a.apply(o,s||[])).next())})}function d(n,r){var i,o,s,t,u={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;u;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return u.label++,{value:e[1],done:!1};case 5:u.label++,o=e[1],e=[0];continue;case 7:e=u.ops.pop(),u.trys.pop();continue;default:if(!(s=0<(s=u.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){u=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){u.label=e[1];break}if(6===e[0]&&u.label<s[1]){u.label=s[1],s=e;break}if(s&&u.label<s[2]){u.label=s[2],u.ops.push(e);break}s[2]&&u.ops.pop(),u.trys.pop();continue}e=r.call(n,u)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}var i=Object.prototype.toString,o=Array.prototype.toString;function l(t){return"[object String]"===i.call(t)}function s(t){return"function"==typeof t}function a(t){return u(t)?"":s(t.to_liquid)?a(t.to_liquid()):s(t.toLiquid)?a(t.toLiquid()):s(t.to_s)?t.to_s():-1<[i,o].indexOf(t.toString)?(e=t,n=[],JSON.stringify(e,function(t,e){if(g(e)){if(-1!==n.indexOf(e))return;n.push(e)}return e})):s(t.toString)?t.toString():i.call(t);var e,n}function u(t){return null==t}function f(t){return"[object Array]"===i.call(t)}function c(t,e){for(var n in t=t||{})if(t.hasOwnProperty(n)&&!1===e(t[n],n,t))break;return t}function p(t){return t[t.length-1]}function g(t){var e=typeof t;return null!==t&&("object"===e||"function"===e)}function m(t,e,n){void 0===e&&(e=t,t=0),n=n||1;for(var r=[],i=t;i<e;i+=n)r.push(i);return r}function w(t,e,n){void 0===n&&(n=" ");for(var r=e-(t=String(t)).length;0<r--;)t=n+t;return t}var t=new RegExp(/'[^']*'/.source+"|"+/"[^"]*"/.source),y=new RegExp("(?:"+t.source+"|[^'\"])*"),n=/[+-]?(?:\d+\.?\d*|\.?\d+)/,b=/true|false/,x=/[\w-]+[?]?/,T=new RegExp("\\[(?:"+t.source+"|[\\w-\\.]+)\\]"),E=new RegExp("(?:"+t.source+"|"+b.source+"|"+n.source+")"),k=new RegExp(x.source+"(?:\\."+x.source+"|"+T.source+")*"),S=new RegExp("(?:"+k.source+"|"+n.source+")"),_=new RegExp("\\("+S.source+"\\.\\."+S.source+"\\)"),R=new RegExp("\\(("+S.source+")\\.\\.("+S.source+")\\)"),q=new RegExp("(?:"+k.source+"|"+E.source+"|"+_.source+")"),O=new RegExp("(?:"+x.source+")\\s*:\\s*(?:"+q.source+")"),M=new RegExp("("+x.source+")\\s*:\\s*("+q.source+")","g"),L=new RegExp("^\\s*("+x.source+")\\s*([\\s\\S]*?)\\s*$"),P=new RegExp("^"+E.source+"$","i"),A=new RegExp("^"+k.source+"$"),U=new RegExp("^"+n.source+"$"),j=new RegExp("^"+b.source+"$","i"),F=new RegExp("^"+t.source+"$"),D=new RegExp("^"+R.source+"$"),H=new RegExp("^"+/-?\d+/.source+"$"),$=new RegExp("(?:"+x.source+"\\s*:\\s*)?"+q.source),C=new RegExp($.source+"(\\s*,\\s*"+$.source+")*"),N=new RegExp(x.source+"(?:\\s*:\\s*"+C.source+")?","g"),z=new RegExp("("+x.source+")(?:\\s*:\\s*("+C.source+"))?"),Y=new RegExp("^"+z.source+"$"),I=[/\s+or\s+/,/\s+and\s+/,/==|!=|<=|>=|<|>|\s+contains\s+/];var B=function(r){function t(t,e){var n=r.call(this,t.message)||this;return n.originalError=t,n.token=e,n}return e(t,r),t.prototype.update=function(){var i,o,t,s,e=this.originalError,n=(i=this.token,o=i.input.split("\n"),t=Math.max(i.line-2,1),s=Math.min(i.line+3,o.length),m(t,s+1).map(function(t){var e=t===i.line?">> ":" ",n=w(String(t),String(s).length),r=o[t-1];return""+e+n+"| "+r}).join("\n"));this.message=function(t,e){e.file&&(t+=", file:"+e.file);return t+=", line:"+e.line+", col:"+e.col}(e.message,this.token),this.stack=this.message+"\n"+n+"\n"+this.stack+"\nFrom "+e.stack},t}(Error),G=function(r){function t(t,e){var n=r.call(this,new Error(t),e)||this;return n.name="TokenizationError",r.prototype.update.call(n),n}return e(t,r),t}(B),V=function(r){function t(t,e){var n=r.call(this,t,e)||this;return n.name="ParseError",n.message=t.message,r.prototype.update.call(n),n}return e(t,r),t}(B),W=function(r){function t(t,e){var n=r.call(this,t,e.token)||this;return n.name="RenderError",n.message=t.message,r.prototype.update.call(n),n}return e(t,r),t}(B),J=function(n){function t(t){var e=n.call(this,t)||this;return e.resolvedHTML="",e.name="RenderBreakError",e.message=t+"",e}return e(t,n),t}(Error),X=function(n){function t(t){var e=n.call(this,t)||this;return e.name="AssertionError",e.message=t+"",e}return e(t,n),t}(Error);function K(t,e){if(!t)throw new X(e=e||"expect "+t+" to be true")}var Q,Z,tt={root:["."],cache:!1,extname:"",dynamicPartials:!0,trim_tag_right:!1,trim_tag_left:!1,trim_output_right:!1,trim_output_left:!1,greedy:!0,tag_delimiter_left:"{%",tag_delimiter_right:"%}",output_delimiter_left:"{{",output_delimiter_right:"}}",strict_filters:!1,strict_variables:!1};function et(t){var e;return(t=t||{}).hasOwnProperty("root")&&(t.root=f(e=t.root)?e:l(e)?[e]:[]),t}function nt(t){return v({},tt,t)}(Z=Q||(Q={}))[Z.OUTPUT=0]="OUTPUT",Z[Z.STORE=1]="STORE";var rt=Q,it=function(){function t(t,e){void 0===t&&(t={}),this.blocks={},this.groups={},this.blockMode=rt.OUTPUT,this.opts=nt(e),this.contexts=[t||{}]}return t.prototype.getAll=function(){return this.contexts.reduce(function(t,e){return v(t,e)},{})},t.prototype.get=function(t){var n=this,e=this.propertyAccessSeq(t),r=this.findContextFor(e[0])||p(this.contexts);return e.reduce(function(t,e){return n.readProperty(t,e)},r)},t.prototype.set=function(t,n){var r=this.propertyAccessSeq(t),i=this.findContextFor(r[0])||p(this.contexts);r.some(function(t,e){return!g(i)||(e===r.length-1?(i[t]=n,!0):(void 0===i[t]&&(i[t]={}),i=i[t],!1))})},t.prototype.unshift=function(t){return this.contexts.unshift(t)},t.prototype.push=function(t){return this.contexts.push(t)},t.prototype.pop=function(e){if(!arguments.length)return this.contexts.pop();var t=this.contexts.findIndex(function(t){return t===e});if(-1===t)throw new TypeError("scope not found, cannot pop");return this.contexts.splice(t,1)[0]},t.prototype.findContextFor=function(t,e){void 0===e&&(e=function(){return!0});for(var n=this.contexts.length-1;0<=n;n--){var r=this.contexts[n];if(e(r)&&t in r)return r}return null},t.prototype.readProperty=function(t,e){var n,r;if(u(t)?n=void 0:(t=function(t){if(s(t.to_liquid))return t.to_liquid();if(s(t.toLiquid))return t.toLiquid();return t}(t),n="size"===e?u((r=t).size)&&(f(r)||l(r))?r.length:r.size:t[e],s(t.liquid_method_missing)&&(n=t.liquid_method_missing(e))),u(n)&&this.opts.strict_variables)throw new TypeError("undefined variable: "+e);return n},t.prototype.propertyAccessSeq=function(t){t=String(t);for(var e,n,r=[],i="",o=0;o<t.length;)switch(t[o]){case"[":u();var s=t[o+1];o=/['"]/.test(s)?(K(-1!==(e=t.indexOf(s,o+2)),"unbalanced "+s+": "+t),i=t.slice(o+2,e),u(),e+2):(K(-1!==(e=ot(t,o+1)),"unbalanced []: "+t),i=t.slice(o+1,e),n=i,H.test(n)||(i=String(this.get(i))),u(),e+1);break;case".":u(),o++;break;default:i+=t[o],o++}if(u(),!r.length)throw new TypeError('invalid path:"'+t+'"');return r;function u(){i.length&&r.push(i),i=""}},t}();function ot(t,e){for(var n=1,r=e;r<t.length;r++)if("["===t[r]&&n++,"]"===t[r]&&0===--n)return r;return-1}var st=function(){},ut=function(){},at=function(){},ct=function(){},lt=Object.freeze({AssignScope:ut,CaptureScope:st,IncrementScope:at,DecrementScope:ct,ParseError:V,TokenizationError:G,RenderBreakError:J,AssertionError:X});var ft={readFile:function(r){return h(this,void 0,void 0,function(){return d(this,function(t){return[2,new Promise(function(t,e){var n=new XMLHttpRequest;n.onload=function(){200<=n.status&&n.status<300?t(n.responseText):e(new Error(n.statusText))},n.onerror=function(){e(new Error("An error occurred whilst receiving the response."))},n.open("GET",r),n.send()})]})})},resolve:function(t,e,i){return t.length&&"/"!==p(t)&&(t+="/"),function(t,e){var n=document.createElement("base");n.href=t;var r=document.getElementsByTagName("head")[0];r.insertBefore(n,r.firstChild);var i=document.createElement("a");i.href=e;var o=i.href;return r.removeChild(n),o}(t,e).replace(/^(\w+:\/\/[^/]+)(\/[^?]+)/,function(t,e,n){var r=n.split("/").pop();return/\.\w+$/.test(r)?t:e+n+i})},exists:function(){return h(this,void 0,void 0,function(){return d(this,function(t){return[2,!0]})})}};var pt,ht,dt=function(t,e,n,r,i){this.type="notset",this.col=r,this.line=n,this.raw=t,this.value=t,this.input=e,this.file=i},gt=function(s){function t(t,e,n,r,i){var o=s.call(this,t,e,n,r,i)||this;return o.type="html",o.value=t,o}return e(t,s),t}(dt),vt=function(u){function t(t,e,n,r,i,o){var s=u.call(this,t,n,r,i,o)||this;return s.trimLeft="-"===e[0],s.trimRight="-"===p(e),s.value=e.slice(s.trimLeft?1:0,s.trimRight?-1:e.length).trim(),s}return e(t,u),t}(dt),mt=function(a){function t(t,e,n,r,i,o){var s=a.call(this,t,e,n,r,i,o)||this;s.type="tag";var u=s.value.match(L);if(!u)throw new G("illegal tag syntax",s);return s.name=u[1],s.args=u[2],s}return e(t,a),t}(vt),wt=function(u){function t(t,e,n,r,i,o){var s=u.call(this,t,e,n,r,i,o)||this;return s.type="output",s}return e(t,u),t}(vt);(ht=pt||(pt={}))[ht.HTML=0]="HTML",ht[ht.OUTPUT=1]="OUTPUT",ht[ht.TAG=2]="TAG";var yt=function(){function t(t){this.options=nt(t)}return t.prototype.tokenize=function(t,e){for(var n=[],r=this.options.tag_delimiter_left,i=this.options.tag_delimiter_right,o=this.options.output_delimiter_left,s=this.options.output_delimiter_right,u=0,a=1,c=pt.HTML,l="",f=0,p=1,h=1;u<t.length;){if("\n"===t[u]&&(a++,f=u+1),c===pt.HTML){if(t.substr(u,o.length)===o){l&&n.push(new gt(l,t,p,h,e)),p=a,h=u-f+1,u+=(l=o).length,c=pt.OUTPUT;continue}if(t.substr(u,r.length)===r){l&&n.push(new gt(l,t,p,h,e)),p=a,h=u-f+1,u+=(l=r).length,c=pt.TAG;continue}}else{if(c===pt.OUTPUT&&t.substr(u,s.length)===s){l+=s,n.push(new wt(l,l.slice(o.length,-s.length),t,p,h,e)),l="",p=a,h=(u+=s.length)-f+1,c=pt.HTML;continue}if(t.substr(u,i.length)===i){l+=i,n.push(new mt(l,l.slice(r.length,-i.length),t,p,h,e)),l="",p=a,h=(u+=i.length)-f+1,c=pt.HTML;continue}}l+=t[u++]}if(c===pt.HTML)return l&&n.push(new gt(l,t,p,h,e)),function(s,u){u=v({greedy:!0},u);var a=!1;s.forEach(function(t,e){var n,r,i,o;i=t,o=u,!a&&("tag"===i.type?i.trimLeft||o.trim_tag_left:"output"===i.type?i.trimLeft||o.trim_output_left:void 0)&&function(t,e){if(t&&"html"===t.type){var n=e?/\s+$/g:/[\t\r ]*$/g;t.value=t.value.replace(n,"")}}(s[e-1],u.greedy),"tag"===t.type&&"raw"===t.name&&(a=!0),"tag"===t.type&&"endraw"===t.name&&(a=!1),n=t,r=u,!a&&("tag"===n.type?n.trimRight||r.trim_tag_right:"output"===n.type?n.trimRight||r.trim_output_right:void 0)&&function(t,e){if(t&&"html"===t.type){var n=e?/^\s+/g:/^[\t\r ]*\n?/g;t.value=t.value.replace(n,"")}}(s[e+1],u.greedy)})}(n,this.options),n;var d=c===pt.OUTPUT?"output":"tag",g=16<l.length?l.slice(0,13)+"...":l;throw new G(d+' "'+g+'" not closed',new dt(l,t,p,h,e))},t}(),bt=function(){function t(){}return t.prototype.renderTemplates=function(u,a){return h(this,void 0,void 0,function(){var e,n,r,i,o,s;return d(this,function(t){switch(t.label){case 0:K(a,"unable to evalTemplates: scope undefined"),e="",n=0,r=u,t.label=1;case 1:if(!(n<r.length))return[3,6];i=r[n],t.label=2;case 2:return t.trys.push([2,4,,5]),o=e,[4,i.render(a)];case 3:return e=o+t.sent(),[3,5];case 4:if("RenderBreakError"===(s=t.sent()).name)throw s.resolvedHTML=e,s;throw"RenderError"===s.name?s:new W(s,i);case 5:return n++,[3,1];case 6:return[2,e]}})})},t}(),xt={"==":function(t,e){return t===e},"!=":function(t,e){return t!==e},">":function(t,e){return null!==t&&null!==e&&e<t},"<":function(t,e){return null!==t&&null!==e&&t<e},">=":function(t,e){return null!==t&&null!==e&&e<=t},"<=":function(t,e){return null!==t&&null!==e&&t<=e},contains:function(t,e){return!!t&&("function"==typeof t.indexOf&&-1<t.indexOf(e))},and:function(t,e){return kt(t)&&kt(e)},or:function(t,e){return kt(t)||kt(e)}};function Tt(t,e){K(e,"unable to evalExp: scope undefined");for(var n,r=I,i=0;i<r.length;i++){var o=r[i],s=new RegExp("^("+y.source+")("+o.source+")("+y.source+")$");if(n=t.match(s)){var u=Tt(n[1],e);return(0,xt[n[2].trim()])(u,Tt(n[3],e))}}return(n=t.match(D))?m(Et(n[1],e),Et(n[2],e)+1):Et(t,e)}function Et(t,e){if(t=t&&t.trim()){if(n=t,P.test(n))return function(t){var e=t.match(U);if(e)return Number(t);if(e=t.match(j))return"true"===t.toLowerCase();if(e=t.match(F))return t.slice(1,-1);throw new TypeError("cannot parse '"+t+"' as literal")}(t);var n,r;if(r=t,A.test(r))return e.get(t);throw new TypeError("cannot eval '"+t+"' as value")}}function kt(t){return!St(t)}function St(t){return!1===t||null==t}var _t=function(t,e){var n;for(M.lastIndex=0;n=M.exec(t);){var r=n[1],i=n[2];this[r]=Et(i,e)}},Rt=function(t){this.token=t},qt=function(s){function u(t,e,n){var r=s.call(this,t)||this;r.name=t.name;var i,o=u.impls[t.name];return K(o,"tag "+t.name+" not found"),r.impl=(i=o,Object.create(i)),r.impl.liquid=n,r.impl.parse&&r.impl.parse(t,e),r}return e(u,s),u.prototype.render=function(r){return h(this,void 0,void 0,function(){var e,n;return d(this,function(t){switch(t.label){case 0:return e=new _t(this.token.args,r),"function"!=typeof(n=this.impl).render?[2,""]:[4,n.render(r,e)];case 1:return[2,a(t.sent())]}})})},u.register=function(t,e){u.impls[t]=e},u.clear=function(){u.impls={}},u.impls={},u}(Rt),Ot=new RegExp(""+q.source,"g"),Mt=function(){function s(t,e){void 0===e&&(e=!1);var n=Y.exec(t);K(n,"illegal filter: "+t);var r=n[1],i=n[2]||"",o=s.impls[r];if(!o&&e)throw new TypeError("undefined filter: "+r);this.name=r,this.impl=o||function(t){return t},this.args=this.parseArgs(i)}return s.prototype.parseArgs=function(t){for(var e,n=[];e=Ot.exec(t.trim());){var r=e[0],i=new RegExp(r+"\\s*:","g").exec(e.input);i&&i.index===e.index?n.push("'"+r+"'"):n.push(r)}return n},s.prototype.render=function(t,e){var n=this.args.map(function(t){return Et(t,e)});return this.impl.apply(null,[t].concat(n))},s.register=function(t,e){s.impls[t]=e},s.clear=function(){s.impls={}},s.impls={},s}(),Lt=function(){function t(t,e){this.handlers={},this.stopRequested=!1,this.tokens=t,this.parseToken=e}return t.prototype.on=function(t,e){return this.handlers[t]=e,this},t.prototype.trigger=function(t,e){var n=this.handlers[t];return"function"==typeof n&&(n(e),!0)},t.prototype.start=function(){var t;for(this.trigger("start");!this.stopRequested&&(t=this.tokens.shift());)if(!(this.trigger("token",t)||"tag"===t.type&&this.trigger("tag:"+t.name,t))){var e=this.parseToken(t,this.tokens);this.trigger("template",e)}return this.stopRequested||this.trigger("end"),this},t.prototype.stop=function(){return this.stopRequested=!0,this},t}(),Pt=function(){function t(t,e){this.filters=[];var n,r=(n=t,q.exec(n));for(K(r,"illegal value string: "+t),this.initial=r[0],t=t.substr(r.index+r[0].length);r=N.exec(t);)this.filters.push(new Mt(r[0].trim(),e))}return t.prototype.value=function(n){return this.filters.reduce(function(t,e){return e.render(t,n)},Tt(this.initial,n))},t}(),At=function(r){function t(t,e){var n=r.call(this,t)||this;return n.value=new Pt(t.value,e),n}return e(t,r),t.prototype.render=function(e){return h(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.value.value(e)];case 1:return[2,a(t.sent())]}})})},t}(Rt),Ut=function(n){function t(t){var e=n.call(this,t)||this;return e.str=t.value,e}return e(t,n),t.prototype.render=function(){return h(this,void 0,void 0,function(){return d(this,function(t){return[2,this.str]})})},t}(Rt),jt=function(){function t(t){this.liquid=t}return t.prototype.parse=function(t){for(var e,n=[];e=t.shift();)n.push(this.parseToken(e,t));return n},t.prototype.parseToken=function(e,t){try{return"tag"===e.type?new qt(e,t,this.liquid):"output"===e.type?new At(e,this.liquid.options.strict_filters):new Ut(e)}catch(t){throw new V(t,e)}},t.prototype.parseStream=function(t){var n=this;return new Lt(t,function(t,e){return n.parseToken(t,e)})},t}(),Ft=new RegExp("("+x.source+")\\s*=([^]*)"),Dt={parse:function(t){var e=t.args.match(Ft);K(e,"illegal token "+t.raw),this.key=e[1],this.value=e[2]},render:function(t){var e=new ut;return e[this.key]=this.liquid.evalValue(this.value,t),t.push(e),Promise.resolve("")}};function Ht(n,r){var i=Promise.resolve(0),o=[];return n.forEach(function(t,e){i=i.then(function(){return r(t,e,n)}).then(function(t){return o.push(t)})}),i.then(function(){return o})}var $t=new RegExp("^("+x.source+")\\s+in\\s+("+q.source+")(?:\\s+"+O.source+")*(?:\\s+(reversed))?(?:\\s+"+O.source+")*$"),Ct={type:"block",parse:function(t,e){var n,r=this,i=$t.exec(t.args);K(i,"illegal tag: "+t.raw),this.variable=i[1],this.collection=i[2],this.reversed=!!i[3],this.templates=[],this.elseTemplates=[];var o=this.liquid.parser.parseStream(e).on("start",function(){return n=r.templates}).on("tag:else",function(){return n=r.elseTemplates}).on("tag:endfor",function(){return o.stop()}).on("template",function(t){return n.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});o.start()},render:function(a,c){return h(this,void 0,void 0,function(){var r,e,n,i,o,s,u=this;return d(this,function(t){switch(t.label){case 0:return f(r=Tt(this.collection,a))||(l(r)&&0<r.length?r=[r]:g(r)&&(r=Object.keys(r).map(function(t){return[t,r[t]]}))),f(r)&&r.length?(e=c.offset||0,n=void 0===c.limit?r.length:c.limit,r=r.slice(e,e+n),this.reversed&&r.reverse(),i=r.map(function(t,e){var n={};return n[u.variable]=t,n.forloop={first:0===e,index:e+1,index0:e,last:e===r.length-1,length:r.length,rindex:r.length-e,rindex0:r.length-e-1},n}),o="",s=!1,[4,Ht(i,function(r){return h(u,void 0,void 0,function(){var e,n;return d(this,function(t){switch(t.label){case 0:if(s)return[2];a.push(r),t.label=1;case 1:return t.trys.push([1,3,,4]),e=o,[4,this.liquid.renderer.renderTemplates(this.templates,a)];case 2:return o=e+t.sent(),[3,4];case 3:if("RenderBreakError"!==(n=t.sent()).name)throw n;return o+=n.resolvedHTML,"break"===n.message&&(s=!0),[3,4];case 4:return a.pop(r),[2]}})})})]):[2,this.liquid.renderer.renderTemplates(this.elseTemplates,a)];case 1:return t.sent(),[2,o]}})})}},Nt=new RegExp("("+x.source+")"),zt={parse:function(t,e){var n=this,r=t.args.match(Nt);K(r,t.args+" not valid identifier"),this.variable=r[1],this.templates=[];var i=this.liquid.parser.parseStream(e);i.on("tag:endcapture",function(){return i.stop()}).on("template",function(t){return n.templates.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")}),i.start()},render:function(r){return h(this,void 0,void 0,function(){var e,n;return d(this,function(t){switch(t.label){case 0:return[4,this.liquid.renderer.renderTemplates(this.templates,r)];case 1:return e=t.sent(),(n=new st)[this.variable]=e,r.push(n),[2]}})})}},Yt={parse:function(t,e){var n=this;this.cond=t.args,this.cases=[],this.elseTemplates=[];var r=[],i=this.liquid.parser.parseStream(e).on("tag:when",function(t){n.cases.push({val:t.args,templates:r=[]})}).on("tag:else",function(){return r=n.elseTemplates}).on("tag:endcase",function(){return i.stop()}).on("template",function(t){return r.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});i.start()},render:function(t){for(var e=0;e<this.cases.length;e++){var n=this.cases[e];if(Tt(n.val,t)===Tt(this.cond,t))return this.liquid.renderer.renderTemplates(n.templates,t)}return this.liquid.renderer.renderTemplates(this.elseTemplates,t)}},It={parse:function(t,e){var n=this.liquid.parser.parseStream(e);n.on("token",function(t){"endcomment"===t.name&&n.stop()}).on("end",function(){throw new Error("tag "+t.raw+" not closed")}),n.start()}},Bt=/[^\s,]+/,Gt=new RegExp("with\\s+("+q.source+")"),Vt={parse:function(t){var e=Bt.exec(t.args);e&&(this.staticValue=e[0]),(e=q.exec(t.args))&&(this.value=e[0]),(e=Gt.exec(t.args))&&(this.with=e[1])},render:function(u,a){return h(this,void 0,void 0,function(){var e,n,r,i,o,s;return d(this,function(t){switch(t.label){case 0:return u.opts.dynamicPartials?F.exec(this.value)?(n=this.value.slice(1,-1),[4,this.liquid.parseAndRender(n,u.getAll(),u.opts)]):[3,2]:[3,4];case 1:return e=t.sent(),[3,3];case 2:e=Et(this.value,u),t.label=3;case 3:return[3,5];case 4:e=this.staticValue,t.label=5;case 5:return K(e,"cannot include with empty filename"),r=u.blocks,i=u.blockMode,u.blocks={},u.blockMode=rt.OUTPUT,this.with&&(a[e]=Et(this.with,u)),[4,this.liquid.getTemplate(e,u.opts)];case 6:return o=t.sent(),u.push(a),[4,this.liquid.renderer.renderTemplates(o,u)];case 7:return s=t.sent(),u.pop(a),u.blocks=r,u.blockMode=i,[2,s]}})})}},Wt={parse:function(t){var e=t.args.match(x);K(e,"illegal identifier "+t.args),this.variable=e[0]},render:function(t){var e=t.findContextFor(this.variable,function(t){return!(t instanceof st||t instanceof ut)});return e||(e=new ct,t.unshift(e)),"number"!=typeof e[this.variable]&&(e[this.variable]=0),--e[this.variable]}},Jt=new RegExp("^(?:("+q.source+")\\s*:\\s*)?(.*)$"),Xt=new RegExp(q.source,"g"),Kt={parse:function(t){var e=Jt.exec(t.args);K(e,"illegal tag: "+t.raw),this.group=e[1]||"";var n=e[2];for(this.candidates=[];e=Xt.exec(n);)this.candidates.push(e[0]);K(this.candidates.length,"empty candidates: "+t.raw)},render:function(t){var e="cycle:"+Et(this.group,t)+":"+this.candidates.join(","),n=t.groups,r=n[e];void 0===r&&(r=n[e]=0);var i=this.candidates[r];return r=(r+1)%this.candidates.length,n[e]=r,Et(i,t)}},Qt={parse:function(t,e){var n,r=this;this.branches=[],this.elseTemplates=[];var i=this.liquid.parser.parseStream(e).on("start",function(){return r.branches.push({cond:t.args,templates:n=[]})}).on("tag:elsif",function(t){r.branches.push({cond:t.args,templates:n=[]})}).on("tag:else",function(){return n=r.elseTemplates}).on("tag:endif",function(){return i.stop()}).on("template",function(t){return n.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});i.start()},render:function(t){for(var e=0,n=this.branches;e<n.length;e++){var r=n[e];if(kt(Tt(r.cond,t)))return this.liquid.renderer.renderTemplates(r.templates,t)}return this.liquid.renderer.renderTemplates(this.elseTemplates,t)}},Zt={parse:function(t){var e=t.args.match(x);K(e,"illegal identifier "+t.args),this.variable=e[0]},render:function(t){var e=t.findContextFor(this.variable,function(t){return!(t instanceof st||t instanceof ut)});e||(e=new at,t.unshift(e)),"number"!=typeof e[this.variable]&&(e[this.variable]=0);var n=e[this.variable];return e[this.variable]++,n}},te=/\S+/,ee={parse:function(t,e){var n=te.exec(t.args);n&&(this.staticLayout=n[0]),(n=q.exec(t.args))&&(this.layout=n[0]),this.tpls=this.liquid.parser.parse(e)},render:function(o,s){return h(this,void 0,void 0,function(){var e,n,r,i;return d(this,function(t){switch(t.label){case 0:return K(e=o.opts.dynamicPartials?Et(this.layout,o):this.staticLayout,"cannot apply layout with empty filename"),o.blockMode=rt.STORE,[4,this.liquid.renderer.renderTemplates(this.tpls,o)];case 1:return n=t.sent(),void 0===o.blocks[""]&&(o.blocks[""]=n),[4,this.liquid.getTemplate(e,o.opts)];case 2:return r=t.sent(),o.push(s),o.blockMode=rt.OUTPUT,[4,this.liquid.renderer.renderTemplates(r,o)];case 3:return i=t.sent(),o.pop(s),[2,i]}})})}},ne={parse:function(t,e){var n=this,r=/\w+/.exec(t.args);this.block=r?r[0]:"",this.tpls=[];var i=this.liquid.parser.parseStream(e).on("tag:endblock",function(){return i.stop()}).on("template",function(t){return n.tpls.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});i.start()},render:function(i){return h(this,void 0,void 0,function(){var e,n,r;return d(this,function(t){switch(t.label){case 0:return void 0===(e=i.blocks[this.block])?[3,1]:(r=e,[3,3]);case 1:return[4,this.liquid.renderer.renderTemplates(this.tpls,i)];case 2:r=t.sent(),t.label=3;case 3:return n=r,i.blockMode===rt.STORE?(i.blocks[this.block]=n,[2,""]):[2,n]}})})}},re={parse:function(t,e){var n=this;this.tokens=[];var r=this.liquid.parser.parseStream(e);r.on("token",function(t){"endraw"===t.name?r.stop():n.tokens.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")}),r.start()},render:function(){return this.tokens.map(function(t){return t.raw}).join("")}},ie=new RegExp("^("+x.source+")\\s+in\\s+("+q.source+")(?:\\s+"+O.source+")*$"),oe={assign:Dt,for:Ct,capture:zt,case:Yt,comment:It,include:Vt,decrement:Wt,increment:Zt,cycle:Kt,if:Qt,layout:ee,block:ne,raw:re,tablerow:{parse:function(t,e){var n,r=this,i=ie.exec(t.args);K(i,"illegal tag: "+t.raw),this.variable=i[1],this.collection=i[2],this.templates=[];var o=this.liquid.parser.parseStream(e).on("start",function(){return n=r.templates}).on("tag:endtablerow",function(){return o.stop()}).on("template",function(t){return n.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});o.start()},render:function(c,l){return h(this,void 0,void 0,function(){var e,n,r,o,i,s,u,a=this;return d(this,function(t){switch(t.label){case 0:return e=Tt(this.collection,c)||[],n=l.offset||0,r=void 0===l.limit?e.length:l.limit,e=e.slice(n,n+r),o=l.cols||e.length,i=e.map(function(t){var e={};return e[a.variable]=t,e}),s=0,u="",[4,Ht(i,function(r,i){return h(a,void 0,void 0,function(){var e,n;return d(this,function(t){switch(t.label){case 0:return s=Math.floor(i/o)+1,1===(e=i%o+1)&&(1!==s&&(u+="</tr>"),u+='<tr class="row'+s+'">'),u+='<td class="col'+e+'">',c.push(r),n=u,[4,this.liquid.renderer.renderTemplates(this.templates,c)];case 1:return u=n+t.sent(),u+="</td>",c.pop(r),[2,u]}})})})];case 1:return t.sent(),0<s&&(u+="</tr>"),[2,u]}})})}},unless:{parse:function(t,e){var n,r=this;this.templates=[],this.elseTemplates=[];var i=this.liquid.parser.parseStream(e).on("start",function(){n=r.templates,r.cond=t.args}).on("tag:else",function(){return n=r.elseTemplates}).on("tag:endunless",function(){return i.stop()}).on("template",function(t){return n.push(t)}).on("end",function(){throw new Error("tag "+t.raw+" not closed")});i.start()},render:function(t){return St(Tt(this.cond,t))?this.liquid.renderer.renderTemplates(this.templates,t):this.liquid.renderer.renderTemplates(this.elseTemplates,t)}},break:{render:function(){return h(this,void 0,void 0,function(){return d(this,function(t){throw new J("break")})})}},continue:{render:function(){return h(this,void 0,void 0,function(){return d(this,function(t){throw new J("continue")})})}}},se={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&#34;","'":"&#39;"},ue={"&amp;":"&","&lt;":"<","&gt;":">","&#34;":'"',"&#39;":"'"};function ae(t){return String(t).replace(/&|<|>|"|'/g,function(t){return se[t]})}var ce={escape:ae,escape_once:function(t){return ae(String(t).replace(/&(amp|lt|gt|#34|#39);/g,function(t){return ue[t]}))},newline_to_br:function(t){return t.replace(/\n/g,"<br />")},strip_html:function(t){return t.replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g,"")}},le={append:function(t,e){return t+e},prepend:function(t,e){return e+t},capitalize:function(t){return String(t).charAt(0).toUpperCase()+t.slice(1)},lstrip:function(t){return String(t).replace(/^\s+/,"")},downcase:function(t){return t.toLowerCase()},upcase:function(t){return String(t).toUpperCase()},remove:function(t,e){return t.split(e).join("")},remove_first:function(t,e){return t.replace(e,"")},replace:function(t,e,n){return String(t).split(e).join(n)},replace_first:function(t,e,n){return String(t).replace(e,n)},rstrip:function(t){return String(t).replace(/\s+$/,"")},split:function(t,e){return String(t).split(e)},strip:function(t){return String(t).trim()},strip_newlines:function(t){return String(t).replace(/\n/g,"")},truncate:function(t,e,n){return void 0===e&&(e=50),void 0===n&&(n="..."),(t=String(t)).length<=e?t:t.substr(0,e-n.length)+n},truncatewords:function(t,e,n){void 0===e&&(e=15),void 0===n&&(n="...");var r=t.split(/\s+/),i=r.slice(0,e).join(" ");return r.length>=e&&(i+=n),i}},fe={abs:function(t){return Math.abs(t)},ceil:function(t){return Math.ceil(t)},divided_by:function(t,e){return t/e},floor:function(t){return Math.floor(t)},minus:he(function(t,e){return t-e}),modulo:he(function(t,e){return t%e}),round:function(t,e){void 0===e&&(e=0);var n=Math.pow(10,e);return Math.round(t*n)/n},plus:he(function(t,e){return Number(t)+Number(e)}),times:function(t,e){return t*e}};function pe(t){var e=String(t).split(".");return 1<e.length?e[1].length:0}function he(r){return function(t,e){var n=Math.max(pe(t),pe(e));return r(t,e).toFixed(n)}}var de={url_decode:function(t){return t.split("+").map(decodeURIComponent).join(" ")},url_encode:function(t){return t.split(" ").map(encodeURIComponent).join("+")}},ge={join:function(t,e){return t.join(void 0===e?" ":e)},last:function(t){return p(t)},first:function(t){return t[0]},map:function(t,e){return t.map(function(t){return t[e]})},reverse:function(t){return t.reverse()},sort:function(t,e){return t.sort(e)},size:function(t){return t.length},concat:function(t,e){return Array.prototype.concat.call(t,e)},slice:function(t,e,n){return void 0===n&&(n=1),t.slice(e,e+n)},uniq:function(t){var e={};return(t||[]).filter(function(t){return!e.hasOwnProperty(String(t))&&(e[String(t)]=!0)})}},ve=["January","February","March","April","May","June","July","August","September","October","November","December"],me=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],we=ve.map(xe),ye=me.map(xe),be={1:"st",2:"nd",3:"rd",default:"th"};function xe(t){return t.slice(0,3)}var Te={daysInMonth:function(t){return[31,Te.isLeapYear(t)?29:28,31,30,31,30,31,31,30,31,30,31]},getDayOfYear:function(t){for(var e=0,n=0;n<t.getMonth();++n)e+=Te.daysInMonth(t)[n];return e+t.getDate()},getWeekOfYear:function(t,e){var n=this.getDayOfYear(t)+(e-t.getDay()),r=7-new Date(t.getFullYear(),0,1).getDay()+e;return w(String(Math.floor((n-r)/7)+1),2,"0")},isLeapYear:function(t){var e=t.getFullYear();return!(0!=(3&e)||!(e%100||e%400==0&&e))},getSuffix:function(t){var e=t.getDate().toString(),n=parseInt(e.slice(-1));return be[n]||be.default},century:function(t){return parseInt(t.getFullYear().toString().substring(0,2),10)}},Ee={a:function(t){return ye[t.getDay()]},A:function(t){return me[t.getDay()]},b:function(t){return we[t.getMonth()]},B:function(t){return ve[t.getMonth()]},c:function(t){return t.toLocaleString()},C:function(t){return Te.century(t)},d:function(t){return w(t.getDate(),2,"0")},e:function(t){return w(t.getDate(),2)},H:function(t){return w(t.getHours(),2,"0")},I:function(t){return w(String(t.getHours()%12||12),2,"0")},j:function(t){return w(Te.getDayOfYear(t),3,"0")},k:function(t){return w(t.getHours(),2)},l:function(t){return w(String(t.getHours()%12||12),2)},L:function(t){return w(t.getMilliseconds(),3,"0")},m:function(t){return w(t.getMonth()+1,2,"0")},M:function(t){return w(t.getMinutes(),2,"0")},p:function(t){return t.getHours()<12?"AM":"PM"},P:function(t){return t.getHours()<12?"am":"pm"},q:function(t){return Te.getSuffix(t)},s:function(t){return Math.round(t.valueOf()/1e3)},S:function(t){return w(t.getSeconds(),2,"0")},u:function(t){return t.getDay()||7},U:function(t){return Te.getWeekOfYear(t,0)},w:function(t){return t.getDay()},W:function(t){return Te.getWeekOfYear(t,1)},x:function(t){return t.toLocaleDateString()},X:function(t){return t.toLocaleTimeString()},y:function(t){return t.getFullYear().toString().substring(2,4)},Y:function(t){return t.getFullYear()},z:function(t){var e=t.getTimezoneOffset()/60*100;return(0<e?"-":"+")+w(String(Math.abs(e)),4,"0")},"%":function(){return"%"}};Ee.h=Ee.b,Ee.N=Ee.L;var ke=v({},ce,le,fe,de,{date:function(t,e){var n,r=t;return"now"===t?r=new Date:l(t)&&(r=new Date(t)),(n=r)instanceof Date&&!isNaN(n.getTime())?function(t,e){for(var n="",r=e;;){var i=/%./g,o=i.exec(r);if(!o)return n+r;n+=r.slice(0,i.lastIndex-2),r=r.slice(i.lastIndex);var s=o[0].charAt(1),u=Ee[s];n+=u?u(t):"%"+s}}(r,e):t}},{default:function(t,e){return kt(t)?t:e}},ge);return function(){function e(t){void 0===t&&(t={});var n=this;this.cache={},this.options=nt(et(t)),this.parser=new jt(this),this.renderer=new bt,this.tokenizer=new yt(this.options),c(oe,function(t,e){return n.registerTag(e,t)}),c(ke,function(t,e){return n.registerFilter(e,t)})}return e.prototype.parse=function(t,e){var n=this.tokenizer.tokenize(t,e);return this.parser.parse(n)},e.prototype.render=function(t,e,n){var r=v({},this.options,et(n)),i=new it(e,r);return this.renderer.renderTemplates(t,i)},e.prototype.parseAndRender=function(n,r,i){return h(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return[4,this.parse(n)];case 1:return e=t.sent(),[2,this.render(e,r,i)]}})})},e.prototype.getTemplate=function(f,p){return h(this,void 0,void 0,function(){var e,n,r,i,o,s,u,a,c,l=this;return d(this,function(t){switch(t.label){case 0:e=et(p),n=e.root?e.root.concat(this.options.root):this.options.root,r=n.map(function(t){return ft.resolve(t,f,l.options.extname)}),i=0,o=r,t.label=1;case 1:return i<o.length?(s=o[i],[4,ft.exists(s)]):[3,5];case 2:return t.sent()?this.options.cache&&this.cache[s]?[2,this.cache[s]]:(a=this.parse,[4,ft.readFile(s)]):[3,4];case 3:return u=a.apply(this,[t.sent(),s]),this.options.cache&&(this.cache[s]=u),[2,u];case 4:return i++,[3,1];case 5:throw(c=new Error("ENOENT")).message='ENOENT: Failed to lookup "'+f+'" in "'+n+'"',c.code="ENOENT",c}})})},e.prototype.renderFile=function(r,i,o){return h(this,void 0,void 0,function(){var e,n;return d(this,function(t){switch(t.label){case 0:return e=et(o),[4,this.getTemplate(r,e)];case 1:return n=t.sent(),[2,this.render(n,i,o)]}})})},e.prototype.evalValue=function(t,e){return new Pt(t,this.options.strict_filters).value(e)},e.prototype.registerFilter=function(t,e){return Mt.register(t,e)},e.prototype.registerTag=function(t,e){return qt.register(t,e)},e.prototype.plugin=function(t){return t.call(this,e)},e.prototype.express=function(){var i=this;return function(t,e,n){var r={root:this.root};i.renderFile(t,e,r).then(function(t){return n(null,t)},n)}},(e.default=e).isTruthy=kt,e.isFalsy=St,e.evalExp=Tt,e.evalValue=Et,e.Types=lt,e}()});
//# sourceMappingURL=liquid.min.js.map