mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 00:55:13 -07:00
refactor
This commit is contained in:
Vendored
+206
-166
@@ -45,6 +45,36 @@ var asyncToGenerator = function (fn) {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var classCallCheck = function (instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var inherits = function (subClass, superClass) {
|
||||||
|
if (typeof superClass !== "function" && superClass !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||||
|
constructor: {
|
||||||
|
value: subClass,
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
||||||
|
};
|
||||||
|
|
||||||
|
var possibleConstructorReturn = function (self, call) {
|
||||||
|
if (!self) {
|
||||||
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||||
|
}
|
||||||
|
|
||||||
|
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
*
|
*
|
||||||
@@ -771,6 +801,10 @@ function stringify(value) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create(proto) {
|
||||||
|
return Object.create(proto);
|
||||||
|
}
|
||||||
|
|
||||||
function isNil(value) {
|
function isNil(value) {
|
||||||
return value === null || value === undefined;
|
return value === null || value === undefined;
|
||||||
}
|
}
|
||||||
@@ -923,10 +957,6 @@ function isLiteral(str) {
|
|||||||
return literalLine.test(str);
|
return literalLine.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRange(str) {
|
|
||||||
return rangeLine.test(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVariable(str) {
|
function isVariable(str) {
|
||||||
return variableLine.test(str);
|
return variableLine.test(str);
|
||||||
}
|
}
|
||||||
@@ -951,104 +981,117 @@ function parseLiteral(str) {
|
|||||||
throw new TypeError('cannot parse \'' + str + '\' as literal');
|
throw new TypeError('cannot parse \'' + str + '\' as literal');
|
||||||
}
|
}
|
||||||
|
|
||||||
var lexical = /*#__PURE__*/Object.freeze({
|
var LiquidError = function (_Error) {
|
||||||
quoted: quoted,
|
inherits(LiquidError, _Error);
|
||||||
quoteBalanced: quoteBalanced,
|
|
||||||
integer: integer,
|
|
||||||
number: number,
|
|
||||||
bool: bool,
|
|
||||||
identifier: identifier,
|
|
||||||
subscript: subscript,
|
|
||||||
literal: literal,
|
|
||||||
variable: variable,
|
|
||||||
rangeLimit: rangeLimit,
|
|
||||||
range: range$1,
|
|
||||||
rangeCapture: rangeCapture,
|
|
||||||
value: value,
|
|
||||||
hash: hash,
|
|
||||||
hashCapture: hashCapture,
|
|
||||||
tagLine: tagLine,
|
|
||||||
literalLine: literalLine,
|
|
||||||
variableLine: variableLine,
|
|
||||||
numberLine: numberLine,
|
|
||||||
boolLine: boolLine,
|
|
||||||
quotedLine: quotedLine,
|
|
||||||
rangeLine: rangeLine,
|
|
||||||
integerLine: integerLine,
|
|
||||||
valueDeclaration: valueDeclaration,
|
|
||||||
valueList: valueList,
|
|
||||||
filter: filter,
|
|
||||||
filterCapture: filterCapture,
|
|
||||||
filterLine: filterLine,
|
|
||||||
operators: operators,
|
|
||||||
isInteger: isInteger,
|
|
||||||
isLiteral: isLiteral,
|
|
||||||
isRange: isRange,
|
|
||||||
isVariable: isVariable,
|
|
||||||
matchValue: matchValue,
|
|
||||||
parseLiteral: parseLiteral
|
|
||||||
});
|
|
||||||
|
|
||||||
function initError() {
|
function LiquidError(message) {
|
||||||
this.name = this.constructor.name;
|
classCallCheck(this, LiquidError);
|
||||||
if (Error.captureStackTrace) {
|
|
||||||
Error.captureStackTrace(this, this.constructor);
|
var _this = possibleConstructorReturn(this, (LiquidError.__proto__ || Object.getPrototypeOf(LiquidError)).call(this, message));
|
||||||
|
|
||||||
|
_this.name = _this.constructor.name;
|
||||||
|
if (typeof Error.captureStackTrace === 'function') {
|
||||||
|
Error.captureStackTrace(_this, _this.constructor);
|
||||||
|
} else {
|
||||||
|
_this.stack = new Error(message).stack;
|
||||||
|
}
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function initLiquidError(err, token) {
|
return LiquidError;
|
||||||
initError.call(this);
|
}(Error);
|
||||||
|
|
||||||
this.input = token.input;
|
var TemplateError = function (_LiquidError) {
|
||||||
this.line = token.line;
|
inherits(TemplateError, _LiquidError);
|
||||||
this.file = token.file;
|
|
||||||
|
|
||||||
var context = mkContext(token.input, token.line);
|
function TemplateError(err, token) {
|
||||||
this.message = mkMessage(err.message, token);
|
classCallCheck(this, TemplateError);
|
||||||
this.stack = context + '\n' + (this.stack || this.message) + (err.stack ? '\nFrom ' + err.stack : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function TokenizationError(message, token) {
|
var _this2 = possibleConstructorReturn(this, (TemplateError.__proto__ || Object.getPrototypeOf(TemplateError)).call(this));
|
||||||
initLiquidError.call(this, { message: message }, token);
|
|
||||||
}
|
|
||||||
TokenizationError.prototype = Object.create(Error.prototype);
|
|
||||||
TokenizationError.prototype.constructor = TokenizationError;
|
|
||||||
|
|
||||||
function ParseError(e, token) {
|
_this2.input = token.input;
|
||||||
assign(this, e);
|
_this2.line = token.line;
|
||||||
this.originalError = e;
|
_this2.file = token.file;
|
||||||
|
_this2.message = mkMessage(err.message, token);
|
||||||
initLiquidError.call(this, e, token);
|
var context = mkContext(token.input, token.line);
|
||||||
}
|
_this2.stack = context + '\n' + (_this2.stack || _this2.message) + (err.stack ? '\nFrom ' + err.stack : '');
|
||||||
ParseError.prototype = Object.create(Error.prototype);
|
return _this2;
|
||||||
ParseError.prototype.constructor = ParseError;
|
|
||||||
|
|
||||||
function RenderError(e, tpl) {
|
|
||||||
// return the original render error
|
|
||||||
if (e instanceof RenderError) {
|
|
||||||
return e;
|
|
||||||
}
|
}
|
||||||
assign(this, e);
|
|
||||||
this.originalError = e;
|
|
||||||
|
|
||||||
initLiquidError.call(this, e, tpl.token);
|
return TemplateError;
|
||||||
}
|
}(LiquidError);
|
||||||
RenderError.prototype = Object.create(Error.prototype);
|
|
||||||
RenderError.prototype.constructor = RenderError;
|
|
||||||
|
|
||||||
function RenderBreakError(message) {
|
var TokenizationError = function (_TemplateError) {
|
||||||
initError.call(this);
|
inherits(TokenizationError, _TemplateError);
|
||||||
this.message = message + '';
|
|
||||||
}
|
|
||||||
RenderBreakError.prototype = Object.create(Error.prototype);
|
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError;
|
|
||||||
|
|
||||||
function AssertionError(message) {
|
function TokenizationError(message, token) {
|
||||||
initError.call(this);
|
classCallCheck(this, TokenizationError);
|
||||||
this.message = message + '';
|
return possibleConstructorReturn(this, (TokenizationError.__proto__ || Object.getPrototypeOf(TokenizationError)).call(this, { message: message }, token));
|
||||||
}
|
}
|
||||||
AssertionError.prototype = Object.create(Error.prototype);
|
|
||||||
AssertionError.prototype.constructor = AssertionError;
|
return TokenizationError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var ParseError = function (_TemplateError2) {
|
||||||
|
inherits(ParseError, _TemplateError2);
|
||||||
|
|
||||||
|
function ParseError(e, token) {
|
||||||
|
classCallCheck(this, ParseError);
|
||||||
|
|
||||||
|
var _this4 = possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, e, token));
|
||||||
|
|
||||||
|
assign(_this4, e);
|
||||||
|
_this4.originalError = e;
|
||||||
|
return _this4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParseError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var RenderError = function (_TemplateError3) {
|
||||||
|
inherits(RenderError, _TemplateError3);
|
||||||
|
|
||||||
|
function RenderError(e, tpl) {
|
||||||
|
classCallCheck(this, RenderError);
|
||||||
|
|
||||||
|
// return the original render error
|
||||||
|
if (e instanceof RenderError) {
|
||||||
|
var _ret;
|
||||||
|
|
||||||
|
return _ret = e, possibleConstructorReturn(_this5, _ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
var _this5 = possibleConstructorReturn(this, (RenderError.__proto__ || Object.getPrototypeOf(RenderError)).call(this, e, tpl.token));
|
||||||
|
|
||||||
|
assign(_this5, e);
|
||||||
|
_this5.originalError = e;
|
||||||
|
return _this5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RenderError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var RenderBreakError = function (_LiquidError2) {
|
||||||
|
inherits(RenderBreakError, _LiquidError2);
|
||||||
|
|
||||||
|
function RenderBreakError(message) {
|
||||||
|
classCallCheck(this, RenderBreakError);
|
||||||
|
return possibleConstructorReturn(this, (RenderBreakError.__proto__ || Object.getPrototypeOf(RenderBreakError)).call(this, message + ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
return RenderBreakError;
|
||||||
|
}(LiquidError);
|
||||||
|
|
||||||
|
var AssertionError = function (_LiquidError3) {
|
||||||
|
inherits(AssertionError, _LiquidError3);
|
||||||
|
|
||||||
|
function AssertionError(message) {
|
||||||
|
classCallCheck(this, AssertionError);
|
||||||
|
return possibleConstructorReturn(this, (AssertionError.__proto__ || Object.getPrototypeOf(AssertionError)).call(this, message + ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
return AssertionError;
|
||||||
|
}(LiquidError);
|
||||||
|
|
||||||
function mkContext(input, line) {
|
function mkContext(input, line) {
|
||||||
var lines = input.split('\n');
|
var lines = input.split('\n');
|
||||||
@@ -1090,8 +1133,8 @@ function assert (predicate, message) {
|
|||||||
var Scope = {
|
var Scope = {
|
||||||
getAll: function getAll() {
|
getAll: function getAll() {
|
||||||
return this.contexts.reduce(function (ctx, val) {
|
return this.contexts.reduce(function (ctx, val) {
|
||||||
return Object.assign(ctx, val);
|
return assign(ctx, val);
|
||||||
}, Object.create(null));
|
}, create(null));
|
||||||
},
|
},
|
||||||
get: function get(path$$1) {
|
get: function get(path$$1) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -1262,7 +1305,7 @@ function factory(ctx, opts) {
|
|||||||
blocks: {},
|
blocks: {},
|
||||||
root: []
|
root: []
|
||||||
};
|
};
|
||||||
var scope = Object.create(Scope);
|
var scope = create(Scope);
|
||||||
scope.opts = assign(defaultOptions, opts);
|
scope.opts = assign(defaultOptions, opts);
|
||||||
scope.contexts = [ctx || {}];
|
scope.contexts = [ctx || {}];
|
||||||
return scope;
|
return scope;
|
||||||
@@ -1773,7 +1816,7 @@ var render = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Render () {
|
function Render () {
|
||||||
var instance = Object.create(render);
|
var instance = create(render);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1834,7 +1877,7 @@ function Tag () {
|
|||||||
|
|
||||||
var tagImpl = tagImpls[this.name];
|
var tagImpl = tagImpls[this.name];
|
||||||
assert(tagImpl, 'tag ' + this.name + ' not found');
|
assert(tagImpl, 'tag ' + this.name + ' not found');
|
||||||
this.tagImpl = Object.create(tagImpl);
|
this.tagImpl = create(tagImpl);
|
||||||
if (this.tagImpl.parse) {
|
if (this.tagImpl.parse) {
|
||||||
this.tagImpl.parse(token, tokens);
|
this.tagImpl.parse(token, tokens);
|
||||||
}
|
}
|
||||||
@@ -1846,7 +1889,7 @@ function Tag () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function construct(token, tokens) {
|
function construct(token, tokens) {
|
||||||
var instance = Object.create(_tagInstance);
|
var instance = create(_tagInstance);
|
||||||
instance.parse(token, tokens);
|
instance.parse(token, tokens);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@@ -1913,7 +1956,7 @@ function Filter (options) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function construct(str) {
|
function construct(str) {
|
||||||
var instance = Object.create(_filterInstance);
|
var instance = create(_filterInstance);
|
||||||
return instance.parse(str);
|
return instance.parse(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2022,7 +2065,7 @@ function Parser (Tag, Filter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseStream(tokens) {
|
function parseStream(tokens) {
|
||||||
var s = Object.create(stream);
|
var s = create(stream);
|
||||||
return s.init(tokens);
|
return s.init(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2073,7 +2116,7 @@ function mapSeries(iterable, iteratee) {
|
|||||||
|
|
||||||
function For (liquid, Liquid) {
|
function For (liquid, Liquid) {
|
||||||
var render = function () {
|
var render = function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash$$1) {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
var collection, offset, limit, contexts, html, finished;
|
var collection, offset, limit, contexts, html, finished;
|
||||||
@@ -2102,8 +2145,8 @@ function For (liquid, Liquid) {
|
|||||||
return _context2.abrupt('return', liquid.renderer.renderTemplates(this.elseTemplates, scope));
|
return _context2.abrupt('return', liquid.renderer.renderTemplates(this.elseTemplates, scope));
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
offset = hash.offset || 0;
|
offset = hash$$1.offset || 0;
|
||||||
limit = hash.limit === undefined ? collection.length : hash.limit;
|
limit = hash$$1.limit === undefined ? collection.length : hash$$1.limit;
|
||||||
|
|
||||||
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
collection = collection.slice(offset, offset + limit);
|
||||||
@@ -2203,8 +2246,7 @@ function For (liquid, Liquid) {
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
var RenderBreakError = Liquid.Types.RenderBreakError;
|
var RenderBreakError = Liquid.Types.RenderBreakError;
|
||||||
var lexical = Liquid.lexical;
|
var re = new RegExp('^(' + identifier.source + ')\\s+in\\s+' + ('(' + value.source + ')') + ('(?:\\s+' + hash.source + ')*') + '(?:\\s+(reversed))?' + ('(?:\\s+' + hash.source + ')*$'));
|
||||||
var re = new RegExp('^(' + lexical.identifier.source + ')\\s+in\\s+' + ('(' + lexical.value.source + ')') + ('(?:\\s+' + lexical.hash.source + ')*') + '(?:\\s+(reversed))?' + ('(?:\\s+' + lexical.hash.source + ')*$'));
|
|
||||||
|
|
||||||
liquid.registerTag('for', { parse: parse, render: render });
|
liquid.registerTag('for', { parse: parse, render: render });
|
||||||
|
|
||||||
@@ -2238,8 +2280,7 @@ function For (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Assign (liquid, Liquid) {
|
function Assign (liquid, Liquid) {
|
||||||
var rIdentifier = Liquid.lexical.identifier;
|
var re = new RegExp('(' + identifier.source + ')\\s*=(.*)');
|
||||||
var re = new RegExp('(' + rIdentifier.source + ')\\s*=(.*)');
|
|
||||||
var AssignScope = Liquid.Types.AssignScope;
|
var AssignScope = Liquid.Types.AssignScope;
|
||||||
|
|
||||||
|
|
||||||
@@ -2251,7 +2292,7 @@ function Assign (liquid, Liquid) {
|
|||||||
this.value = match[2];
|
this.value = match[2];
|
||||||
},
|
},
|
||||||
render: function render(scope) {
|
render: function render(scope) {
|
||||||
var ctx = Object.create(AssignScope);
|
var ctx = create(AssignScope);
|
||||||
ctx[this.key] = liquid.evalValue(this.value, scope);
|
ctx[this.key] = liquid.evalValue(this.value, scope);
|
||||||
scope.push(ctx);
|
scope.push(ctx);
|
||||||
return Promise.resolve('');
|
return Promise.resolve('');
|
||||||
@@ -2260,8 +2301,7 @@ function Assign (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Capture (liquid, Liquid) {
|
function Capture (liquid, Liquid) {
|
||||||
var rIdentifier = Liquid.lexical.identifier;
|
var re = new RegExp('(' + identifier.source + ')');
|
||||||
var re = new RegExp('(' + rIdentifier.source + ')');
|
|
||||||
var CaptureScope = Liquid.Types.CaptureScope;
|
var CaptureScope = Liquid.Types.CaptureScope;
|
||||||
|
|
||||||
|
|
||||||
@@ -2286,7 +2326,7 @@ function Capture (liquid, Liquid) {
|
|||||||
stream.start();
|
stream.start();
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var html, ctx;
|
var html, ctx;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2297,7 +2337,7 @@ function Capture (liquid, Liquid) {
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
html = _context.sent;
|
html = _context.sent;
|
||||||
ctx = Object.create(CaptureScope);
|
ctx = create(CaptureScope);
|
||||||
|
|
||||||
ctx[this.variable] = html;
|
ctx[this.variable] = html;
|
||||||
scope.push(ctx);
|
scope.push(ctx);
|
||||||
@@ -2379,8 +2419,7 @@ function Comment (liquid) {
|
|||||||
var staticFileRE = /[^\s,]+/;
|
var staticFileRE = /[^\s,]+/;
|
||||||
|
|
||||||
function Include (liquid, Liquid) {
|
function Include (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
var withRE = new RegExp('with\\s+(' + value.source + ')');
|
||||||
var withRE = new RegExp('with\\s+(' + lexical.value.source + ')');
|
|
||||||
|
|
||||||
liquid.registerTag('include', {
|
liquid.registerTag('include', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
@@ -2389,7 +2428,7 @@ function Include (liquid, Liquid) {
|
|||||||
this.staticValue = match[0];
|
this.staticValue = match[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
match = lexical.value.exec(token.args);
|
match = value.exec(token.args);
|
||||||
if (match) {
|
if (match) {
|
||||||
this.value = match[0];
|
this.value = match[0];
|
||||||
}
|
}
|
||||||
@@ -2400,7 +2439,7 @@ function Include (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var filepath, template, originBlocks, originBlockMode, templates, html;
|
var filepath, template, originBlocks, originBlockMode, templates, html;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2413,7 +2452,7 @@ function Include (liquid, Liquid) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lexical.quotedLine.exec(this.value)) {
|
if (!quotedLine.exec(this.value)) {
|
||||||
_context.next = 9;
|
_context.next = 9;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2447,7 +2486,7 @@ function Include (liquid, Liquid) {
|
|||||||
scope.opts.blocks = {};
|
scope.opts.blocks = {};
|
||||||
scope.opts.blockMode = 'output';
|
scope.opts.blockMode = 'output';
|
||||||
if (this.with) {
|
if (this.with) {
|
||||||
hash[filepath] = Liquid.evalValue(this.with, scope);
|
hash$$1[filepath] = Liquid.evalValue(this.with, scope);
|
||||||
}
|
}
|
||||||
_context.next = 21;
|
_context.next = 21;
|
||||||
return liquid.getTemplate(filepath, scope.opts.root);
|
return liquid.getTemplate(filepath, scope.opts.root);
|
||||||
@@ -2455,14 +2494,14 @@ function Include (liquid, Liquid) {
|
|||||||
case 21:
|
case 21:
|
||||||
templates = _context.sent;
|
templates = _context.sent;
|
||||||
|
|
||||||
scope.push(hash);
|
scope.push(hash$$1);
|
||||||
_context.next = 25;
|
_context.next = 25;
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
|
|
||||||
case 25:
|
case 25:
|
||||||
html = _context.sent;
|
html = _context.sent;
|
||||||
|
|
||||||
scope.pop(hash);
|
scope.pop(hash$$1);
|
||||||
scope.opts.blocks = originBlocks;
|
scope.opts.blocks = originBlocks;
|
||||||
scope.opts.blockMode = originBlockMode;
|
scope.opts.blockMode = originBlockMode;
|
||||||
return _context.abrupt('return', html);
|
return _context.abrupt('return', html);
|
||||||
@@ -2485,7 +2524,6 @@ function Include (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Decrement (liquid, Liquid) {
|
function Decrement (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
|
||||||
var _Liquid$Types = Liquid.Types,
|
var _Liquid$Types = Liquid.Types,
|
||||||
CaptureScope = _Liquid$Types.CaptureScope,
|
CaptureScope = _Liquid$Types.CaptureScope,
|
||||||
AssignScope = _Liquid$Types.AssignScope,
|
AssignScope = _Liquid$Types.AssignScope,
|
||||||
@@ -2494,16 +2532,17 @@ function Decrement (liquid, Liquid) {
|
|||||||
|
|
||||||
liquid.registerTag('decrement', {
|
liquid.registerTag('decrement', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(identifier);
|
||||||
assert(match, 'illegal identifier ' + token.args);
|
assert(match, 'illegal identifier ' + token.args);
|
||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var context = scope.findContextFor(this.variable, function (ctx) {
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope && Object.getPrototypeOf(ctx) !== AssignScope;
|
var proto = Object.getPrototypeOf(ctx);
|
||||||
|
return proto !== CaptureScope && proto !== AssignScope;
|
||||||
});
|
});
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(DecrementScope);
|
context = create(DecrementScope);
|
||||||
scope.unshift(context);
|
scope.unshift(context);
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
@@ -2515,9 +2554,8 @@ function Decrement (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Cycle (liquid, Liquid) {
|
function Cycle (liquid, Liquid) {
|
||||||
var rValue = Liquid.lexical.value;
|
var groupRE = new RegExp('^(?:(' + value.source + ')\\s*:\\s*)?(.*)$');
|
||||||
var groupRE = new RegExp('^(?:(' + rValue.source + ')\\s*:\\s*)?(.*)$');
|
var candidatesRE = new RegExp(value.source, 'g');
|
||||||
var candidatesRE = new RegExp(rValue.source, 'g');
|
|
||||||
|
|
||||||
liquid.registerTag('cycle', {
|
liquid.registerTag('cycle', {
|
||||||
|
|
||||||
@@ -2536,7 +2574,7 @@ function Cycle (liquid, Liquid) {
|
|||||||
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var group = Liquid.evalValue(this.group, scope);
|
var group = Liquid.evalValue(this.group, scope);
|
||||||
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
||||||
|
|
||||||
@@ -2624,7 +2662,6 @@ function If (liquid, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Increment (liquid, Liquid) {
|
function Increment (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
|
||||||
var _Liquid$Types = Liquid.Types,
|
var _Liquid$Types = Liquid.Types,
|
||||||
CaptureScope = _Liquid$Types.CaptureScope,
|
CaptureScope = _Liquid$Types.CaptureScope,
|
||||||
AssignScope = _Liquid$Types.AssignScope,
|
AssignScope = _Liquid$Types.AssignScope,
|
||||||
@@ -2633,16 +2670,17 @@ function Increment (liquid, Liquid) {
|
|||||||
|
|
||||||
liquid.registerTag('increment', {
|
liquid.registerTag('increment', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(identifier);
|
||||||
assert(match, 'illegal identifier ' + token.args);
|
assert(match, 'illegal identifier ' + token.args);
|
||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var context = scope.findContextFor(this.variable, function (ctx) {
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope && Object.getPrototypeOf(ctx) !== AssignScope;
|
var proto = Object.getPrototypeOf(ctx);
|
||||||
|
return proto !== CaptureScope && proto !== AssignScope;
|
||||||
});
|
});
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(IncrementScope);
|
context = create(IncrementScope);
|
||||||
scope.unshift(context);
|
scope.unshift(context);
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
@@ -2662,7 +2700,6 @@ function Increment (liquid, Liquid) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Layout (liquid, Liquid) {
|
function Layout (liquid, Liquid) {
|
||||||
var rValue = Liquid.lexical.value;
|
|
||||||
var staticFileRE = /\S+/;
|
var staticFileRE = /\S+/;
|
||||||
|
|
||||||
liquid.registerTag('layout', {
|
liquid.registerTag('layout', {
|
||||||
@@ -2672,7 +2709,7 @@ function Layout (liquid, Liquid) {
|
|||||||
this.staticLayout = match[0];
|
this.staticLayout = match[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
match = rValue.exec(token.args);
|
match = value.exec(token.args);
|
||||||
if (match) {
|
if (match) {
|
||||||
this.layout = match[0];
|
this.layout = match[0];
|
||||||
}
|
}
|
||||||
@@ -2680,7 +2717,7 @@ function Layout (liquid, Liquid) {
|
|||||||
this.tpls = liquid.parser.parse(remainTokens);
|
this.tpls = liquid.parser.parse(remainTokens);
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var layout, html, templates, partial;
|
var layout, html, templates, partial;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2707,7 +2744,7 @@ function Layout (liquid, Liquid) {
|
|||||||
case 9:
|
case 9:
|
||||||
templates = _context.sent;
|
templates = _context.sent;
|
||||||
|
|
||||||
scope.push(hash);
|
scope.push(hash$$1);
|
||||||
scope.opts.blockMode = 'output';
|
scope.opts.blockMode = 'output';
|
||||||
_context.next = 14;
|
_context.next = 14;
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
@@ -2715,7 +2752,7 @@ function Layout (liquid, Liquid) {
|
|||||||
case 14:
|
case 14:
|
||||||
partial = _context.sent;
|
partial = _context.sent;
|
||||||
|
|
||||||
scope.pop(hash);
|
scope.pop(hash$$1);
|
||||||
return _context.abrupt('return', partial);
|
return _context.abrupt('return', partial);
|
||||||
|
|
||||||
case 17:
|
case 17:
|
||||||
@@ -2831,8 +2868,7 @@ function Raw (liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Tablerow (liquid, Liquid) {
|
function Tablerow (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
var re = new RegExp('^(' + identifier.source + ')\\s+in\\s+' + ('(' + value.source + ')') + ('(?:\\s+' + hash.source + ')*$'));
|
||||||
var re = new RegExp('^(' + lexical.identifier.source + ')\\s+in\\s+' + ('(' + lexical.value.source + ')') + ('(?:\\s+' + lexical.hash.source + ')*$'));
|
|
||||||
|
|
||||||
liquid.registerTag('tablerow', {
|
liquid.registerTag('tablerow', {
|
||||||
|
|
||||||
@@ -2861,7 +2897,7 @@ function Tablerow (liquid, Liquid) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash$$1) {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
var collection, offset, limit, cols, contexts, row, html;
|
var collection, offset, limit, cols, contexts, row, html;
|
||||||
@@ -2870,12 +2906,12 @@ function Tablerow (liquid, Liquid) {
|
|||||||
switch (_context2.prev = _context2.next) {
|
switch (_context2.prev = _context2.next) {
|
||||||
case 0:
|
case 0:
|
||||||
collection = Liquid.evalExp(this.collection, scope) || [];
|
collection = Liquid.evalExp(this.collection, scope) || [];
|
||||||
offset = hash.offset || 0;
|
offset = hash$$1.offset || 0;
|
||||||
limit = hash.limit === undefined ? collection.length : hash.limit;
|
limit = hash$$1.limit === undefined ? collection.length : hash$$1.limit;
|
||||||
|
|
||||||
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
collection = collection.slice(offset, offset + limit);
|
||||||
cols = hash.cols || collection.length;
|
cols = hash$$1.cols || collection.length;
|
||||||
contexts = collection.map(function (item, i) {
|
contexts = collection.map(function (item, i) {
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
ctx[_this2.variable] = item;
|
ctx[_this2.variable] = item;
|
||||||
@@ -2998,17 +3034,22 @@ function tags (engine, Liquid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
||||||
var monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
||||||
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
var dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
var monthNamesShort = monthNames.map(abbr);
|
||||||
|
var dayNamesShort = dayNames.map(abbr);
|
||||||
var suffixes = {
|
var suffixes = {
|
||||||
1: 'st',
|
1: 'st',
|
||||||
2: 'nd',
|
2: 'nd',
|
||||||
3: 'rd',
|
3: 'rd',
|
||||||
'default': 'th'
|
'default': 'th'
|
||||||
|
};
|
||||||
|
|
||||||
// prototype extensions
|
function abbr(str) {
|
||||||
};var _date = {
|
return str.slice(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// prototype extensions
|
||||||
|
var _date = {
|
||||||
daysInMonth: function daysInMonth(d) {
|
daysInMonth: function daysInMonth(d) {
|
||||||
var feb = _date.isLeapYear(d) ? 29 : 28;
|
var feb = _date.isLeapYear(d) ? 29 : 28;
|
||||||
return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||||
@@ -3396,14 +3437,14 @@ function registerAll(liquid) {
|
|||||||
registerAll.filters = filters;
|
registerAll.filters = filters;
|
||||||
|
|
||||||
var _engine = {
|
var _engine = {
|
||||||
init: function init(tag, filter$$1, options) {
|
init: function init(tag, filter, options) {
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.cache = {};
|
this.cache = {};
|
||||||
}
|
}
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.filter = filter$$1;
|
this.filter = filter;
|
||||||
this.parser = Parser(tag, filter$$1);
|
this.parser = Parser(tag, filter);
|
||||||
this.renderer = Render();
|
this.renderer = Render();
|
||||||
|
|
||||||
tags(this, Liquid);
|
tags(this, Liquid);
|
||||||
@@ -3481,8 +3522,8 @@ var _engine = {
|
|||||||
var tpl = this.parser.parseValue(str.trim());
|
var tpl = this.parser.parseValue(str.trim());
|
||||||
return this.renderer.evalValue(tpl, scope);
|
return this.renderer.evalValue(tpl, scope);
|
||||||
},
|
},
|
||||||
registerFilter: function registerFilter(name, filter$$1) {
|
registerFilter: function registerFilter(name, filter) {
|
||||||
return this.filter.register(name, filter$$1);
|
return this.filter.register(name, filter);
|
||||||
},
|
},
|
||||||
registerTag: function registerTag(name, tag) {
|
registerTag: function registerTag(name, tag) {
|
||||||
return this.tag.register(name, tag);
|
return this.tag.register(name, tag);
|
||||||
@@ -3638,7 +3679,7 @@ var _engine = {
|
|||||||
}(),
|
}(),
|
||||||
respectCache: function () {
|
respectCache: function () {
|
||||||
var _ref8 = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(key, getter) {
|
var _ref8 = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(key, getter) {
|
||||||
var cacheEnabled, value$$1;
|
var cacheEnabled, value;
|
||||||
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (_context8.prev = _context8.next) {
|
switch (_context8.prev = _context8.next) {
|
||||||
@@ -3657,12 +3698,12 @@ var _engine = {
|
|||||||
return getter();
|
return getter();
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
value$$1 = _context8.sent;
|
value = _context8.sent;
|
||||||
|
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
this.cache[key] = value$$1;
|
this.cache[key] = value;
|
||||||
}
|
}
|
||||||
return _context8.abrupt('return', value$$1);
|
return _context8.abrupt('return', value);
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
case 'end':
|
case 'end':
|
||||||
@@ -3691,9 +3732,9 @@ var _engine = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeStringArray(value$$1) {
|
function normalizeStringArray(value) {
|
||||||
if (Array.isArray(value$$1)) return value$$1;
|
if (Array.isArray(value)) return value;
|
||||||
if (isString(value$$1)) return [value$$1];
|
if (isString(value)) return [value];
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3713,7 +3754,7 @@ function Liquid(options) {
|
|||||||
}, options);
|
}, options);
|
||||||
options.root = normalizeStringArray(options.root);
|
options.root = normalizeStringArray(options.root);
|
||||||
|
|
||||||
var engine = Object.create(_engine);
|
var engine = create(_engine);
|
||||||
engine.init(Tag(), Filter(options), options);
|
engine.init(Tag(), Filter(options), options);
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
@@ -3727,12 +3768,11 @@ Liquid.Types = {
|
|||||||
TokenizationError: TokenizationError,
|
TokenizationError: TokenizationError,
|
||||||
RenderBreakError: RenderBreakError,
|
RenderBreakError: RenderBreakError,
|
||||||
AssertionError: AssertionError,
|
AssertionError: AssertionError,
|
||||||
AssignScope: Object.create(null),
|
AssignScope: {},
|
||||||
CaptureScope: Object.create(null),
|
CaptureScope: {},
|
||||||
IncrementScope: Object.create(null),
|
IncrementScope: {},
|
||||||
DecrementScope: Object.create(null)
|
DecrementScope: {}
|
||||||
};
|
};
|
||||||
Liquid.lexical = lexical;
|
|
||||||
|
|
||||||
module.exports = Liquid;
|
module.exports = Liquid;
|
||||||
//# sourceMappingURL=liquid.common.js.map
|
//# sourceMappingURL=liquid.common.js.map
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+206
-166
@@ -44,6 +44,36 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var classCallCheck = function (instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var inherits = function (subClass, superClass) {
|
||||||
|
if (typeof superClass !== "function" && superClass !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||||
|
constructor: {
|
||||||
|
value: subClass,
|
||||||
|
enumerable: false,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
|
||||||
|
};
|
||||||
|
|
||||||
|
var possibleConstructorReturn = function (self, call) {
|
||||||
|
if (!self) {
|
||||||
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||||
|
}
|
||||||
|
|
||||||
|
return call && (typeof call === "object" || typeof call === "function") ? call : self;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copyright (c) 2014-present, Facebook, Inc.
|
* Copyright (c) 2014-present, Facebook, Inc.
|
||||||
*
|
*
|
||||||
@@ -770,6 +800,10 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create(proto) {
|
||||||
|
return Object.create(proto);
|
||||||
|
}
|
||||||
|
|
||||||
function isNil(value) {
|
function isNil(value) {
|
||||||
return value === null || value === undefined;
|
return value === null || value === undefined;
|
||||||
}
|
}
|
||||||
@@ -922,10 +956,6 @@
|
|||||||
return literalLine.test(str);
|
return literalLine.test(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRange(str) {
|
|
||||||
return rangeLine.test(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function isVariable(str) {
|
function isVariable(str) {
|
||||||
return variableLine.test(str);
|
return variableLine.test(str);
|
||||||
}
|
}
|
||||||
@@ -950,104 +980,117 @@
|
|||||||
throw new TypeError('cannot parse \'' + str + '\' as literal');
|
throw new TypeError('cannot parse \'' + str + '\' as literal');
|
||||||
}
|
}
|
||||||
|
|
||||||
var lexical = ({
|
var LiquidError = function (_Error) {
|
||||||
quoted: quoted,
|
inherits(LiquidError, _Error);
|
||||||
quoteBalanced: quoteBalanced,
|
|
||||||
integer: integer,
|
|
||||||
number: number,
|
|
||||||
bool: bool,
|
|
||||||
identifier: identifier,
|
|
||||||
subscript: subscript,
|
|
||||||
literal: literal,
|
|
||||||
variable: variable,
|
|
||||||
rangeLimit: rangeLimit,
|
|
||||||
range: range$1,
|
|
||||||
rangeCapture: rangeCapture,
|
|
||||||
value: value,
|
|
||||||
hash: hash,
|
|
||||||
hashCapture: hashCapture,
|
|
||||||
tagLine: tagLine,
|
|
||||||
literalLine: literalLine,
|
|
||||||
variableLine: variableLine,
|
|
||||||
numberLine: numberLine,
|
|
||||||
boolLine: boolLine,
|
|
||||||
quotedLine: quotedLine,
|
|
||||||
rangeLine: rangeLine,
|
|
||||||
integerLine: integerLine,
|
|
||||||
valueDeclaration: valueDeclaration,
|
|
||||||
valueList: valueList,
|
|
||||||
filter: filter,
|
|
||||||
filterCapture: filterCapture,
|
|
||||||
filterLine: filterLine,
|
|
||||||
operators: operators,
|
|
||||||
isInteger: isInteger,
|
|
||||||
isLiteral: isLiteral,
|
|
||||||
isRange: isRange,
|
|
||||||
isVariable: isVariable,
|
|
||||||
matchValue: matchValue,
|
|
||||||
parseLiteral: parseLiteral
|
|
||||||
});
|
|
||||||
|
|
||||||
function initError() {
|
function LiquidError(message) {
|
||||||
this.name = this.constructor.name;
|
classCallCheck(this, LiquidError);
|
||||||
if (Error.captureStackTrace) {
|
|
||||||
Error.captureStackTrace(this, this.constructor);
|
var _this = possibleConstructorReturn(this, (LiquidError.__proto__ || Object.getPrototypeOf(LiquidError)).call(this, message));
|
||||||
|
|
||||||
|
_this.name = _this.constructor.name;
|
||||||
|
if (typeof Error.captureStackTrace === 'function') {
|
||||||
|
Error.captureStackTrace(_this, _this.constructor);
|
||||||
|
} else {
|
||||||
|
_this.stack = new Error(message).stack;
|
||||||
|
}
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
function initLiquidError(err, token) {
|
return LiquidError;
|
||||||
initError.call(this);
|
}(Error);
|
||||||
|
|
||||||
this.input = token.input;
|
var TemplateError = function (_LiquidError) {
|
||||||
this.line = token.line;
|
inherits(TemplateError, _LiquidError);
|
||||||
this.file = token.file;
|
|
||||||
|
|
||||||
var context = mkContext(token.input, token.line);
|
function TemplateError(err, token) {
|
||||||
this.message = mkMessage(err.message, token);
|
classCallCheck(this, TemplateError);
|
||||||
this.stack = context + '\n' + (this.stack || this.message) + (err.stack ? '\nFrom ' + err.stack : '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function TokenizationError(message, token) {
|
var _this2 = possibleConstructorReturn(this, (TemplateError.__proto__ || Object.getPrototypeOf(TemplateError)).call(this));
|
||||||
initLiquidError.call(this, { message: message }, token);
|
|
||||||
}
|
|
||||||
TokenizationError.prototype = Object.create(Error.prototype);
|
|
||||||
TokenizationError.prototype.constructor = TokenizationError;
|
|
||||||
|
|
||||||
function ParseError(e, token) {
|
_this2.input = token.input;
|
||||||
assign(this, e);
|
_this2.line = token.line;
|
||||||
this.originalError = e;
|
_this2.file = token.file;
|
||||||
|
_this2.message = mkMessage(err.message, token);
|
||||||
initLiquidError.call(this, e, token);
|
var context = mkContext(token.input, token.line);
|
||||||
}
|
_this2.stack = context + '\n' + (_this2.stack || _this2.message) + (err.stack ? '\nFrom ' + err.stack : '');
|
||||||
ParseError.prototype = Object.create(Error.prototype);
|
return _this2;
|
||||||
ParseError.prototype.constructor = ParseError;
|
|
||||||
|
|
||||||
function RenderError(e, tpl) {
|
|
||||||
// return the original render error
|
|
||||||
if (e instanceof RenderError) {
|
|
||||||
return e;
|
|
||||||
}
|
}
|
||||||
assign(this, e);
|
|
||||||
this.originalError = e;
|
|
||||||
|
|
||||||
initLiquidError.call(this, e, tpl.token);
|
return TemplateError;
|
||||||
}
|
}(LiquidError);
|
||||||
RenderError.prototype = Object.create(Error.prototype);
|
|
||||||
RenderError.prototype.constructor = RenderError;
|
|
||||||
|
|
||||||
function RenderBreakError(message) {
|
var TokenizationError = function (_TemplateError) {
|
||||||
initError.call(this);
|
inherits(TokenizationError, _TemplateError);
|
||||||
this.message = message + '';
|
|
||||||
}
|
|
||||||
RenderBreakError.prototype = Object.create(Error.prototype);
|
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError;
|
|
||||||
|
|
||||||
function AssertionError(message) {
|
function TokenizationError(message, token) {
|
||||||
initError.call(this);
|
classCallCheck(this, TokenizationError);
|
||||||
this.message = message + '';
|
return possibleConstructorReturn(this, (TokenizationError.__proto__ || Object.getPrototypeOf(TokenizationError)).call(this, { message: message }, token));
|
||||||
}
|
}
|
||||||
AssertionError.prototype = Object.create(Error.prototype);
|
|
||||||
AssertionError.prototype.constructor = AssertionError;
|
return TokenizationError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var ParseError = function (_TemplateError2) {
|
||||||
|
inherits(ParseError, _TemplateError2);
|
||||||
|
|
||||||
|
function ParseError(e, token) {
|
||||||
|
classCallCheck(this, ParseError);
|
||||||
|
|
||||||
|
var _this4 = possibleConstructorReturn(this, (ParseError.__proto__ || Object.getPrototypeOf(ParseError)).call(this, e, token));
|
||||||
|
|
||||||
|
assign(_this4, e);
|
||||||
|
_this4.originalError = e;
|
||||||
|
return _this4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ParseError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var RenderError = function (_TemplateError3) {
|
||||||
|
inherits(RenderError, _TemplateError3);
|
||||||
|
|
||||||
|
function RenderError(e, tpl) {
|
||||||
|
classCallCheck(this, RenderError);
|
||||||
|
|
||||||
|
// return the original render error
|
||||||
|
if (e instanceof RenderError) {
|
||||||
|
var _ret;
|
||||||
|
|
||||||
|
return _ret = e, possibleConstructorReturn(_this5, _ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
var _this5 = possibleConstructorReturn(this, (RenderError.__proto__ || Object.getPrototypeOf(RenderError)).call(this, e, tpl.token));
|
||||||
|
|
||||||
|
assign(_this5, e);
|
||||||
|
_this5.originalError = e;
|
||||||
|
return _this5;
|
||||||
|
}
|
||||||
|
|
||||||
|
return RenderError;
|
||||||
|
}(TemplateError);
|
||||||
|
|
||||||
|
var RenderBreakError = function (_LiquidError2) {
|
||||||
|
inherits(RenderBreakError, _LiquidError2);
|
||||||
|
|
||||||
|
function RenderBreakError(message) {
|
||||||
|
classCallCheck(this, RenderBreakError);
|
||||||
|
return possibleConstructorReturn(this, (RenderBreakError.__proto__ || Object.getPrototypeOf(RenderBreakError)).call(this, message + ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
return RenderBreakError;
|
||||||
|
}(LiquidError);
|
||||||
|
|
||||||
|
var AssertionError = function (_LiquidError3) {
|
||||||
|
inherits(AssertionError, _LiquidError3);
|
||||||
|
|
||||||
|
function AssertionError(message) {
|
||||||
|
classCallCheck(this, AssertionError);
|
||||||
|
return possibleConstructorReturn(this, (AssertionError.__proto__ || Object.getPrototypeOf(AssertionError)).call(this, message + ''));
|
||||||
|
}
|
||||||
|
|
||||||
|
return AssertionError;
|
||||||
|
}(LiquidError);
|
||||||
|
|
||||||
function mkContext(input, line) {
|
function mkContext(input, line) {
|
||||||
var lines = input.split('\n');
|
var lines = input.split('\n');
|
||||||
@@ -1089,8 +1132,8 @@
|
|||||||
var Scope = {
|
var Scope = {
|
||||||
getAll: function getAll() {
|
getAll: function getAll() {
|
||||||
return this.contexts.reduce(function (ctx, val) {
|
return this.contexts.reduce(function (ctx, val) {
|
||||||
return Object.assign(ctx, val);
|
return assign(ctx, val);
|
||||||
}, Object.create(null));
|
}, create(null));
|
||||||
},
|
},
|
||||||
get: function get(path) {
|
get: function get(path) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -1261,7 +1304,7 @@
|
|||||||
blocks: {},
|
blocks: {},
|
||||||
root: []
|
root: []
|
||||||
};
|
};
|
||||||
var scope = Object.create(Scope);
|
var scope = create(Scope);
|
||||||
scope.opts = assign(defaultOptions, opts);
|
scope.opts = assign(defaultOptions, opts);
|
||||||
scope.contexts = [ctx || {}];
|
scope.contexts = [ctx || {}];
|
||||||
return scope;
|
return scope;
|
||||||
@@ -1776,7 +1819,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function Render () {
|
function Render () {
|
||||||
var instance = Object.create(render);
|
var instance = create(render);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1837,7 +1880,7 @@
|
|||||||
|
|
||||||
var tagImpl = tagImpls[this.name];
|
var tagImpl = tagImpls[this.name];
|
||||||
assert(tagImpl, 'tag ' + this.name + ' not found');
|
assert(tagImpl, 'tag ' + this.name + ' not found');
|
||||||
this.tagImpl = Object.create(tagImpl);
|
this.tagImpl = create(tagImpl);
|
||||||
if (this.tagImpl.parse) {
|
if (this.tagImpl.parse) {
|
||||||
this.tagImpl.parse(token, tokens);
|
this.tagImpl.parse(token, tokens);
|
||||||
}
|
}
|
||||||
@@ -1849,7 +1892,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function construct(token, tokens) {
|
function construct(token, tokens) {
|
||||||
var instance = Object.create(_tagInstance);
|
var instance = create(_tagInstance);
|
||||||
instance.parse(token, tokens);
|
instance.parse(token, tokens);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
@@ -1916,7 +1959,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
function construct(str) {
|
function construct(str) {
|
||||||
var instance = Object.create(_filterInstance);
|
var instance = create(_filterInstance);
|
||||||
return instance.parse(str);
|
return instance.parse(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2025,7 +2068,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseStream(tokens) {
|
function parseStream(tokens) {
|
||||||
var s = Object.create(stream);
|
var s = create(stream);
|
||||||
return s.init(tokens);
|
return s.init(tokens);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2076,7 +2119,7 @@
|
|||||||
|
|
||||||
function For (liquid, Liquid) {
|
function For (liquid, Liquid) {
|
||||||
var render = function () {
|
var render = function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash$$1) {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
var collection, offset, limit, contexts, html, finished;
|
var collection, offset, limit, contexts, html, finished;
|
||||||
@@ -2105,8 +2148,8 @@
|
|||||||
return _context2.abrupt('return', liquid.renderer.renderTemplates(this.elseTemplates, scope));
|
return _context2.abrupt('return', liquid.renderer.renderTemplates(this.elseTemplates, scope));
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
offset = hash.offset || 0;
|
offset = hash$$1.offset || 0;
|
||||||
limit = hash.limit === undefined ? collection.length : hash.limit;
|
limit = hash$$1.limit === undefined ? collection.length : hash$$1.limit;
|
||||||
|
|
||||||
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
collection = collection.slice(offset, offset + limit);
|
||||||
@@ -2206,8 +2249,7 @@
|
|||||||
}();
|
}();
|
||||||
|
|
||||||
var RenderBreakError = Liquid.Types.RenderBreakError;
|
var RenderBreakError = Liquid.Types.RenderBreakError;
|
||||||
var lexical = Liquid.lexical;
|
var re = new RegExp('^(' + identifier.source + ')\\s+in\\s+' + ('(' + value.source + ')') + ('(?:\\s+' + hash.source + ')*') + '(?:\\s+(reversed))?' + ('(?:\\s+' + hash.source + ')*$'));
|
||||||
var re = new RegExp('^(' + lexical.identifier.source + ')\\s+in\\s+' + ('(' + lexical.value.source + ')') + ('(?:\\s+' + lexical.hash.source + ')*') + '(?:\\s+(reversed))?' + ('(?:\\s+' + lexical.hash.source + ')*$'));
|
|
||||||
|
|
||||||
liquid.registerTag('for', { parse: parse, render: render });
|
liquid.registerTag('for', { parse: parse, render: render });
|
||||||
|
|
||||||
@@ -2241,8 +2283,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Assign (liquid, Liquid) {
|
function Assign (liquid, Liquid) {
|
||||||
var rIdentifier = Liquid.lexical.identifier;
|
var re = new RegExp('(' + identifier.source + ')\\s*=(.*)');
|
||||||
var re = new RegExp('(' + rIdentifier.source + ')\\s*=(.*)');
|
|
||||||
var AssignScope = Liquid.Types.AssignScope;
|
var AssignScope = Liquid.Types.AssignScope;
|
||||||
|
|
||||||
|
|
||||||
@@ -2254,7 +2295,7 @@
|
|||||||
this.value = match[2];
|
this.value = match[2];
|
||||||
},
|
},
|
||||||
render: function render(scope) {
|
render: function render(scope) {
|
||||||
var ctx = Object.create(AssignScope);
|
var ctx = create(AssignScope);
|
||||||
ctx[this.key] = liquid.evalValue(this.value, scope);
|
ctx[this.key] = liquid.evalValue(this.value, scope);
|
||||||
scope.push(ctx);
|
scope.push(ctx);
|
||||||
return Promise.resolve('');
|
return Promise.resolve('');
|
||||||
@@ -2263,8 +2304,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Capture (liquid, Liquid) {
|
function Capture (liquid, Liquid) {
|
||||||
var rIdentifier = Liquid.lexical.identifier;
|
var re = new RegExp('(' + identifier.source + ')');
|
||||||
var re = new RegExp('(' + rIdentifier.source + ')');
|
|
||||||
var CaptureScope = Liquid.Types.CaptureScope;
|
var CaptureScope = Liquid.Types.CaptureScope;
|
||||||
|
|
||||||
|
|
||||||
@@ -2289,7 +2329,7 @@
|
|||||||
stream.start();
|
stream.start();
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var html, ctx;
|
var html, ctx;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2300,7 +2340,7 @@
|
|||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
html = _context.sent;
|
html = _context.sent;
|
||||||
ctx = Object.create(CaptureScope);
|
ctx = create(CaptureScope);
|
||||||
|
|
||||||
ctx[this.variable] = html;
|
ctx[this.variable] = html;
|
||||||
scope.push(ctx);
|
scope.push(ctx);
|
||||||
@@ -2382,8 +2422,7 @@
|
|||||||
var staticFileRE = /[^\s,]+/;
|
var staticFileRE = /[^\s,]+/;
|
||||||
|
|
||||||
function Include (liquid, Liquid) {
|
function Include (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
var withRE = new RegExp('with\\s+(' + value.source + ')');
|
||||||
var withRE = new RegExp('with\\s+(' + lexical.value.source + ')');
|
|
||||||
|
|
||||||
liquid.registerTag('include', {
|
liquid.registerTag('include', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
@@ -2392,7 +2431,7 @@
|
|||||||
this.staticValue = match[0];
|
this.staticValue = match[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
match = lexical.value.exec(token.args);
|
match = value.exec(token.args);
|
||||||
if (match) {
|
if (match) {
|
||||||
this.value = match[0];
|
this.value = match[0];
|
||||||
}
|
}
|
||||||
@@ -2403,7 +2442,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var filepath, template, originBlocks, originBlockMode, templates, html;
|
var filepath, template, originBlocks, originBlockMode, templates, html;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2416,7 +2455,7 @@
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lexical.quotedLine.exec(this.value)) {
|
if (!quotedLine.exec(this.value)) {
|
||||||
_context.next = 9;
|
_context.next = 9;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -2450,7 +2489,7 @@
|
|||||||
scope.opts.blocks = {};
|
scope.opts.blocks = {};
|
||||||
scope.opts.blockMode = 'output';
|
scope.opts.blockMode = 'output';
|
||||||
if (this.with) {
|
if (this.with) {
|
||||||
hash[filepath] = Liquid.evalValue(this.with, scope);
|
hash$$1[filepath] = Liquid.evalValue(this.with, scope);
|
||||||
}
|
}
|
||||||
_context.next = 21;
|
_context.next = 21;
|
||||||
return liquid.getTemplate(filepath, scope.opts.root);
|
return liquid.getTemplate(filepath, scope.opts.root);
|
||||||
@@ -2458,14 +2497,14 @@
|
|||||||
case 21:
|
case 21:
|
||||||
templates = _context.sent;
|
templates = _context.sent;
|
||||||
|
|
||||||
scope.push(hash);
|
scope.push(hash$$1);
|
||||||
_context.next = 25;
|
_context.next = 25;
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
|
|
||||||
case 25:
|
case 25:
|
||||||
html = _context.sent;
|
html = _context.sent;
|
||||||
|
|
||||||
scope.pop(hash);
|
scope.pop(hash$$1);
|
||||||
scope.opts.blocks = originBlocks;
|
scope.opts.blocks = originBlocks;
|
||||||
scope.opts.blockMode = originBlockMode;
|
scope.opts.blockMode = originBlockMode;
|
||||||
return _context.abrupt('return', html);
|
return _context.abrupt('return', html);
|
||||||
@@ -2488,7 +2527,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Decrement (liquid, Liquid) {
|
function Decrement (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
|
||||||
var _Liquid$Types = Liquid.Types,
|
var _Liquid$Types = Liquid.Types,
|
||||||
CaptureScope = _Liquid$Types.CaptureScope,
|
CaptureScope = _Liquid$Types.CaptureScope,
|
||||||
AssignScope = _Liquid$Types.AssignScope,
|
AssignScope = _Liquid$Types.AssignScope,
|
||||||
@@ -2497,16 +2535,17 @@
|
|||||||
|
|
||||||
liquid.registerTag('decrement', {
|
liquid.registerTag('decrement', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(identifier);
|
||||||
assert(match, 'illegal identifier ' + token.args);
|
assert(match, 'illegal identifier ' + token.args);
|
||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var context = scope.findContextFor(this.variable, function (ctx) {
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope && Object.getPrototypeOf(ctx) !== AssignScope;
|
var proto = Object.getPrototypeOf(ctx);
|
||||||
|
return proto !== CaptureScope && proto !== AssignScope;
|
||||||
});
|
});
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(DecrementScope);
|
context = create(DecrementScope);
|
||||||
scope.unshift(context);
|
scope.unshift(context);
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
@@ -2518,9 +2557,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Cycle (liquid, Liquid) {
|
function Cycle (liquid, Liquid) {
|
||||||
var rValue = Liquid.lexical.value;
|
var groupRE = new RegExp('^(?:(' + value.source + ')\\s*:\\s*)?(.*)$');
|
||||||
var groupRE = new RegExp('^(?:(' + rValue.source + ')\\s*:\\s*)?(.*)$');
|
var candidatesRE = new RegExp(value.source, 'g');
|
||||||
var candidatesRE = new RegExp(rValue.source, 'g');
|
|
||||||
|
|
||||||
liquid.registerTag('cycle', {
|
liquid.registerTag('cycle', {
|
||||||
|
|
||||||
@@ -2539,7 +2577,7 @@
|
|||||||
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var group = Liquid.evalValue(this.group, scope);
|
var group = Liquid.evalValue(this.group, scope);
|
||||||
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
||||||
|
|
||||||
@@ -2627,7 +2665,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Increment (liquid, Liquid) {
|
function Increment (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
|
||||||
var _Liquid$Types = Liquid.Types,
|
var _Liquid$Types = Liquid.Types,
|
||||||
CaptureScope = _Liquid$Types.CaptureScope,
|
CaptureScope = _Liquid$Types.CaptureScope,
|
||||||
AssignScope = _Liquid$Types.AssignScope,
|
AssignScope = _Liquid$Types.AssignScope,
|
||||||
@@ -2636,16 +2673,17 @@
|
|||||||
|
|
||||||
liquid.registerTag('increment', {
|
liquid.registerTag('increment', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
var match = token.args.match(lexical.identifier);
|
var match = token.args.match(identifier);
|
||||||
assert(match, 'illegal identifier ' + token.args);
|
assert(match, 'illegal identifier ' + token.args);
|
||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash$$1) {
|
||||||
var context = scope.findContextFor(this.variable, function (ctx) {
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope && Object.getPrototypeOf(ctx) !== AssignScope;
|
var proto = Object.getPrototypeOf(ctx);
|
||||||
|
return proto !== CaptureScope && proto !== AssignScope;
|
||||||
});
|
});
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(IncrementScope);
|
context = create(IncrementScope);
|
||||||
scope.unshift(context);
|
scope.unshift(context);
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
@@ -2665,7 +2703,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Layout (liquid, Liquid) {
|
function Layout (liquid, Liquid) {
|
||||||
var rValue = Liquid.lexical.value;
|
|
||||||
var staticFileRE = /\S+/;
|
var staticFileRE = /\S+/;
|
||||||
|
|
||||||
liquid.registerTag('layout', {
|
liquid.registerTag('layout', {
|
||||||
@@ -2675,7 +2712,7 @@
|
|||||||
this.staticLayout = match[0];
|
this.staticLayout = match[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
match = rValue.exec(token.args);
|
match = value.exec(token.args);
|
||||||
if (match) {
|
if (match) {
|
||||||
this.layout = match[0];
|
this.layout = match[0];
|
||||||
}
|
}
|
||||||
@@ -2683,7 +2720,7 @@
|
|||||||
this.tpls = liquid.parser.parse(remainTokens);
|
this.tpls = liquid.parser.parse(remainTokens);
|
||||||
},
|
},
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(scope, hash$$1) {
|
||||||
var layout, html, templates, partial;
|
var layout, html, templates, partial;
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -2710,7 +2747,7 @@
|
|||||||
case 9:
|
case 9:
|
||||||
templates = _context.sent;
|
templates = _context.sent;
|
||||||
|
|
||||||
scope.push(hash);
|
scope.push(hash$$1);
|
||||||
scope.opts.blockMode = 'output';
|
scope.opts.blockMode = 'output';
|
||||||
_context.next = 14;
|
_context.next = 14;
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
@@ -2718,7 +2755,7 @@
|
|||||||
case 14:
|
case 14:
|
||||||
partial = _context.sent;
|
partial = _context.sent;
|
||||||
|
|
||||||
scope.pop(hash);
|
scope.pop(hash$$1);
|
||||||
return _context.abrupt('return', partial);
|
return _context.abrupt('return', partial);
|
||||||
|
|
||||||
case 17:
|
case 17:
|
||||||
@@ -2834,8 +2871,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Tablerow (liquid, Liquid) {
|
function Tablerow (liquid, Liquid) {
|
||||||
var lexical = Liquid.lexical;
|
var re = new RegExp('^(' + identifier.source + ')\\s+in\\s+' + ('(' + value.source + ')') + ('(?:\\s+' + hash.source + ')*$'));
|
||||||
var re = new RegExp('^(' + lexical.identifier.source + ')\\s+in\\s+' + ('(' + lexical.value.source + ')') + ('(?:\\s+' + lexical.hash.source + ')*$'));
|
|
||||||
|
|
||||||
liquid.registerTag('tablerow', {
|
liquid.registerTag('tablerow', {
|
||||||
|
|
||||||
@@ -2864,7 +2900,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: function () {
|
render: function () {
|
||||||
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash) {
|
var _ref = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(scope, hash$$1) {
|
||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
var collection, offset, limit, cols, contexts, row, html;
|
var collection, offset, limit, cols, contexts, row, html;
|
||||||
@@ -2873,12 +2909,12 @@
|
|||||||
switch (_context2.prev = _context2.next) {
|
switch (_context2.prev = _context2.next) {
|
||||||
case 0:
|
case 0:
|
||||||
collection = Liquid.evalExp(this.collection, scope) || [];
|
collection = Liquid.evalExp(this.collection, scope) || [];
|
||||||
offset = hash.offset || 0;
|
offset = hash$$1.offset || 0;
|
||||||
limit = hash.limit === undefined ? collection.length : hash.limit;
|
limit = hash$$1.limit === undefined ? collection.length : hash$$1.limit;
|
||||||
|
|
||||||
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
collection = collection.slice(offset, offset + limit);
|
||||||
cols = hash.cols || collection.length;
|
cols = hash$$1.cols || collection.length;
|
||||||
contexts = collection.map(function (item, i) {
|
contexts = collection.map(function (item, i) {
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
ctx[_this2.variable] = item;
|
ctx[_this2.variable] = item;
|
||||||
@@ -3001,17 +3037,22 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
|
||||||
var monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
||||||
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
var dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
var monthNamesShort = monthNames.map(abbr);
|
||||||
|
var dayNamesShort = dayNames.map(abbr);
|
||||||
var suffixes = {
|
var suffixes = {
|
||||||
1: 'st',
|
1: 'st',
|
||||||
2: 'nd',
|
2: 'nd',
|
||||||
3: 'rd',
|
3: 'rd',
|
||||||
'default': 'th'
|
'default': 'th'
|
||||||
|
};
|
||||||
|
|
||||||
// prototype extensions
|
function abbr(str) {
|
||||||
};var _date = {
|
return str.slice(0, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// prototype extensions
|
||||||
|
var _date = {
|
||||||
daysInMonth: function daysInMonth(d) {
|
daysInMonth: function daysInMonth(d) {
|
||||||
var feb = _date.isLeapYear(d) ? 29 : 28;
|
var feb = _date.isLeapYear(d) ? 29 : 28;
|
||||||
return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
return [31, feb, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
||||||
@@ -3399,14 +3440,14 @@
|
|||||||
registerAll.filters = filters;
|
registerAll.filters = filters;
|
||||||
|
|
||||||
var _engine = {
|
var _engine = {
|
||||||
init: function init(tag, filter$$1, options) {
|
init: function init(tag, filter, options) {
|
||||||
if (options.cache) {
|
if (options.cache) {
|
||||||
this.cache = {};
|
this.cache = {};
|
||||||
}
|
}
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.tag = tag;
|
this.tag = tag;
|
||||||
this.filter = filter$$1;
|
this.filter = filter;
|
||||||
this.parser = Parser(tag, filter$$1);
|
this.parser = Parser(tag, filter);
|
||||||
this.renderer = Render();
|
this.renderer = Render();
|
||||||
|
|
||||||
tags(this, Liquid);
|
tags(this, Liquid);
|
||||||
@@ -3484,8 +3525,8 @@
|
|||||||
var tpl = this.parser.parseValue(str.trim());
|
var tpl = this.parser.parseValue(str.trim());
|
||||||
return this.renderer.evalValue(tpl, scope);
|
return this.renderer.evalValue(tpl, scope);
|
||||||
},
|
},
|
||||||
registerFilter: function registerFilter(name, filter$$1) {
|
registerFilter: function registerFilter(name, filter) {
|
||||||
return this.filter.register(name, filter$$1);
|
return this.filter.register(name, filter);
|
||||||
},
|
},
|
||||||
registerTag: function registerTag(name, tag) {
|
registerTag: function registerTag(name, tag) {
|
||||||
return this.tag.register(name, tag);
|
return this.tag.register(name, tag);
|
||||||
@@ -3641,7 +3682,7 @@
|
|||||||
}(),
|
}(),
|
||||||
respectCache: function () {
|
respectCache: function () {
|
||||||
var _ref8 = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(key, getter) {
|
var _ref8 = asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee8(key, getter) {
|
||||||
var cacheEnabled, value$$1;
|
var cacheEnabled, value;
|
||||||
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
return regeneratorRuntime.wrap(function _callee8$(_context8) {
|
||||||
while (1) {
|
while (1) {
|
||||||
switch (_context8.prev = _context8.next) {
|
switch (_context8.prev = _context8.next) {
|
||||||
@@ -3660,12 +3701,12 @@
|
|||||||
return getter();
|
return getter();
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
value$$1 = _context8.sent;
|
value = _context8.sent;
|
||||||
|
|
||||||
if (cacheEnabled) {
|
if (cacheEnabled) {
|
||||||
this.cache[key] = value$$1;
|
this.cache[key] = value;
|
||||||
}
|
}
|
||||||
return _context8.abrupt('return', value$$1);
|
return _context8.abrupt('return', value);
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
case 'end':
|
case 'end':
|
||||||
@@ -3694,9 +3735,9 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function normalizeStringArray(value$$1) {
|
function normalizeStringArray(value) {
|
||||||
if (Array.isArray(value$$1)) return value$$1;
|
if (Array.isArray(value)) return value;
|
||||||
if (isString(value$$1)) return [value$$1];
|
if (isString(value)) return [value];
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3716,7 +3757,7 @@
|
|||||||
}, options);
|
}, options);
|
||||||
options.root = normalizeStringArray(options.root);
|
options.root = normalizeStringArray(options.root);
|
||||||
|
|
||||||
var engine = Object.create(_engine);
|
var engine = create(_engine);
|
||||||
engine.init(Tag(), Filter(options), options);
|
engine.init(Tag(), Filter(options), options);
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
@@ -3730,12 +3771,11 @@
|
|||||||
TokenizationError: TokenizationError,
|
TokenizationError: TokenizationError,
|
||||||
RenderBreakError: RenderBreakError,
|
RenderBreakError: RenderBreakError,
|
||||||
AssertionError: AssertionError,
|
AssertionError: AssertionError,
|
||||||
AssignScope: Object.create(null),
|
AssignScope: {},
|
||||||
CaptureScope: Object.create(null),
|
CaptureScope: {},
|
||||||
IncrementScope: Object.create(null),
|
IncrementScope: {},
|
||||||
DecrementScope: Object.create(null)
|
DecrementScope: {}
|
||||||
};
|
};
|
||||||
Liquid.lexical = lexical;
|
|
||||||
|
|
||||||
return Liquid;
|
return Liquid;
|
||||||
|
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+2
-1
@@ -4,8 +4,9 @@
|
|||||||
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
|
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
|
||||||
"main": "dist/liquid.common.js",
|
"main": "dist/liquid.common.js",
|
||||||
"module": "src/index.js",
|
"module": "src/index.js",
|
||||||
|
"browser": "dist/liquid.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint src/ test/",
|
"lint": "eslint src/ test/ *.js",
|
||||||
"test": "mocha --require babel-core/register --recursive",
|
"test": "mocha --require babel-core/register --recursive",
|
||||||
"coverage": "nyc report --require babel-core/register mocha test/ --recursive ",
|
"coverage": "nyc report --require babel-core/register mocha test/ --recursive ",
|
||||||
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
|
"coveralls": "nyc report --reporter=text-lcov --require babel-core/register mocha test/ --recursive | coveralls",
|
||||||
|
|||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
import * as lexical from './lexical.js'
|
import * as lexical from './lexical.js'
|
||||||
import {evalValue} from './syntax.js'
|
import {evalValue} from './syntax.js'
|
||||||
import assert from './util/assert.js'
|
import assert from './util/assert.js'
|
||||||
import {assign} from './util/underscore.js'
|
import {assign, create} from './util/underscore.js'
|
||||||
|
|
||||||
const valueRE = new RegExp(`${lexical.value.source}`, 'g')
|
const valueRE = new RegExp(`${lexical.value.source}`, 'g')
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ export default function (options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function construct (str) {
|
function construct (str) {
|
||||||
const instance = Object.create(_filterInstance)
|
const instance = create(_filterInstance)
|
||||||
return instance.parse(str)
|
return instance.parse(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-7
@@ -7,7 +7,6 @@ import * as tokenizer from './tokenizer.js'
|
|||||||
import {statFileAsync, readFileAsync} from './util/fs.js'
|
import {statFileAsync, readFileAsync} from './util/fs.js'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {valid as isValidUrl, extname, resolve} from './util/url.js'
|
import {valid as isValidUrl, extname, resolve} from './util/url.js'
|
||||||
import * as lexical from './lexical.js'
|
|
||||||
import Render from './render.js'
|
import Render from './render.js'
|
||||||
import Tag from './tag.js'
|
import Tag from './tag.js'
|
||||||
import Filter from './filter.js'
|
import Filter from './filter.js'
|
||||||
@@ -151,7 +150,7 @@ export default function Liquid (options) {
|
|||||||
}, options)
|
}, options)
|
||||||
options.root = normalizeStringArray(options.root)
|
options.root = normalizeStringArray(options.root)
|
||||||
|
|
||||||
const engine = Object.create(_engine)
|
const engine = _.create(_engine)
|
||||||
engine.init(Tag(), Filter(options), options)
|
engine.init(Tag(), Filter(options), options)
|
||||||
return engine
|
return engine
|
||||||
}
|
}
|
||||||
@@ -165,9 +164,8 @@ Liquid.Types = {
|
|||||||
TokenizationError,
|
TokenizationError,
|
||||||
RenderBreakError,
|
RenderBreakError,
|
||||||
AssertionError,
|
AssertionError,
|
||||||
AssignScope: Object.create(null),
|
AssignScope: {},
|
||||||
CaptureScope: Object.create(null),
|
CaptureScope: {},
|
||||||
IncrementScope: Object.create(null),
|
IncrementScope: {},
|
||||||
DecrementScope: Object.create(null)
|
DecrementScope: {}
|
||||||
}
|
}
|
||||||
Liquid.lexical = lexical
|
|
||||||
|
|||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
import * as lexical from './lexical.js'
|
import * as lexical from './lexical.js'
|
||||||
|
import {create} from './util/underscore.js'
|
||||||
import {ParseError} from './util/error.js'
|
import {ParseError} from './util/error.js'
|
||||||
import assert from './util/assert.js'
|
import assert from './util/assert.js'
|
||||||
|
|
||||||
@@ -92,7 +93,7 @@ export default function (Tag, Filter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function parseStream (tokens) {
|
function parseStream (tokens) {
|
||||||
const s = Object.create(stream)
|
const s = create(stream)
|
||||||
return s.init(tokens)
|
return s.init(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
import {evalExp} from './syntax.js'
|
import {evalExp} from './syntax.js'
|
||||||
import {RenderBreakError, RenderError} from './util/error.js'
|
import {RenderBreakError, RenderError} from './util/error.js'
|
||||||
import {stringify} from './util/underscore.js'
|
import {stringify, create} from './util/underscore.js'
|
||||||
import assert from './util/assert.js'
|
import assert from './util/assert.js'
|
||||||
|
|
||||||
const render = {
|
const render = {
|
||||||
@@ -57,6 +57,6 @@ const render = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function () {
|
export default function () {
|
||||||
const instance = Object.create(render)
|
const instance = create(render)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -4,7 +4,7 @@ import assert from './util/assert.js'
|
|||||||
|
|
||||||
const Scope = {
|
const Scope = {
|
||||||
getAll: function () {
|
getAll: function () {
|
||||||
return this.contexts.reduce((ctx, val) => Object.assign(ctx, val), Object.create(null))
|
return this.contexts.reduce((ctx, val) => _.assign(ctx, val), _.create(null))
|
||||||
},
|
},
|
||||||
get: function (path) {
|
get: function (path) {
|
||||||
const paths = this.propertyAccessSeq(path)
|
const paths = this.propertyAccessSeq(path)
|
||||||
@@ -162,7 +162,7 @@ export function factory (ctx, opts) {
|
|||||||
blocks: {},
|
blocks: {},
|
||||||
root: []
|
root: []
|
||||||
}
|
}
|
||||||
const scope = Object.create(Scope)
|
const scope = _.create(Scope)
|
||||||
scope.opts = _.assign(defaultOptions, opts)
|
scope.opts = _.assign(defaultOptions, opts)
|
||||||
scope.contexts = [ctx || {}]
|
scope.contexts = [ctx || {}]
|
||||||
return scope
|
return scope
|
||||||
|
|||||||
+3
-2
@@ -1,4 +1,5 @@
|
|||||||
import {hashCapture} from './lexical.js'
|
import {hashCapture} from './lexical.js'
|
||||||
|
import {create} from './util/underscore.js'
|
||||||
import {evalValue} from './syntax.js'
|
import {evalValue} from './syntax.js'
|
||||||
import assert from './util/assert.js'
|
import assert from './util/assert.js'
|
||||||
|
|
||||||
@@ -33,7 +34,7 @@ export default function () {
|
|||||||
|
|
||||||
const tagImpl = tagImpls[this.name]
|
const tagImpl = tagImpls[this.name]
|
||||||
assert(tagImpl, `tag ${this.name} not found`)
|
assert(tagImpl, `tag ${this.name} not found`)
|
||||||
this.tagImpl = Object.create(tagImpl)
|
this.tagImpl = create(tagImpl)
|
||||||
if (this.tagImpl.parse) {
|
if (this.tagImpl.parse) {
|
||||||
this.tagImpl.parse(token, tokens)
|
this.tagImpl.parse(token, tokens)
|
||||||
}
|
}
|
||||||
@@ -45,7 +46,7 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function construct (token, tokens) {
|
function construct (token, tokens) {
|
||||||
const instance = Object.create(_tagInstance)
|
const instance = create(_tagInstance)
|
||||||
instance.parse(token, tokens)
|
instance.parse(token, tokens)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -1,8 +1,9 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {identifier} from '../lexical.js'
|
||||||
|
import {create} from '../util/underscore.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const rIdentifier = Liquid.lexical.identifier
|
const re = new RegExp(`(${identifier.source})\\s*=(.*)`)
|
||||||
const re = new RegExp(`(${rIdentifier.source})\\s*=(.*)`)
|
|
||||||
const {AssignScope} = Liquid.Types
|
const {AssignScope} = Liquid.Types
|
||||||
|
|
||||||
liquid.registerTag('assign', {
|
liquid.registerTag('assign', {
|
||||||
@@ -13,7 +14,7 @@ export default function (liquid, Liquid) {
|
|||||||
this.value = match[2]
|
this.value = match[2]
|
||||||
},
|
},
|
||||||
render: function (scope) {
|
render: function (scope) {
|
||||||
const ctx = Object.create(AssignScope)
|
const ctx = create(AssignScope)
|
||||||
ctx[this.key] = liquid.evalValue(this.value, scope)
|
ctx[this.key] = liquid.evalValue(this.value, scope)
|
||||||
scope.push(ctx)
|
scope.push(ctx)
|
||||||
return Promise.resolve('')
|
return Promise.resolve('')
|
||||||
|
|||||||
+4
-3
@@ -1,8 +1,9 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {create} from '../util/underscore.js'
|
||||||
|
import {identifier} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const rIdentifier = Liquid.lexical.identifier
|
const re = new RegExp(`(${identifier.source})`)
|
||||||
const re = new RegExp(`(${rIdentifier.source})`)
|
|
||||||
const {CaptureScope} = Liquid.Types
|
const {CaptureScope} = Liquid.Types
|
||||||
|
|
||||||
liquid.registerTag('capture', {
|
liquid.registerTag('capture', {
|
||||||
@@ -23,7 +24,7 @@ export default function (liquid, Liquid) {
|
|||||||
},
|
},
|
||||||
render: async function (scope, hash) {
|
render: async function (scope, hash) {
|
||||||
const html = await liquid.renderer.renderTemplates(this.templates, scope)
|
const html = await liquid.renderer.renderTemplates(this.templates, scope)
|
||||||
const ctx = Object.create(CaptureScope)
|
const ctx = create(CaptureScope)
|
||||||
ctx[this.variable] = html
|
ctx[this.variable] = html
|
||||||
scope.push(ctx)
|
scope.push(ctx)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {value as rValue} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const rValue = Liquid.lexical.value
|
|
||||||
const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`)
|
const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`)
|
||||||
const candidatesRE = new RegExp(rValue.source, 'g')
|
const candidatesRE = new RegExp(rValue.source, 'g')
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
|
import {create} from '../util/underscore.js'
|
||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {identifier} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const lexical = Liquid.lexical
|
|
||||||
const {CaptureScope, AssignScope, DecrementScope} = Liquid.Types
|
const {CaptureScope, AssignScope, DecrementScope} = Liquid.Types
|
||||||
|
|
||||||
liquid.registerTag('decrement', {
|
liquid.registerTag('decrement', {
|
||||||
parse: function (token) {
|
parse: function (token) {
|
||||||
const match = token.args.match(lexical.identifier)
|
const match = token.args.match(identifier)
|
||||||
assert(match, `illegal identifier ${token.args}`)
|
assert(match, `illegal identifier ${token.args}`)
|
||||||
this.variable = match[0]
|
this.variable = match[0]
|
||||||
},
|
},
|
||||||
@@ -14,12 +15,12 @@ export default function (liquid, Liquid) {
|
|||||||
let context = scope.findContextFor(
|
let context = scope.findContextFor(
|
||||||
this.variable,
|
this.variable,
|
||||||
ctx => {
|
ctx => {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope &&
|
const proto = Object.getPrototypeOf(ctx)
|
||||||
Object.getPrototypeOf(ctx) !== AssignScope
|
return proto !== CaptureScope && proto !== AssignScope
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(DecrementScope)
|
context = create(DecrementScope)
|
||||||
scope.unshift(context)
|
scope.unshift(context)
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
|
|||||||
+5
-5
@@ -1,15 +1,15 @@
|
|||||||
import {mapSeries} from '../util/promise.js'
|
import {mapSeries} from '../util/promise.js'
|
||||||
import {isString, isObject} from '../util/underscore.js'
|
import {isString, isObject} from '../util/underscore.js'
|
||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {identifier, value, hash} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const RenderBreakError = Liquid.Types.RenderBreakError
|
const RenderBreakError = Liquid.Types.RenderBreakError
|
||||||
const lexical = Liquid.lexical
|
const re = new RegExp(`^(${identifier.source})\\s+in\\s+` +
|
||||||
const re = new RegExp(`^(${lexical.identifier.source})\\s+in\\s+` +
|
`(${value.source})` +
|
||||||
`(${lexical.value.source})` +
|
`(?:\\s+${hash.source})*` +
|
||||||
`(?:\\s+${lexical.hash.source})*` +
|
|
||||||
`(?:\\s+(reversed))?` +
|
`(?:\\s+(reversed))?` +
|
||||||
`(?:\\s+${lexical.hash.source})*$`)
|
`(?:\\s+${hash.source})*$`)
|
||||||
|
|
||||||
liquid.registerTag('for', {parse, render})
|
liquid.registerTag('for', {parse, render})
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,10 +1,10 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {value, quotedLine} from '../lexical.js'
|
||||||
|
|
||||||
const staticFileRE = /[^\s,]+/
|
const staticFileRE = /[^\s,]+/
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const lexical = Liquid.lexical
|
const withRE = new RegExp(`with\\s+(${value.source})`)
|
||||||
const withRE = new RegExp(`with\\s+(${lexical.value.source})`)
|
|
||||||
|
|
||||||
liquid.registerTag('include', {
|
liquid.registerTag('include', {
|
||||||
parse: function (token) {
|
parse: function (token) {
|
||||||
@@ -13,7 +13,7 @@ export default function (liquid, Liquid) {
|
|||||||
this.staticValue = match[0]
|
this.staticValue = match[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
match = lexical.value.exec(token.args)
|
match = value.exec(token.args)
|
||||||
if (match) {
|
if (match) {
|
||||||
this.value = match[0]
|
this.value = match[0]
|
||||||
}
|
}
|
||||||
@@ -26,7 +26,7 @@ export default function (liquid, Liquid) {
|
|||||||
render: async function (scope, hash) {
|
render: async function (scope, hash) {
|
||||||
let filepath
|
let filepath
|
||||||
if (scope.opts.dynamicPartials) {
|
if (scope.opts.dynamicPartials) {
|
||||||
if (lexical.quotedLine.exec(this.value)) {
|
if (quotedLine.exec(this.value)) {
|
||||||
const template = this.value.slice(1, -1)
|
const template = this.value.slice(1, -1)
|
||||||
filepath = await liquid.parseAndRender(template, scope.getAll(), scope.opts)
|
filepath = await liquid.parseAndRender(template, scope.getAll(), scope.opts)
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {create} from '../util/underscore.js'
|
||||||
|
import {identifier} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const lexical = Liquid.lexical
|
|
||||||
const {CaptureScope, AssignScope, IncrementScope} = Liquid.Types
|
const {CaptureScope, AssignScope, IncrementScope} = Liquid.Types
|
||||||
|
|
||||||
liquid.registerTag('increment', {
|
liquid.registerTag('increment', {
|
||||||
parse: function (token) {
|
parse: function (token) {
|
||||||
const match = token.args.match(lexical.identifier)
|
const match = token.args.match(identifier)
|
||||||
assert(match, `illegal identifier ${token.args}`)
|
assert(match, `illegal identifier ${token.args}`)
|
||||||
this.variable = match[0]
|
this.variable = match[0]
|
||||||
},
|
},
|
||||||
@@ -14,12 +15,12 @@ export default function (liquid, Liquid) {
|
|||||||
let context = scope.findContextFor(
|
let context = scope.findContextFor(
|
||||||
this.variable,
|
this.variable,
|
||||||
ctx => {
|
ctx => {
|
||||||
return Object.getPrototypeOf(ctx) !== CaptureScope &&
|
const proto = Object.getPrototypeOf(ctx)
|
||||||
Object.getPrototypeOf(ctx) !== AssignScope
|
return proto !== CaptureScope && proto !== AssignScope
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
if (!context) {
|
if (!context) {
|
||||||
context = Object.create(IncrementScope)
|
context = create(IncrementScope)
|
||||||
scope.unshift(context)
|
scope.unshift(context)
|
||||||
}
|
}
|
||||||
if (typeof context[this.variable] !== 'number') {
|
if (typeof context[this.variable] !== 'number') {
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,5 @@
|
|||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {value as rValue} from '../lexical.js'
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* blockMode:
|
* blockMode:
|
||||||
@@ -7,7 +8,6 @@ import assert from '../util/assert.js'
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const rValue = Liquid.lexical.value
|
|
||||||
const staticFileRE = /\S+/
|
const staticFileRE = /\S+/
|
||||||
|
|
||||||
liquid.registerTag('layout', {
|
liquid.registerTag('layout', {
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import {mapSeries} from '../util/promise.js'
|
import {mapSeries} from '../util/promise.js'
|
||||||
import assert from '../util/assert.js'
|
import assert from '../util/assert.js'
|
||||||
|
import {identifier, value, hash} from '../lexical.js'
|
||||||
|
|
||||||
export default function (liquid, Liquid) {
|
export default function (liquid, Liquid) {
|
||||||
const lexical = Liquid.lexical
|
const re = new RegExp(`^(${identifier.source})\\s+in\\s+` +
|
||||||
const re = new RegExp(`^(${lexical.identifier.source})\\s+in\\s+` +
|
`(${value.source})` +
|
||||||
`(${lexical.value.source})` +
|
`(?:\\s+${hash.source})*$`)
|
||||||
`(?:\\s+${lexical.hash.source})*$`)
|
|
||||||
|
|
||||||
liquid.registerTag('tablerow', {
|
liquid.registerTag('tablerow', {
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -24,7 +24,7 @@ function initLiquidError (err, token) {
|
|||||||
export function TokenizationError (message, token) {
|
export function TokenizationError (message, token) {
|
||||||
initLiquidError.call(this, {message: message}, token)
|
initLiquidError.call(this, {message: message}, token)
|
||||||
}
|
}
|
||||||
TokenizationError.prototype = Object.create(Error.prototype)
|
TokenizationError.prototype = _.create(Error.prototype)
|
||||||
TokenizationError.prototype.constructor = TokenizationError
|
TokenizationError.prototype.constructor = TokenizationError
|
||||||
|
|
||||||
export function ParseError (e, token) {
|
export function ParseError (e, token) {
|
||||||
@@ -33,7 +33,7 @@ export function ParseError (e, token) {
|
|||||||
|
|
||||||
initLiquidError.call(this, e, token)
|
initLiquidError.call(this, e, token)
|
||||||
}
|
}
|
||||||
ParseError.prototype = Object.create(Error.prototype)
|
ParseError.prototype = _.create(Error.prototype)
|
||||||
ParseError.prototype.constructor = ParseError
|
ParseError.prototype.constructor = ParseError
|
||||||
|
|
||||||
export function RenderError (e, tpl) {
|
export function RenderError (e, tpl) {
|
||||||
@@ -46,21 +46,21 @@ export function RenderError (e, tpl) {
|
|||||||
|
|
||||||
initLiquidError.call(this, e, tpl.token)
|
initLiquidError.call(this, e, tpl.token)
|
||||||
}
|
}
|
||||||
RenderError.prototype = Object.create(Error.prototype)
|
RenderError.prototype = _.create(Error.prototype)
|
||||||
RenderError.prototype.constructor = RenderError
|
RenderError.prototype.constructor = RenderError
|
||||||
|
|
||||||
export function RenderBreakError (message) {
|
export function RenderBreakError (message) {
|
||||||
initError.call(this)
|
initError.call(this)
|
||||||
this.message = message + ''
|
this.message = message + ''
|
||||||
}
|
}
|
||||||
RenderBreakError.prototype = Object.create(Error.prototype)
|
RenderBreakError.prototype = _.create(Error.prototype)
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError
|
RenderBreakError.prototype.constructor = RenderBreakError
|
||||||
|
|
||||||
export function AssertionError (message) {
|
export function AssertionError (message) {
|
||||||
initError.call(this)
|
initError.call(this)
|
||||||
this.message = message + ''
|
this.message = message + ''
|
||||||
}
|
}
|
||||||
AssertionError.prototype = Object.create(Error.prototype)
|
AssertionError.prototype = _.create(Error.prototype)
|
||||||
AssertionError.prototype.constructor = AssertionError
|
AssertionError.prototype.constructor = AssertionError
|
||||||
|
|
||||||
function mkContext (input, line) {
|
function mkContext (input, line) {
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ const monthNames = [
|
|||||||
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
|
'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August',
|
||||||
'September', 'October', 'November', 'December'
|
'September', 'October', 'November', 'December'
|
||||||
]
|
]
|
||||||
const monthNamesShort = [
|
|
||||||
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct',
|
|
||||||
'Nov', 'Dec'
|
|
||||||
]
|
|
||||||
const dayNames = [
|
const dayNames = [
|
||||||
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
|
'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'
|
||||||
]
|
]
|
||||||
const dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
|
const monthNamesShort = monthNames.map(abbr)
|
||||||
|
const dayNamesShort = dayNames.map(abbr)
|
||||||
const suffixes = {
|
const suffixes = {
|
||||||
1: 'st',
|
1: 'st',
|
||||||
2: 'nd',
|
2: 'nd',
|
||||||
@@ -17,6 +14,10 @@ const suffixes = {
|
|||||||
'default': 'th'
|
'default': 'th'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function abbr (str) {
|
||||||
|
return str.slice(0, 3)
|
||||||
|
}
|
||||||
|
|
||||||
// prototype extensions
|
// prototype extensions
|
||||||
const _date = {
|
const _date = {
|
||||||
daysInMonth: function (d) {
|
daysInMonth: function (d) {
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ export function stringify (value) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function create (proto) {
|
||||||
|
return Object.create(proto)
|
||||||
|
}
|
||||||
|
|
||||||
export function isNil (value) {
|
export function isNil (value) {
|
||||||
return value === null || value === undefined
|
return value === null || value === undefined
|
||||||
}
|
}
|
||||||
@@ -45,7 +49,7 @@ export function isArray (value) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function isError (value) {
|
export function isError (value) {
|
||||||
const signature = Object.prototype.toString.call(value)
|
const signature = toStr.call(value)
|
||||||
// [object XXXError]
|
// [object XXXError]
|
||||||
return signature.substr(-6, 5) === 'Error' ||
|
return signature.substr(-6, 5) === 'Error' ||
|
||||||
(typeof value.message === 'string' && typeof value.name === 'string')
|
(typeof value.message === 'string' && typeof value.name === 'string')
|
||||||
|
|||||||
Reference in New Issue
Block a user