diff --git a/README.md b/README.md index 485912a16..d61c3c347 100644 --- a/README.md +++ b/README.md @@ -74,14 +74,19 @@ engine.parseAndRender("{{ foo }}", {}, opts).catch(function(err){ engine.parseAndRender("{{ 'foo' | filter1 }}", {}, opts).catch(function(err){ // err.message === undefined filter: filter1 }); -// Note: -// `engine.render(tpl, ctx, opts)` and `engine.renderFile(path, ctx, opts)` also works. +// Note: the below opts also work: +// engine.render(tpl, ctx, opts) +// engine.renderFile(path, ctx, opts) ``` ## Use with Express.js ```javascript -app.engine('liquid', engine.express()); // register liquid engine +// register liquid engine +app.engine('liquid', engine.express({ + strict_variables: true, // Default: fasle + strict_filters: true // Default: false +})); app.set('views', './views'); // specify the views directory app.set('view engine', 'liquid'); // set to default ``` diff --git a/dist/shopify-liquid.js b/dist/shopify-liquid.js index 050b7dda1..1cddf996c 100644 --- a/dist/shopify-liquid.js +++ b/dist/shopify-liquid.js @@ -289,11 +289,11 @@ var _engine = { }); }); }, - express: function express() { + express: function express(renderingOptions) { var _this3 = this; return function (filePath, options, callback) { - _this3.renderFile(filePath, options).then(function (html) { + _this3.renderFile(filePath, options, renderingOptions).then(function (html) { return callback(null, html); }).catch(function (e) { return callback(e); diff --git a/dist/shopify-liquid.min.js b/dist/shopify-liquid.min.js index 7d3117b52..ac6ad0a23 100644 --- a/dist/shopify-liquid.min.js +++ b/dist/shopify-liquid.min.js @@ -1,4 +1,4 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Liquid=f()}})(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o":">",'"':""","'":"'"};function escape(str){return(str||"").replace(/&|<|>|"|'/g,function(m){return escapeMap[m]})}liquid.registerFilter("escape",escape);var unescapeMap={"&":"&","<":"<",">":">",""":'"',"'":"'"};function unescape(str){return(str||"").replace(/&(amp|lt|gt|#34|#39);/g,function(m){return unescapeMap[m]})}liquid.registerFilter("escape_once",function(str){return escape(unescape(str))});liquid.registerFilter("first",function(v){return v[0]});liquid.registerFilter("floor",function(v){return Math.floor(v)});liquid.registerFilter("join",function(v,arg){return v.join(arg)});liquid.registerFilter("last",function(v){return v[v.length-1]});liquid.registerFilter("lstrip",function(v){return(v||"").replace(/^\s+/,"")});liquid.registerFilter("map",function(arr,arg){return arr.map(function(v){return v[arg]})});liquid.registerFilter("minus",bindFixed(function(v,arg){return v-arg}));liquid.registerFilter("modulo",bindFixed(function(v,arg){return v%arg}));liquid.registerFilter("newline_to_br",function(v){return v.replace(/\n/g,"
")});liquid.registerFilter("plus",bindFixed(function(v,arg){return v+arg}));liquid.registerFilter("prepend",function(v,arg){return arg+v});liquid.registerFilter("remove",function(v,arg){return v.split(arg).join("")});liquid.registerFilter("remove_first",function(v,l){return v.replace(l,"")});liquid.registerFilter("replace",function(v,pattern,replacement){return(v||"").split(pattern).join(replacement)});liquid.registerFilter("replace_first",function(v,arg1,arg2){return(v||"").replace(arg1,arg2)});liquid.registerFilter("reverse",function(v){return(v||"").reverse()});liquid.registerFilter("round",function(v,arg){var amp=Math.pow(10,arg||0);return Math.round(v*amp,arg)/amp});liquid.registerFilter("rstrip",function(str){return(str||"").replace(/\s+$/,"")});liquid.registerFilter("size",function(v){return v.length});liquid.registerFilter("slice",function(v,begin,length){return v.substr(begin,length===undefined?1:length)});liquid.registerFilter("sort",function(v,arg){return(v||"").sort(arg)});liquid.registerFilter("split",function(v,arg){return(v||"").split(arg)});liquid.registerFilter("strip",function(v){return(v||"").trim()});liquid.registerFilter("strip_html",function(v){return(v||"").replace(/<\/?\s*\w+\s*\/?>/g,"")});liquid.registerFilter("strip_newlines",function(v){return(v||"").replace(/\n/g,"")});liquid.registerFilter("times",function(v,arg){return v*arg});liquid.registerFilter("truncate",function(v,l,o){v=v||"";o=o===undefined?"...":o;l=l||16;if(v.length<=l)return v;return v.substr(0,l-o.length)+o});liquid.registerFilter("truncatewords",function(v,l,o){if(o===undefined)o="...";var arr=v.split(" ");var ret=arr.slice(0,l).join(" ");if(arr.length>l)ret+=o;return ret});liquid.registerFilter("uniq",function(arr){var u={};return(arr||[]).filter(function(val){if(u.hasOwnProperty(val)){return false}u[val]=true;return true})});liquid.registerFilter("upcase",function(str){return(str||"").toUpperCase()});liquid.registerFilter("url_encode",encodeURIComponent)};function getFixed(v){var p=(v+"").split(".");return p.length>1?p[1].length:0}function getMaxFixed(l,r){return Math.max(getFixed(l),getFixed(r))}function bindFixed(cb){return function(l,r){var f=getMaxFixed(l,r);return cb(l,r).toFixed(f)}}},{strftime:10}],2:[function(require,module,exports){"use strict";var Scope=require("./src/scope");var assert=require("assert");var tokenizer=require("./src/tokenizer.js");var Render=require("./src/render.js");var lexical=require("./src/lexical.js");var path=require("path");var fs=require("fs");var Tag=require("./src/tag.js");var Filter=require("./src/filter.js");var Template=require("./src/parser");var Expression=require("./src/expression.js");var tags=require("./tags");var filters=require("./filters");var Promise=require("any-promise");var _engine={init:function init(tag,filter,options){if(options.cache){this.cache={}}this.options=options;this.tag=tag;this.filter=filter;this.parser=Template(tag,filter);this.renderer=Render();tags(this);filters(this);return this},parse:function parse(html){var tokens=tokenizer.parse(html);return this.parser.parse(tokens)},render:function render(tpl,ctx,opts){opts=opts||{};opts.strict_variables=opts.strict_variables||false;opts.strict_filters=opts.strict_filters||false;this.renderer.resetRegisters();var scope=Scope.factory(ctx,{strict:opts.strict_variables});return this.renderer.renderTemplates(tpl,scope,opts)},parseAndRender:function parseAndRender(html,ctx,opts){try{var tpl=this.parse(html);return this.render(tpl,ctx,opts)}catch(error){return Promise.reject(error)}},renderFile:function renderFile(filepath,ctx,opts){var _this=this;return this.handleCache(filepath).then(function(templates){return _this.render(templates,ctx,opts)}).catch(function(e){e.file=filepath;throw e})},evalOutput:function evalOutput(str,scope){var tpl=this.parser.parseOutput(str.trim());return this.renderer.evalOutput(tpl,scope)},registerFilter:function registerFilter(name,filter){return this.filter.register(name,filter)},registerTag:function registerTag(name,tag){return this.tag.register(name,tag)},handleCache:function handleCache(filepath){var _this2=this;assert(filepath,"filepath cannot be null");filepath=path.resolve(this.options.root,filepath);if(path.extname(filepath)===""){filepath+=this.options.extname}return this.getTemplate(filepath).then(function(html){var tpl=_this2.options.cache&&_this2.cache[filepath]||_this2.parse(html);return _this2.options.cache?_this2.cache[filepath]=tpl:tpl})},getTemplate:function getTemplate(filepath){return new Promise(function(resolve,reject){fs.readFile(filepath,"utf8",function(err,html){err?reject(err):resolve(html)})})},express:function express(){var _this3=this;return function(filePath,options,callback){_this3.renderFile(filePath,options).then(function(html){return callback(null,html)}).catch(function(e){return callback(e)})}}};function factory(options){options=options||{};options.root=options.root||"";options.extname=options.extname||".liquid";var engine=Object.create(_engine);engine.init(Tag(),Filter(),options);return engine}factory.lexical=lexical;factory.isTruthy=Expression.isTruthy;factory.isFalsy=Expression.isFalsy;factory.evalExp=Expression.evalExp;factory.evalValue=Expression.evalValue;module.exports=factory},{"./filters":1,"./src/expression.js":15,"./src/filter.js":16,"./src/lexical.js":17,"./src/parser":18,"./src/render.js":19,"./src/scope":20,"./src/tag.js":22,"./src/tokenizer.js":23,"./tags":34,"any-promise":3,assert:6,fs:7,path:8}],3:[function(require,module,exports){"use strict";module.exports=require("./register")().Promise},{"./register":5}],4:[function(require,module,exports){"use strict";var REGISTRATION_KEY="@@any-promise/REGISTRATION",registered=null;module.exports=function(root,loadImplementation){return function register(implementation,opts){implementation=implementation||null;opts=opts||{};var registerGlobal=opts.global!==false;if(registered===null&®isterGlobal){registered=root[REGISTRATION_KEY]||null}if(registered!==null&&implementation!==null&®istered.implementation!==implementation){throw new Error('any-promise already defined as "'+registered.implementation+'". You can only register an implementation before the first '+' call to require("any-promise") and an implementation cannot be changed')}if(registered===null){if(implementation!==null&&typeof opts.Promise!=="undefined"){registered={Promise:opts.Promise,implementation:implementation}}else{registered=loadImplementation(implementation)}if(registerGlobal){root[REGISTRATION_KEY]=registered}}return registered}}},{}],5:[function(require,module,exports){"use strict";module.exports=require("./loader")(window,loadImplementation);function loadImplementation(){if(typeof window.Promise==="undefined"){throw new Error("any-promise browser requires a polyfill or explicit registration"+" e.g: require('any-promise/register/bluebird')")}return{Promise:window.Promise,implementation:"window.Promise"}}},{"./loader":4}],6:[function(require,module,exports){"use strict";var util=require("util/");var pSlice=Array.prototype.slice;var hasOwn=Object.prototype.hasOwnProperty;var assert=module.exports=ok;assert.AssertionError=function AssertionError(options){this.name="AssertionError";this.actual=options.actual;this.expected=options.expected;this.operator=options.operator;if(options.message){this.message=options.message;this.generatedMessage=false}else{this.message=getMessage(this);this.generatedMessage=true}var stackStartFunction=options.stackStartFunction||fail;if(Error.captureStackTrace){Error.captureStackTrace(this,stackStartFunction)}else{var err=new Error;if(err.stack){var out=err.stack;var fn_name=stackStartFunction.name;var idx=out.indexOf("\n"+fn_name);if(idx>=0){var next_line=out.indexOf("\n",idx+1);out=out.substring(next_line+1)}this.stack=out}}};util.inherits(assert.AssertionError,Error);function replacer(key,value){if(util.isUndefined(value)){return""+value}if(util.isNumber(value)&&!isFinite(value)){return value.toString()}if(util.isFunction(value)||util.isRegExp(value)){return value.toString()}return value}function truncate(s,n){if(util.isString(s)){return s.length=0;i--){if(ka[i]!=kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key]))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}else if(actual instanceof expected){return true}else if(expected.call({},actual)===true){return true}return false}function _throws(shouldThrow,block,expected,message){var actual;if(util.isString(expected)){message=expected;expected=null}try{block()}catch(e){actual=e}message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}if(!shouldThrow&&expectedException(actual,expected)){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws.apply(this,[true].concat(pSlice.call(arguments)))};assert.doesNotThrow=function(block,message){_throws.apply(this,[false].concat(pSlice.call(arguments)))};assert.ifError=function(err){if(err){throw err}};var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}},{"util/":13}],7:[function(require,module,exports){"use strict"},{}],8:[function(require,module,exports){(function(process){"use strict";function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var splitPath=function splitPath(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i1){for(var i=1;i_cachedDateTimestamp){_cachedDateTimestamp=currentTimestamp;_cachedDate=new Date(_cachedDateTimestamp);timestamp=_cachedDateTimestamp;if(_useUtcBasedDate){_cachedDate=new Date(_cachedDateTimestamp+getTimestampToUtcOffsetFor(_cachedDate)+_customTimezoneOffset)}}else{timestamp=_cachedDateTimestamp}date=_cachedDate}else{timestamp=date.getTime();if(_useUtcBasedDate){date=new Date(date.getTime()+getTimestampToUtcOffsetFor(date)+_customTimezoneOffset)}}return _processFormat(format,date,_locale,timestamp)}function _processFormat(format,date,locale,timestamp){var resultString="",padding=null,isInScope=false,length=format.length,extendedTZ=false;for(var i=0;i9){return numberToPad}if(paddingChar==null){paddingChar="0"}return paddingChar+numberToPad}function padTill3(numberToPad){if(numberToPad>99){return numberToPad}if(numberToPad>9){return"0"+numberToPad}return"00"+numberToPad}function hours12(hour){if(hour===0){return 12}else if(hour>12){return hour-12}return hour}function weekNumber(date,firstWeekday){firstWeekday=firstWeekday||"sunday";var weekday=date.getDay();if(firstWeekday==="monday"){if(weekday===0)weekday=6;else weekday--}var firstDayOfYearUtc=Date.UTC(date.getFullYear(),0,1),dateUtc=Date.UTC(date.getFullYear(),date.getMonth(),date.getDate()),yday=Math.floor((dateUtc-firstDayOfYearUtc)/864e5),weekNum=(yday+7-weekday)/7;return Math.floor(weekNum)}function ordinal(number){var i=number%10;var ii=number%100;if(ii>=11&&ii<=13||i===0||i>=4){return"th"}switch(i){case 1:return"st";case 2:return"nd";case 3:return"rd"}}function getTimestampToUtcOffsetFor(date){return(date.getTimezoneOffset()||0)*6e4}})()},{}],11:[function(require,module,exports){"use strict";if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function TempCtor(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],12:[function(require,module,exports){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){ -return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};module.exports=function isBuffer(arg){return arg&&(typeof arg==="undefined"?"undefined":_typeof(arg))==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],13:[function(require,module,exports){(function(process,global){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return(typeof arg==="undefined"?"undefined":_typeof(arg))==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return(typeof arg==="undefined"?"undefined":_typeof(arg))==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||(typeof arg==="undefined"?"undefined":_typeof(arg))==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":12,_process:9,inherits:11}],14:[function(require,module,exports){"use strict";var util=require("util");function TokenizationError(message,input,line){Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.message=message||"";this.input=input;this.line=line}util.inherits(TokenizationError,Error);function ParseError(message,input,line){Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.message=message||"";this.input=input;this.line=line}util.inherits(ParseError,Error);module.exports={TokenizationError:TokenizationError,ParseError:ParseError}},{util:13}],15:[function(require,module,exports){"use strict";var syntax=require("./syntax.js");var Exp=require("./expression.js");var lexical=require("./lexical.js");function evalExp(exp,scope){if(!scope)throw new Error("unable to evalExp: scope undefined");var operatorREs=lexical.operators,match;for(var i=0;i=|<|>|\s+contains\s+/];function isLiteral(str){return literalLine.test(str)}function isRange(str){return rangeLine.test(str)}function isVariable(str){return variableLine.test(str)}function parseLiteral(str){var res;if(res=str.match(numberLine)){return Number(str)}if(res=str.match(boolLine)){return str.toLowerCase()==="true"}if(res=str.match(quotedLine)){return str.slice(1,-1)}}module.exports={quoted:quoted,number:number,bool:bool,literal:literal,filter:filter,hash:hash,hashCapture:hashCapture,range:range,rangeCapture:rangeCapture,identifier:identifier,value:value,quoteBalanced:quoteBalanced,operators:operators,quotedLine:quotedLine,numberLine:numberLine,boolLine:boolLine,rangeLine:rangeLine,literalLine:literalLine,filterLine:filterLine,tagLine:tagLine,isLiteral:isLiteral,isVariable:isVariable,parseLiteral:parseLiteral,isRange:isRange}},{}],18:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var ParseError=require("./error.js").ParseError;module.exports=function(Tag,Filter){var stream={init:function init(tokens){this.tokens=tokens;this.handlers={};return this},on:function on(name,cb){this.handlers[name]=cb;return this},trigger:function trigger(event,arg){var h=this.handlers[event];if(typeof h==="function"){h(arg);return true}},start:function start(){this.trigger("start");while(!this.stopRequested&&(token=this.tokens.shift())){if(this.trigger("token",token))continue;if(token.type=="tag"&&this.trigger("tag:"+token.name,token)){continue}var template=parseToken(token,this.tokens);this.trigger("template",template)}if(!this.stopRequested)this.trigger("end");return this},stop:function stop(){this.stopRequested=true;return this}};function parse(tokens){var token,templates=[];while(token=tokens.shift()){templates.push(parseToken(token,tokens))}return templates}function parseToken(token,tokens){try{switch(token.type){case"tag":return parseTag(token,tokens);case"output":return parseOutput(token.value);case"html":return token}}catch(e){throw new ParseError(e.message,token.input,token.line)}}function parseTag(token,tokens){if(token.name==="continue"||token.name==="break")return token;return Tag.construct(token,tokens)}function parseOutput(str){var match=lexical.value.exec(str);if(!match)throw new Error("illegal output string: "+str);var initial=match[0];str=str.substr(match.index+match[0].length);var filters=[];while(match=lexical.filter.exec(str)){filters.push([match[0].trim()])}return{type:"output",initial:initial,filters:filters.map(function(str){return Filter.construct(str)})}}function parseStream(tokens){var s=Object.create(stream);return s.init(tokens)}return{parse:parse,parseTag:parseTag,parseStream:parseStream,parseOutput:parseOutput}}},{"./error.js":14,"./lexical.js":17}],19:[function(require,module,exports){"use strict";var error=require("./error.js");var Exp=require("./expression.js");var assert=require("assert");var Promise=require("any-promise");var render={renderTemplates:function renderTemplates(templates,scope,opts){var _this=this;assert(scope,"unable to evalTemplates: scope undefined");opts=opts||{};opts.strict_filters=opts.strict_filters||false;var html="";var lastPromise=templates.reduce(function(promise,template){return promise.then(function(partial){if(scope.safeGet("forloop.skip")){return Promise.resolve("")}if(scope.safeGet("forloop.stop")){throw new Error("forloop.stop")}var promiseLink=Promise.resolve("");switch(template.type){case"tag":promiseLink=_this.renderTag(template,scope,_this.register).then(function(partial){if(partial===undefined){return true}return html+=partial});break;case"html":promiseLink=Promise.resolve(template.value).then(function(partial){return html+=partial});break;case"output":var val=_this.evalOutput(template,scope,opts);promiseLink=Promise.resolve(val===undefined?"":stringify(val)).then(function(partial){return html+=partial});break}return promiseLink}).catch(function(error){if(error.message==="forloop.skip"){return html}else{throw error}})},Promise.resolve(""));return lastPromise.then(function(renderedHtml){return renderedHtml}).catch(function(error){throw error})},renderTag:function renderTag(template,scope,register){if(template.name==="continue"){scope.set("forloop.skip",true);return Promise.resolve("")}if(template.name==="break"){scope.set("forloop.stop",true);scope.set("forloop.skip",true);return Promise.reject(new Error("forloop.stop"))}return template.render(scope,register)},evalOutput:function evalOutput(template,scope,opts){assert(scope,"unable to evalOutput: scope undefined");var val=Exp.evalExp(template.initial,scope);template.filters.some(function(filter){if(filter.error){if(opts.strict_filters){throw filter.error}else{val="";return true}}val=filter.render(val,scope)});return val},resetRegisters:function resetRegisters(){return this.register={}}};function factory(){var instance=Object.create(render);instance.register={};return instance}function stringify(val){if(typeof val==="string")return val;return JSON.stringify(val)}module.exports=factory},{"./error.js":14,"./expression.js":15,"any-promise":3,assert:6}],20:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var Scope={safeGet:function safeGet(str){var i;if(str===undefined){var ctx={};for(i=this.scopes.length-1;i>=0;i--){var scp=this.scopes[i];for(var k in scp){if(scp.hasOwnProperty(k)){ctx[k]=scp[k]}}}return ctx}for(i=this.scopes.length-1;i>=0;i--){var v=getPropertyByPath(this.scopes[i],str);if(v!==undefined)return v}},get:function get(str){var val=this.safeGet(str);if(val===undefined&&this.opts.strict){throw new Error("[strict_variables] undefined variable: "+str)}return val},set:function set(k,v){setPropertyByPath(this.scopes[this.scopes.length-1],k,v);return this},push:function push(ctx){if(!ctx)throw new Error("trying to push "+ctx+" into scopes");return this.scopes.push(ctx)},pop:function pop(){return this.scopes.pop()}};function setPropertyByPath(obj,path,val){if(path instanceof String||typeof path==="string"){var paths=path.replace(/\[/g,".").replace(/\]/g,"").split(".");for(var i=0;i":function _(l,r){return l>r},"<":function _(l,r){return l=":function _(l,r){return l>=r},"<=":function _(l,r){return l<=r},contains:function contains(l,r){return l.indexOf(r)>-1},and:function and(l,r){return l&&r},or:function or(l,r){return l||r}};exports.operators=operators},{}],22:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var Promise=require("any-promise");var Exp=require("./expression.js");var TokenizationError=require("./error.js").TokenizationError;function hash(markup,scope){var obj={};lexical.hashCapture.lastIndex=0;while(match=lexical.hashCapture.exec(markup)){var k=match[1],v=match[2];obj[k]=Exp.evalValue(v,scope)}return obj}module.exports=function(){var tagImpls={};var _tagInstance={render:function render(scope,register){var reg=register[this.name];if(!reg)reg=register[this.name]={};var obj=hash(this.token.args,scope);return this.tagImpl.render&&this.tagImpl.render(scope,obj,reg)||Promise.resolve("")},parse:function parse(token,tokens){this.type="tag";this.token=token;this.name=token.name;var tagImpl=tagImpls[this.name];if(!tagImpl)throw new Error("tag "+this.name+" not found");this.tagImpl=Object.create(tagImpl);if(this.tagImpl.parse){this.tagImpl.parse(token,tokens)}}};function register(name,tag){tagImpls[name]=tag}function construct(token,tokens){var instance=Object.create(_tagInstance);instance.parse(token,tokens);return instance}function clear(){tagImpls={}}return{construct:construct,register:register,clear:clear}}},{"./error.js":14,"./expression.js":15,"./lexical.js":17,"any-promise":3}],23:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var TokenizationError=require("./error.js").TokenizationError;function parse(html){var tokens=[];if(!html)return tokens;var syntax=/({%(.*?)%})|({{(.*?)}})/g;var result,htmlFragment,token;var lastMatchEnd=0,lastMatchBegin=-1,parsedLinesCount=0;while((result=syntax.exec(html))!==null){if(result.index>lastMatchEnd){htmlFragment=html.slice(lastMatchEnd,result.index);tokens.push({type:"html",raw:htmlFragment,value:htmlFragment})}if(result[1]){token=factory("tag",1,result);var match=token.value.match(lexical.tagLine);if(!match){throw new TokenizationError("illegal tag: "+token.raw,token.input,token.line)}token.name=match[1];token.args=match[2];tokens.push(token)}else{token=factory("output",3,result);tokens.push(token)}lastMatchEnd=syntax.lastIndex}if(html.length>lastMatchEnd){htmlFragment=html.slice(lastMatchEnd,html.length);tokens.push({type:"html",raw:htmlFragment,value:htmlFragment})}return tokens;function factory(type,offset,match){return{type:type,raw:match[offset],value:match[offset+1].trim(),line:getLineNum(match),input:getLineContent(match)}}function getLineContent(match){var idx1=match.input.lastIndexOf("\n",match.index);var idx2=match.input.indexOf("\n",match.index);if(idx2===-1)idx2=match.input.length;return match.input.slice(idx1+1,idx2)}function getLineNum(match){var lines=match.input.slice(lastMatchBegin+1,match.index).split("\n");parsedLinesCount+=lines.length-1;lastMatchBegin=match.index;return parsedLinesCount+1}}exports.parse=parse},{"./error.js":14,"./lexical.js":17}],24:[function(require,module,exports){"use strict";var Liquid=require("..");var Promise=require("any-promise");var lexical=Liquid.lexical;var re=new RegExp("("+lexical.identifier.source+")\\s*=(.*)");module.exports=function(liquid){liquid.registerTag("assign",{parse:function parse(token){var match=token.args.match(re);if(!match)throw new Error("illegal token "+token.raw);this.key=match[1];this.value=match[2]},render:function render(scope,hash){scope.set(this.key,liquid.evalOutput(this.value,scope));return Promise.resolve("")}})}},{"..":2,"any-promise":3}],25:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;var re=new RegExp("("+lexical.identifier.source+")");module.exports=function(liquid){liquid.registerTag("capture",{parse:function parse(tagToken,remainTokens){var _this=this;var match=tagToken.args.match(re);if(!match)throw new Error(tagToken.args+" not valid identifier");this.variable=match[1];this.templates=[];var stream=liquid.parser.parseStream(remainTokens);stream.on("tag:endcapture",function(token){return stream.stop()}).on("template",function(tpl){return _this.templates.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){var _this2=this;return liquid.renderer.renderTemplates(this.templates,scope).then(function(html){scope.set(_this2.variable,html)})}})}},{"..":2}],26:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;module.exports=function(liquid){liquid.registerTag("case",{parse:function parse(tagToken,remainTokens){var _this=this;this.cond=tagToken.args;this.cases=[];this.elseTemplates=[];var p=[],stream=liquid.parser.parseStream(remainTokens).on("tag:when",function(token){if(!_this.cases[token.args]){_this.cases.push({val:token.args,templates:p=[]})}}).on("tag:else",function(token){return p=_this.elseTemplates}).on("tag:endcase",function(token){return stream.stop()}).on("template",function(tpl){return p.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){for(var i=0;i":">",'"':""","'":"'"};function escape(str){return(str||"").replace(/&|<|>|"|'/g,function(m){return escapeMap[m]})}liquid.registerFilter("escape",escape);var unescapeMap={"&":"&","<":"<",">":">",""":'"',"'":"'"};function unescape(str){return(str||"").replace(/&(amp|lt|gt|#34|#39);/g,function(m){return unescapeMap[m]})}liquid.registerFilter("escape_once",function(str){return escape(unescape(str))});liquid.registerFilter("first",function(v){return v[0]});liquid.registerFilter("floor",function(v){return Math.floor(v)});liquid.registerFilter("join",function(v,arg){return v.join(arg)});liquid.registerFilter("last",function(v){return v[v.length-1]});liquid.registerFilter("lstrip",function(v){return(v||"").replace(/^\s+/,"")});liquid.registerFilter("map",function(arr,arg){return arr.map(function(v){return v[arg]})});liquid.registerFilter("minus",bindFixed(function(v,arg){return v-arg}));liquid.registerFilter("modulo",bindFixed(function(v,arg){return v%arg}));liquid.registerFilter("newline_to_br",function(v){return v.replace(/\n/g,"
")});liquid.registerFilter("plus",bindFixed(function(v,arg){return v+arg}));liquid.registerFilter("prepend",function(v,arg){return arg+v});liquid.registerFilter("remove",function(v,arg){return v.split(arg).join("")});liquid.registerFilter("remove_first",function(v,l){return v.replace(l,"")});liquid.registerFilter("replace",function(v,pattern,replacement){return(v||"").split(pattern).join(replacement)});liquid.registerFilter("replace_first",function(v,arg1,arg2){return(v||"").replace(arg1,arg2)});liquid.registerFilter("reverse",function(v){return(v||"").reverse()});liquid.registerFilter("round",function(v,arg){var amp=Math.pow(10,arg||0);return Math.round(v*amp,arg)/amp});liquid.registerFilter("rstrip",function(str){return(str||"").replace(/\s+$/,"")});liquid.registerFilter("size",function(v){return v.length});liquid.registerFilter("slice",function(v,begin,length){return v.substr(begin,length===undefined?1:length)});liquid.registerFilter("sort",function(v,arg){return(v||"").sort(arg)});liquid.registerFilter("split",function(v,arg){return(v||"").split(arg)});liquid.registerFilter("strip",function(v){return(v||"").trim()});liquid.registerFilter("strip_html",function(v){return(v||"").replace(/<\/?\s*\w+\s*\/?>/g,"")});liquid.registerFilter("strip_newlines",function(v){return(v||"").replace(/\n/g,"")});liquid.registerFilter("times",function(v,arg){return v*arg});liquid.registerFilter("truncate",function(v,l,o){v=v||"";o=o===undefined?"...":o;l=l||16;if(v.length<=l)return v;return v.substr(0,l-o.length)+o});liquid.registerFilter("truncatewords",function(v,l,o){if(o===undefined)o="...";var arr=v.split(" ");var ret=arr.slice(0,l).join(" ");if(arr.length>l)ret+=o;return ret});liquid.registerFilter("uniq",function(arr){var u={};return(arr||[]).filter(function(val){if(u.hasOwnProperty(val)){return false}u[val]=true;return true})});liquid.registerFilter("upcase",function(str){return(str||"").toUpperCase()});liquid.registerFilter("url_encode",encodeURIComponent)};function getFixed(v){var p=(v+"").split(".");return p.length>1?p[1].length:0}function getMaxFixed(l,r){return Math.max(getFixed(l),getFixed(r))}function bindFixed(cb){return function(l,r){var f=getMaxFixed(l,r);return cb(l,r).toFixed(f)}}},{strftime:10}],2:[function(require,module,exports){"use strict";var Scope=require("./src/scope");var assert=require("assert");var tokenizer=require("./src/tokenizer.js");var Render=require("./src/render.js");var lexical=require("./src/lexical.js");var path=require("path");var fs=require("fs");var Tag=require("./src/tag.js");var Filter=require("./src/filter.js");var Template=require("./src/parser");var Expression=require("./src/expression.js");var tags=require("./tags");var filters=require("./filters");var Promise=require("any-promise");var _engine={init:function init(tag,filter,options){if(options.cache){this.cache={}}this.options=options;this.tag=tag;this.filter=filter;this.parser=Template(tag,filter);this.renderer=Render();tags(this);filters(this);return this},parse:function parse(html){var tokens=tokenizer.parse(html);return this.parser.parse(tokens)},render:function render(tpl,ctx,opts){opts=opts||{};opts.strict_variables=opts.strict_variables||false;opts.strict_filters=opts.strict_filters||false;this.renderer.resetRegisters();var scope=Scope.factory(ctx,{strict:opts.strict_variables});return this.renderer.renderTemplates(tpl,scope,opts)},parseAndRender:function parseAndRender(html,ctx,opts){try{var tpl=this.parse(html);return this.render(tpl,ctx,opts)}catch(error){return Promise.reject(error)}},renderFile:function renderFile(filepath,ctx,opts){var _this=this;return this.handleCache(filepath).then(function(templates){return _this.render(templates,ctx,opts)}).catch(function(e){e.file=filepath;throw e})},evalOutput:function evalOutput(str,scope){var tpl=this.parser.parseOutput(str.trim());return this.renderer.evalOutput(tpl,scope)},registerFilter:function registerFilter(name,filter){return this.filter.register(name,filter)},registerTag:function registerTag(name,tag){return this.tag.register(name,tag)},handleCache:function handleCache(filepath){var _this2=this;assert(filepath,"filepath cannot be null");filepath=path.resolve(this.options.root,filepath);if(path.extname(filepath)===""){filepath+=this.options.extname}return this.getTemplate(filepath).then(function(html){var tpl=_this2.options.cache&&_this2.cache[filepath]||_this2.parse(html);return _this2.options.cache?_this2.cache[filepath]=tpl:tpl})},getTemplate:function getTemplate(filepath){return new Promise(function(resolve,reject){fs.readFile(filepath,"utf8",function(err,html){err?reject(err):resolve(html)})})},express:function express(renderingOptions){var _this3=this;return function(filePath,options,callback){_this3.renderFile(filePath,options,renderingOptions).then(function(html){return callback(null,html)}).catch(function(e){return callback(e)})}}};function factory(options){options=options||{};options.root=options.root||"";options.extname=options.extname||".liquid";var engine=Object.create(_engine);engine.init(Tag(),Filter(),options);return engine}factory.lexical=lexical;factory.isTruthy=Expression.isTruthy;factory.isFalsy=Expression.isFalsy;factory.evalExp=Expression.evalExp;factory.evalValue=Expression.evalValue;module.exports=factory},{"./filters":1,"./src/expression.js":15,"./src/filter.js":16,"./src/lexical.js":17,"./src/parser":18,"./src/render.js":19,"./src/scope":20,"./src/tag.js":22,"./src/tokenizer.js":23,"./tags":34,"any-promise":3,assert:6,fs:7,path:8}],3:[function(require,module,exports){"use strict";module.exports=require("./register")().Promise},{"./register":5}],4:[function(require,module,exports){"use strict";var REGISTRATION_KEY="@@any-promise/REGISTRATION",registered=null;module.exports=function(root,loadImplementation){return function register(implementation,opts){implementation=implementation||null;opts=opts||{};var registerGlobal=opts.global!==false;if(registered===null&®isterGlobal){registered=root[REGISTRATION_KEY]||null}if(registered!==null&&implementation!==null&®istered.implementation!==implementation){throw new Error('any-promise already defined as "'+registered.implementation+'". You can only register an implementation before the first '+' call to require("any-promise") and an implementation cannot be changed')}if(registered===null){if(implementation!==null&&typeof opts.Promise!=="undefined"){registered={Promise:opts.Promise,implementation:implementation}}else{registered=loadImplementation(implementation)}if(registerGlobal){root[REGISTRATION_KEY]=registered}}return registered}}},{}],5:[function(require,module,exports){"use strict";module.exports=require("./loader")(window,loadImplementation);function loadImplementation(){if(typeof window.Promise==="undefined"){throw new Error("any-promise browser requires a polyfill or explicit registration"+" e.g: require('any-promise/register/bluebird')")}return{Promise:window.Promise,implementation:"window.Promise"}}},{"./loader":4}],6:[function(require,module,exports){"use strict";var util=require("util/");var pSlice=Array.prototype.slice;var hasOwn=Object.prototype.hasOwnProperty;var assert=module.exports=ok;assert.AssertionError=function AssertionError(options){this.name="AssertionError";this.actual=options.actual;this.expected=options.expected;this.operator=options.operator;if(options.message){this.message=options.message;this.generatedMessage=false}else{this.message=getMessage(this);this.generatedMessage=true}var stackStartFunction=options.stackStartFunction||fail;if(Error.captureStackTrace){Error.captureStackTrace(this,stackStartFunction)}else{var err=new Error;if(err.stack){var out=err.stack;var fn_name=stackStartFunction.name;var idx=out.indexOf("\n"+fn_name);if(idx>=0){var next_line=out.indexOf("\n",idx+1);out=out.substring(next_line+1)}this.stack=out}}};util.inherits(assert.AssertionError,Error);function replacer(key,value){if(util.isUndefined(value)){return""+value}if(util.isNumber(value)&&!isFinite(value)){return value.toString()}if(util.isFunction(value)||util.isRegExp(value)){return value.toString()}return value}function truncate(s,n){if(util.isString(s)){return s.length=0;i--){if(ka[i]!=kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key]))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}else if(actual instanceof expected){return true}else if(expected.call({},actual)===true){return true}return false}function _throws(shouldThrow,block,expected,message){var actual;if(util.isString(expected)){message=expected;expected=null}try{block()}catch(e){actual=e}message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}if(!shouldThrow&&expectedException(actual,expected)){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws.apply(this,[true].concat(pSlice.call(arguments)))};assert.doesNotThrow=function(block,message){_throws.apply(this,[false].concat(pSlice.call(arguments)))};assert.ifError=function(err){if(err){throw err}};var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}},{"util/":13}],7:[function(require,module,exports){"use strict"},{}],8:[function(require,module,exports){(function(process){"use strict";function normalizeArray(parts,allowAboveRoot){var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up--;up){parts.unshift("..")}}return parts}var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;var splitPath=function splitPath(filename){return splitPathRe.exec(filename).slice(1)};exports.resolve=function(){var resolvedPath="",resolvedAbsolute=false;for(var i=arguments.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?arguments[i]:process.cwd();if(typeof path!=="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){continue}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=path.charAt(0)==="/"}resolvedPath=normalizeArray(filter(resolvedPath.split("/"),function(p){return!!p}),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."};exports.normalize=function(path){var isAbsolute=exports.isAbsolute(path),trailingSlash=substr(path,-1)==="/";path=normalizeArray(filter(path.split("/"),function(p){return!!p}),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path};exports.isAbsolute=function(path){return path.charAt(0)==="/"};exports.join=function(){var paths=Array.prototype.slice.call(arguments,0);return exports.normalize(filter(paths,function(p,index){if(typeof p!=="string"){throw new TypeError("Arguments to path.join must be strings")}return p}).join("/"))};exports.relative=function(from,to){from=exports.resolve(from).substr(1);to=exports.resolve(to).substr(1);function trim(arr){var start=0;for(;start=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i1){for(var i=1;i_cachedDateTimestamp){_cachedDateTimestamp=currentTimestamp;_cachedDate=new Date(_cachedDateTimestamp);timestamp=_cachedDateTimestamp;if(_useUtcBasedDate){_cachedDate=new Date(_cachedDateTimestamp+getTimestampToUtcOffsetFor(_cachedDate)+_customTimezoneOffset)}}else{timestamp=_cachedDateTimestamp}date=_cachedDate}else{timestamp=date.getTime();if(_useUtcBasedDate){date=new Date(date.getTime()+getTimestampToUtcOffsetFor(date)+_customTimezoneOffset)}}return _processFormat(format,date,_locale,timestamp)}function _processFormat(format,date,locale,timestamp){var resultString="",padding=null,isInScope=false,length=format.length,extendedTZ=false;for(var i=0;i9){return numberToPad}if(paddingChar==null){paddingChar="0"}return paddingChar+numberToPad}function padTill3(numberToPad){if(numberToPad>99){return numberToPad}if(numberToPad>9){return"0"+numberToPad}return"00"+numberToPad}function hours12(hour){if(hour===0){return 12}else if(hour>12){return hour-12}return hour}function weekNumber(date,firstWeekday){firstWeekday=firstWeekday||"sunday";var weekday=date.getDay();if(firstWeekday==="monday"){if(weekday===0)weekday=6;else weekday--}var firstDayOfYearUtc=Date.UTC(date.getFullYear(),0,1),dateUtc=Date.UTC(date.getFullYear(),date.getMonth(),date.getDate()),yday=Math.floor((dateUtc-firstDayOfYearUtc)/864e5),weekNum=(yday+7-weekday)/7;return Math.floor(weekNum)}function ordinal(number){var i=number%10;var ii=number%100;if(ii>=11&&ii<=13||i===0||i>=4){return"th"}switch(i){case 1:return"st";case 2:return"nd";case 3:return"rd"}}function getTimestampToUtcOffsetFor(date){return(date.getTimezoneOffset()||0)*6e4}})()},{}],11:[function(require,module,exports){"use strict";if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function TempCtor(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],12:[function(require,module,exports){"use strict"; -}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){for(var i=0;i"}html+=''}return html+=''}).then(function(partial){scope.push(context);return liquid.renderer.renderTemplates(_this2.templates,scope)}).then(function(partial){scope.pop(context);html+=partial;return html+=""})},Promise.resolve(""));return lastPromise.then(function(){if(row>0){html+=""}html+="";return html}).catch(function(error){throw error})}})}},{"..":2,"any-promise":3}],38:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;module.exports=function(liquid){liquid.registerTag("unless",{parse:function parse(tagToken,remainTokens){var _this=this;this.templates=[];this.elseTemplates=[];var p,stream=liquid.parser.parseStream(remainTokens).on("start",function(x){p=_this.templates;_this.cond=tagToken.args}).on("tag:else",function(token){return p=_this.elseTemplates}).on("tag:endunless",function(token){return stream.stop()}).on("template",function(tpl){return p.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){var cond=Liquid.evalExp(this.cond,scope);return Liquid.isFalsy(cond)?liquid.renderer.renderTemplates(this.templates,scope):liquid.renderer.renderTemplates(this.elseTemplates,scope)}})}},{"..":2}]},{},[2])(2)}); \ No newline at end of file +var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};module.exports=function isBuffer(arg){return arg&&(typeof arg==="undefined"?"undefined":_typeof(arg))==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],13:[function(require,module,exports){(function(process,global){"use strict";var _typeof=typeof Symbol==="function"&&typeof Symbol.iterator==="symbol"?function(obj){return typeof obj}:function(obj){return obj&&typeof Symbol==="function"&&obj.constructor===Symbol?"symbol":typeof obj};var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return(typeof arg==="undefined"?"undefined":_typeof(arg))==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return(typeof arg==="undefined"?"undefined":_typeof(arg))==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||(typeof arg==="undefined"?"undefined":_typeof(arg))==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":12,_process:9,inherits:11}],14:[function(require,module,exports){"use strict";var util=require("util");function TokenizationError(message,input,line){Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.message=message||"";this.input=input;this.line=line}util.inherits(TokenizationError,Error);function ParseError(message,input,line){Error.captureStackTrace(this,this.constructor);this.name=this.constructor.name;this.message=message||"";this.input=input;this.line=line}util.inherits(ParseError,Error);module.exports={TokenizationError:TokenizationError,ParseError:ParseError}},{util:13}],15:[function(require,module,exports){"use strict";var syntax=require("./syntax.js");var Exp=require("./expression.js");var lexical=require("./lexical.js");function evalExp(exp,scope){if(!scope)throw new Error("unable to evalExp: scope undefined");var operatorREs=lexical.operators,match;for(var i=0;i=|<|>|\s+contains\s+/];function isLiteral(str){return literalLine.test(str)}function isRange(str){return rangeLine.test(str)}function isVariable(str){return variableLine.test(str)}function parseLiteral(str){var res;if(res=str.match(numberLine)){return Number(str)}if(res=str.match(boolLine)){return str.toLowerCase()==="true"}if(res=str.match(quotedLine)){return str.slice(1,-1)}}module.exports={quoted:quoted,number:number,bool:bool,literal:literal,filter:filter,hash:hash,hashCapture:hashCapture,range:range,rangeCapture:rangeCapture,identifier:identifier,value:value,quoteBalanced:quoteBalanced,operators:operators,quotedLine:quotedLine,numberLine:numberLine,boolLine:boolLine,rangeLine:rangeLine,literalLine:literalLine,filterLine:filterLine,tagLine:tagLine,isLiteral:isLiteral,isVariable:isVariable,parseLiteral:parseLiteral,isRange:isRange}},{}],18:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var ParseError=require("./error.js").ParseError;module.exports=function(Tag,Filter){var stream={init:function init(tokens){this.tokens=tokens;this.handlers={};return this},on:function on(name,cb){this.handlers[name]=cb;return this},trigger:function trigger(event,arg){var h=this.handlers[event];if(typeof h==="function"){h(arg);return true}},start:function start(){this.trigger("start");while(!this.stopRequested&&(token=this.tokens.shift())){if(this.trigger("token",token))continue;if(token.type=="tag"&&this.trigger("tag:"+token.name,token)){continue}var template=parseToken(token,this.tokens);this.trigger("template",template)}if(!this.stopRequested)this.trigger("end");return this},stop:function stop(){this.stopRequested=true;return this}};function parse(tokens){var token,templates=[];while(token=tokens.shift()){templates.push(parseToken(token,tokens))}return templates}function parseToken(token,tokens){try{switch(token.type){case"tag":return parseTag(token,tokens);case"output":return parseOutput(token.value);case"html":return token}}catch(e){throw new ParseError(e.message,token.input,token.line)}}function parseTag(token,tokens){if(token.name==="continue"||token.name==="break")return token;return Tag.construct(token,tokens)}function parseOutput(str){var match=lexical.value.exec(str);if(!match)throw new Error("illegal output string: "+str);var initial=match[0];str=str.substr(match.index+match[0].length);var filters=[];while(match=lexical.filter.exec(str)){filters.push([match[0].trim()])}return{type:"output",initial:initial,filters:filters.map(function(str){return Filter.construct(str)})}}function parseStream(tokens){var s=Object.create(stream);return s.init(tokens)}return{parse:parse,parseTag:parseTag,parseStream:parseStream,parseOutput:parseOutput}}},{"./error.js":14,"./lexical.js":17}],19:[function(require,module,exports){"use strict";var error=require("./error.js");var Exp=require("./expression.js");var assert=require("assert");var Promise=require("any-promise");var render={renderTemplates:function renderTemplates(templates,scope,opts){var _this=this;assert(scope,"unable to evalTemplates: scope undefined");opts=opts||{};opts.strict_filters=opts.strict_filters||false;var html="";var lastPromise=templates.reduce(function(promise,template){return promise.then(function(partial){if(scope.safeGet("forloop.skip")){return Promise.resolve("")}if(scope.safeGet("forloop.stop")){throw new Error("forloop.stop")}var promiseLink=Promise.resolve("");switch(template.type){case"tag":promiseLink=_this.renderTag(template,scope,_this.register).then(function(partial){if(partial===undefined){return true}return html+=partial});break;case"html":promiseLink=Promise.resolve(template.value).then(function(partial){return html+=partial});break;case"output":var val=_this.evalOutput(template,scope,opts);promiseLink=Promise.resolve(val===undefined?"":stringify(val)).then(function(partial){return html+=partial});break}return promiseLink}).catch(function(error){if(error.message==="forloop.skip"){return html}else{throw error}})},Promise.resolve(""));return lastPromise.then(function(renderedHtml){return renderedHtml}).catch(function(error){throw error})},renderTag:function renderTag(template,scope,register){if(template.name==="continue"){scope.set("forloop.skip",true);return Promise.resolve("")}if(template.name==="break"){scope.set("forloop.stop",true);scope.set("forloop.skip",true);return Promise.reject(new Error("forloop.stop"))}return template.render(scope,register)},evalOutput:function evalOutput(template,scope,opts){assert(scope,"unable to evalOutput: scope undefined");var val=Exp.evalExp(template.initial,scope);template.filters.some(function(filter){if(filter.error){if(opts.strict_filters){throw filter.error}else{val="";return true}}val=filter.render(val,scope)});return val},resetRegisters:function resetRegisters(){return this.register={}}};function factory(){var instance=Object.create(render);instance.register={};return instance}function stringify(val){if(typeof val==="string")return val;return JSON.stringify(val)}module.exports=factory},{"./error.js":14,"./expression.js":15,"any-promise":3,assert:6}],20:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var Scope={safeGet:function safeGet(str){var i;if(str===undefined){var ctx={};for(i=this.scopes.length-1;i>=0;i--){var scp=this.scopes[i];for(var k in scp){if(scp.hasOwnProperty(k)){ctx[k]=scp[k]}}}return ctx}for(i=this.scopes.length-1;i>=0;i--){var v=getPropertyByPath(this.scopes[i],str);if(v!==undefined)return v}},get:function get(str){var val=this.safeGet(str);if(val===undefined&&this.opts.strict){throw new Error("[strict_variables] undefined variable: "+str)}return val},set:function set(k,v){setPropertyByPath(this.scopes[this.scopes.length-1],k,v);return this},push:function push(ctx){if(!ctx)throw new Error("trying to push "+ctx+" into scopes");return this.scopes.push(ctx)},pop:function pop(){return this.scopes.pop()}};function setPropertyByPath(obj,path,val){if(path instanceof String||typeof path==="string"){var paths=path.replace(/\[/g,".").replace(/\]/g,"").split(".");for(var i=0;i":function _(l,r){return l>r},"<":function _(l,r){return l=":function _(l,r){return l>=r},"<=":function _(l,r){return l<=r},contains:function contains(l,r){return l.indexOf(r)>-1},and:function and(l,r){return l&&r},or:function or(l,r){return l||r}};exports.operators=operators},{}],22:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var Promise=require("any-promise");var Exp=require("./expression.js");var TokenizationError=require("./error.js").TokenizationError;function hash(markup,scope){var obj={};lexical.hashCapture.lastIndex=0;while(match=lexical.hashCapture.exec(markup)){var k=match[1],v=match[2];obj[k]=Exp.evalValue(v,scope)}return obj}module.exports=function(){var tagImpls={};var _tagInstance={render:function render(scope,register){var reg=register[this.name];if(!reg)reg=register[this.name]={};var obj=hash(this.token.args,scope);return this.tagImpl.render&&this.tagImpl.render(scope,obj,reg)||Promise.resolve("")},parse:function parse(token,tokens){this.type="tag";this.token=token;this.name=token.name;var tagImpl=tagImpls[this.name];if(!tagImpl)throw new Error("tag "+this.name+" not found");this.tagImpl=Object.create(tagImpl);if(this.tagImpl.parse){this.tagImpl.parse(token,tokens)}}};function register(name,tag){tagImpls[name]=tag}function construct(token,tokens){var instance=Object.create(_tagInstance);instance.parse(token,tokens);return instance}function clear(){tagImpls={}}return{construct:construct,register:register,clear:clear}}},{"./error.js":14,"./expression.js":15,"./lexical.js":17,"any-promise":3}],23:[function(require,module,exports){"use strict";var lexical=require("./lexical.js");var TokenizationError=require("./error.js").TokenizationError;function parse(html){var tokens=[];if(!html)return tokens;var syntax=/({%(.*?)%})|({{(.*?)}})/g;var result,htmlFragment,token;var lastMatchEnd=0,lastMatchBegin=-1,parsedLinesCount=0;while((result=syntax.exec(html))!==null){if(result.index>lastMatchEnd){htmlFragment=html.slice(lastMatchEnd,result.index);tokens.push({type:"html",raw:htmlFragment,value:htmlFragment})}if(result[1]){token=factory("tag",1,result);var match=token.value.match(lexical.tagLine);if(!match){throw new TokenizationError("illegal tag: "+token.raw,token.input,token.line)}token.name=match[1];token.args=match[2];tokens.push(token)}else{token=factory("output",3,result);tokens.push(token)}lastMatchEnd=syntax.lastIndex}if(html.length>lastMatchEnd){htmlFragment=html.slice(lastMatchEnd,html.length);tokens.push({type:"html",raw:htmlFragment,value:htmlFragment})}return tokens;function factory(type,offset,match){return{type:type,raw:match[offset],value:match[offset+1].trim(),line:getLineNum(match),input:getLineContent(match)}}function getLineContent(match){var idx1=match.input.lastIndexOf("\n",match.index);var idx2=match.input.indexOf("\n",match.index);if(idx2===-1)idx2=match.input.length;return match.input.slice(idx1+1,idx2)}function getLineNum(match){var lines=match.input.slice(lastMatchBegin+1,match.index).split("\n");parsedLinesCount+=lines.length-1;lastMatchBegin=match.index;return parsedLinesCount+1}}exports.parse=parse},{"./error.js":14,"./lexical.js":17}],24:[function(require,module,exports){"use strict";var Liquid=require("..");var Promise=require("any-promise");var lexical=Liquid.lexical;var re=new RegExp("("+lexical.identifier.source+")\\s*=(.*)");module.exports=function(liquid){liquid.registerTag("assign",{parse:function parse(token){var match=token.args.match(re);if(!match)throw new Error("illegal token "+token.raw);this.key=match[1];this.value=match[2]},render:function render(scope,hash){scope.set(this.key,liquid.evalOutput(this.value,scope));return Promise.resolve("")}})}},{"..":2,"any-promise":3}],25:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;var re=new RegExp("("+lexical.identifier.source+")");module.exports=function(liquid){liquid.registerTag("capture",{parse:function parse(tagToken,remainTokens){var _this=this;var match=tagToken.args.match(re);if(!match)throw new Error(tagToken.args+" not valid identifier");this.variable=match[1];this.templates=[];var stream=liquid.parser.parseStream(remainTokens);stream.on("tag:endcapture",function(token){return stream.stop()}).on("template",function(tpl){return _this.templates.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){var _this2=this;return liquid.renderer.renderTemplates(this.templates,scope).then(function(html){scope.set(_this2.variable,html)})}})}},{"..":2}],26:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;module.exports=function(liquid){liquid.registerTag("case",{parse:function parse(tagToken,remainTokens){var _this=this;this.cond=tagToken.args;this.cases=[];this.elseTemplates=[];var p=[],stream=liquid.parser.parseStream(remainTokens).on("tag:when",function(token){if(!_this.cases[token.args]){_this.cases.push({val:token.args,templates:p=[]})}}).on("tag:else",function(token){return p=_this.elseTemplates}).on("tag:endcase",function(token){return stream.stop()}).on("template",function(tpl){return p.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){for(var i=0;i"}html+=''}return html+=''}).then(function(partial){scope.push(context);return liquid.renderer.renderTemplates(_this2.templates,scope)}).then(function(partial){scope.pop(context);html+=partial;return html+=""})},Promise.resolve(""));return lastPromise.then(function(){if(row>0){html+=""}html+="";return html}).catch(function(error){throw error})}})}},{"..":2,"any-promise":3}],38:[function(require,module,exports){"use strict";var Liquid=require("..");var lexical=Liquid.lexical;module.exports=function(liquid){liquid.registerTag("unless",{parse:function parse(tagToken,remainTokens){var _this=this;this.templates=[];this.elseTemplates=[];var p,stream=liquid.parser.parseStream(remainTokens).on("start",function(x){p=_this.templates;_this.cond=tagToken.args}).on("tag:else",function(token){return p=_this.elseTemplates}).on("tag:endunless",function(token){return stream.stop()}).on("template",function(tpl){return p.push(tpl)}).on("end",function(x){throw new Error("tag "+tagToken.raw+" not closed")});stream.start()},render:function render(scope,hash){var cond=Liquid.evalExp(this.cond,scope);return Liquid.isFalsy(cond)?liquid.renderer.renderTemplates(this.templates,scope):liquid.renderer.renderTemplates(this.elseTemplates,scope)}})}},{"..":2}]},{},[2])(2)}); \ No newline at end of file diff --git a/package.json b/package.json index e1d9f62ed..35472bd8a 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "main": "index.js", "scripts": { "test": "mocha --recursive", + "prepublish": "npm test && make dist", "dist": "make dist" }, "repository": {