mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-26 13:45:15 -07:00
chore(release): 7.2.1 [skip ci]
## [7.2.1](https://github.com/harttle/liquidjs/compare/v7.2.0...v7.2.1) (2019-02-22)
### Bug Fixes
* default length for truncate and truncatewords ([56c7992](https://github.com/harttle/liquidjs/commit/56c7992))
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
|
## [7.2.1](https://github.com/harttle/liquidjs/compare/v7.2.0...v7.2.1) (2019-02-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* default length for truncate and truncatewords ([56c7992](https://github.com/harttle/liquidjs/commit/56c7992))
|
||||||
|
|
||||||
# [7.2.0](https://github.com/harttle/liquidjs/compare/v7.1.0...v7.2.0) (2019-02-20)
|
# [7.2.0](https://github.com/harttle/liquidjs/compare/v7.1.0...v7.2.0) (2019-02-20)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Vendored
+12
-9
@@ -1,12 +1,15 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'join': (v: any, arg: any) => any;
|
'join': (v: any[], arg: string) => string;
|
||||||
'last': (v: any) => any;
|
'last': <T>(v: T[]) => T;
|
||||||
'first': (v: any) => any;
|
'first': <T>(v: T[]) => T;
|
||||||
'map': (arr: any, arg: any) => any;
|
'map': <T1, T2>(arr: {
|
||||||
'reverse': (v: any) => any;
|
[key: string]: T1;
|
||||||
'sort': (v: any, arg: any) => any;
|
}[], arg: string) => T1[];
|
||||||
'size': (v: any) => any;
|
'reverse': (v: any[]) => any[];
|
||||||
'slice': (v: any, begin: any, length: any) => any;
|
'sort': <T>(v: T[], arg: (lhs: T, rhs: T) => number) => T[];
|
||||||
'uniq': (arr: any) => any;
|
'size': (v: string | any[]) => number;
|
||||||
|
'concat': <T1, T2>(v: T1[], arg: T2 | T2[]) => (T1 | T2)[];
|
||||||
|
'slice': <T>(v: T[], begin: number, length: number) => T[];
|
||||||
|
'uniq': <T>(arr: T[]) => T[];
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'date': (v: any, arg: any) => any;
|
'date': (v: string | Date, arg: string) => string | Date;
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+4
-4
@@ -1,8 +1,8 @@
|
|||||||
declare function escape(str: any): string;
|
declare function escape(str: string): string;
|
||||||
declare const _default: {
|
declare const _default: {
|
||||||
'escape': typeof escape;
|
'escape': typeof escape;
|
||||||
'escape_once': (str: any) => string;
|
'escape_once': (str: string) => string;
|
||||||
'newline_to_br': (v: any) => any;
|
'newline_to_br': (v: string) => string;
|
||||||
'strip_html': (v: any) => string;
|
'strip_html': (v: string) => string;
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+29
-43
@@ -1,46 +1,32 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'join': (v: any, arg: any) => any;
|
'join': (v: any[], arg: string) => string;
|
||||||
'last': (v: any) => any;
|
'last': <T>(v: T[]) => T;
|
||||||
'first': (v: any) => any;
|
'first': <T>(v: T[]) => T;
|
||||||
'map': (arr: any, arg: any) => any;
|
'map': <T1, T2>(arr: {
|
||||||
'reverse': (v: any) => any;
|
[key: string]: T1;
|
||||||
'sort': (v: any, arg: any) => any;
|
}[], arg: string) => T1[];
|
||||||
'size': (v: any) => any;
|
'reverse': (v: any[]) => any[];
|
||||||
'slice': (v: any, begin: any, length: any) => any;
|
'sort': <T>(v: T[], arg: (lhs: T, rhs: T) => number) => T[];
|
||||||
'uniq': (arr: any) => any;
|
'size': (v: string | any[]) => number;
|
||||||
'default': (v: any, arg: any) => any;
|
'concat': <T1, T2>(v: T1[], arg: T2 | T2[]) => (T1 | T2)[];
|
||||||
'date': (v: any, arg: any) => any;
|
'slice': <T>(v: T[], begin: number, length: number) => T[];
|
||||||
'url_decode': (x: any) => any;
|
'uniq': <T>(arr: T[]) => T[];
|
||||||
'url_encode': (x: any) => any;
|
'default': <T1, T2>(v: T1, arg: T2) => T1 | T2;
|
||||||
'abs': (v: any) => number;
|
'date': (v: string | Date, arg: string) => string | Date;
|
||||||
'ceil': (v: any) => number;
|
'url_decode': (x: string) => string;
|
||||||
'divided_by': (v: any, arg: any) => number;
|
'url_encode': (x: string) => string;
|
||||||
'floor': (v: any) => number;
|
'abs': (v: number) => number;
|
||||||
'minus': (l: any, r: any) => any;
|
'ceil': (v: number) => number;
|
||||||
'modulo': (l: any, r: any) => any;
|
'divided_by': (v: number, arg: number) => number;
|
||||||
'round': (v: any, arg: any) => number;
|
'floor': (v: number) => number;
|
||||||
'plus': (l: any, r: any) => any;
|
'minus': (l: number, r: number) => string;
|
||||||
'times': (v: any, arg: any) => number;
|
'modulo': (l: number, r: number) => string;
|
||||||
'append': (v: any, arg: any) => any;
|
'round': (v: number, arg?: number) => number;
|
||||||
'prepend': (v: any, arg: any) => any;
|
'plus': (l: number, r: number) => string;
|
||||||
'capitalize': (str: any) => string;
|
'times': (v: number, arg: number) => number;
|
||||||
'concat': (v: any, arg: any) => any;
|
'escape': (str: string) => string;
|
||||||
'lstrip': (v: any) => string;
|
'escape_once': (str: string) => string;
|
||||||
'downcase': (v: any) => any;
|
'newline_to_br': (v: string) => string;
|
||||||
'upcase': (str: any) => string;
|
'strip_html': (v: string) => string;
|
||||||
'remove': (v: any, arg: any) => any;
|
|
||||||
'remove_first': (v: any, l: any) => any;
|
|
||||||
'replace': (v: any, pattern: any, replacement: any) => string;
|
|
||||||
'replace_first': (v: any, arg1: any, arg2: any) => string;
|
|
||||||
'rstrip': (str: any) => string;
|
|
||||||
'split': (v: any, arg: any) => string[];
|
|
||||||
'strip': (v: any) => string;
|
|
||||||
'strip_newlines': (v: any) => string;
|
|
||||||
'truncate': (v: any, l: any, o: any) => any;
|
|
||||||
'truncatewords': (v: any, l: any, o: any) => any;
|
|
||||||
'escape': (str: any) => string;
|
|
||||||
'escape_once': (str: any) => string;
|
|
||||||
'newline_to_br': (v: any) => any;
|
|
||||||
'strip_html': (v: any) => string;
|
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+9
-9
@@ -1,12 +1,12 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'abs': (v: any) => number;
|
'abs': (v: number) => number;
|
||||||
'ceil': (v: any) => number;
|
'ceil': (v: number) => number;
|
||||||
'divided_by': (v: any, arg: any) => number;
|
'divided_by': (v: number, arg: number) => number;
|
||||||
'floor': (v: any) => number;
|
'floor': (v: number) => number;
|
||||||
'minus': (l: any, r: any) => any;
|
'minus': (l: number, r: number) => string;
|
||||||
'modulo': (l: any, r: any) => any;
|
'modulo': (l: number, r: number) => string;
|
||||||
'round': (v: any, arg: any) => number;
|
'round': (v: number, arg?: number) => number;
|
||||||
'plus': (l: any, r: any) => any;
|
'plus': (l: number, r: number) => string;
|
||||||
'times': (v: any, arg: any) => number;
|
'times': (v: number, arg: number) => number;
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'default': (v: any, arg: any) => any;
|
'default': <T1, T2>(v: T1, arg: T2) => T1 | T2;
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-17
@@ -1,20 +1,5 @@
|
|||||||
|
import { FilterImpl } from 'src/template/filter/filter-impl';
|
||||||
declare const _default: {
|
declare const _default: {
|
||||||
'append': (v: any, arg: any) => any;
|
[key: string]: FilterImpl;
|
||||||
'prepend': (v: any, arg: any) => any;
|
|
||||||
'capitalize': (str: any) => string;
|
|
||||||
'concat': (v: any, arg: any) => any;
|
|
||||||
'lstrip': (v: any) => string;
|
|
||||||
'downcase': (v: any) => any;
|
|
||||||
'upcase': (str: any) => string;
|
|
||||||
'remove': (v: any, arg: any) => any;
|
|
||||||
'remove_first': (v: any, l: any) => any;
|
|
||||||
'replace': (v: any, pattern: any, replacement: any) => string;
|
|
||||||
'replace_first': (v: any, arg1: any, arg2: any) => string;
|
|
||||||
'rstrip': (str: any) => string;
|
|
||||||
'split': (v: any, arg: any) => string[];
|
|
||||||
'strip': (v: any) => string;
|
|
||||||
'strip_newlines': (v: any) => string;
|
|
||||||
'truncate': (v: any, l: any, o: any) => any;
|
|
||||||
'truncatewords': (v: any, l: any, o: any) => any;
|
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
declare const _default: {
|
declare const _default: {
|
||||||
'url_decode': (x: any) => any;
|
'url_decode': (x: string) => string;
|
||||||
'url_encode': (x: any) => any;
|
'url_encode': (x: string) => string;
|
||||||
};
|
};
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (token: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => Promise<string>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (token: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => Promise<any>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-7
@@ -1,8 +1,3 @@
|
|||||||
import TagToken from 'src/parser/tag-token';
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
import Token from 'src/parser/token';
|
declare const _default: ITagImplOptions;
|
||||||
import Scope from 'src/scope/scope';
|
|
||||||
declare const _default: {
|
|
||||||
parse: (tagToken: TagToken, remainTokens: Token[]) => void;
|
|
||||||
render: (scope: Scope) => Promise<void>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-3
@@ -1,4 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-6
@@ -1,7 +1,3 @@
|
|||||||
import TagToken from 'src/parser/tag-token';
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
import Scope from 'src/scope/scope';
|
declare const _default: ITagImplOptions;
|
||||||
declare const _default: {
|
|
||||||
parse: (token: TagToken) => void;
|
|
||||||
render: (scope: Scope) => number;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-6
@@ -1,7 +1,3 @@
|
|||||||
declare function parse(tagToken: any, remainTokens: any): void;
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
declare function render(scope: any, hash: any): Promise<any>;
|
declare const _default: ITagImplOptions;
|
||||||
declare const _default: {
|
|
||||||
parse: typeof parse;
|
|
||||||
render: typeof render;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (token: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any, hash: any) => Promise<any>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (token: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (token: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any, hash: any) => Promise<any>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: () => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any, hash: any) => Promise<string>;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+2
-4
@@ -1,5 +1,3 @@
|
|||||||
declare const _default: {
|
import ITagImplOptions from 'src/template/tag/itag-impl-options';
|
||||||
parse: (tagToken: any, remainTokens: any) => void;
|
declare const _default: ITagImplOptions;
|
||||||
render: (scope: any) => any;
|
|
||||||
};
|
|
||||||
export default _default;
|
export default _default;
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
export default interface IFS {
|
export default interface IFS {
|
||||||
exists: (filepath?: string) => Promise<boolean>;
|
exists: (filepath: string) => Promise<boolean>;
|
||||||
readFile: (filepath: string) => Promise<string>;
|
readFile: (filepath: string) => Promise<string>;
|
||||||
resolve: (root: string, file: string, ext: string) => string;
|
resolve: (root: string, file: string, ext: string) => string;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
-2
@@ -42,7 +42,11 @@ export interface NormalizedFullOptions extends NormalizedOptions {
|
|||||||
trim_tag_left: boolean;
|
trim_tag_left: boolean;
|
||||||
trim_output_right: boolean;
|
trim_output_right: boolean;
|
||||||
trim_output_left: boolean;
|
trim_output_left: boolean;
|
||||||
|
tag_delimiter_left: string;
|
||||||
|
tag_delimiter_right: string;
|
||||||
|
output_delimiter_left: string;
|
||||||
|
output_delimiter_right: string;
|
||||||
greedy: boolean;
|
greedy: boolean;
|
||||||
}
|
}
|
||||||
export declare function normalize(options: LiquidOptions): NormalizedOptions;
|
export declare function normalize(options?: LiquidOptions): NormalizedOptions;
|
||||||
export declare function applyDefault(options: NormalizedOptions): NormalizedFullOptions;
|
export declare function applyDefault(options?: NormalizedOptions): NormalizedFullOptions;
|
||||||
|
|||||||
Vendored
+194
-238
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* [email protected].0, https://github.com/harttle/liquidjs
|
* [email protected].1, https://github.com/harttle/liquidjs
|
||||||
* (c) 2016-2019 harttle
|
* (c) 2016-2019 harttle
|
||||||
* Released under the MIT License.
|
* Released under the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -166,32 +166,6 @@ function forOwn(object, iteratee) {
|
|||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Assigns own enumerable string keyed properties of source objects to the destination object.
|
|
||||||
* Source objects are applied from left to right.
|
|
||||||
* Subsequent sources overwrite property assignments of previous sources.
|
|
||||||
*
|
|
||||||
* Note: This method mutates object and is loosely based on Object.assign.
|
|
||||||
*
|
|
||||||
* @param {Object} object The destination object.
|
|
||||||
* @param {...Object} sources The source objects.
|
|
||||||
* @return {Object} Returns object.
|
|
||||||
*/
|
|
||||||
function assign(obj) {
|
|
||||||
var srcs = [];
|
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
|
||||||
srcs[_i - 1] = arguments[_i];
|
|
||||||
}
|
|
||||||
obj = isObject(obj) ? obj : {};
|
|
||||||
srcs.forEach(function (src) { return binaryAssign(obj, src); });
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
function binaryAssign(target, src) {
|
|
||||||
for (var key in src)
|
|
||||||
if (src.hasOwnProperty(key))
|
|
||||||
target[key] = src[key];
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
function last(arr) {
|
function last(arr) {
|
||||||
return arr[arr.length - 1];
|
return arr[arr.length - 1];
|
||||||
}
|
}
|
||||||
@@ -214,7 +188,7 @@ function isObject(value) {
|
|||||||
* negative — if you'd like a negative range, use a negative step.
|
* negative — if you'd like a negative range, use a negative step.
|
||||||
*/
|
*/
|
||||||
function range(start, stop, step) {
|
function range(start, stop, step) {
|
||||||
if (arguments.length === 1) {
|
if (stop === undefined) {
|
||||||
stop = start;
|
stop = start;
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
@@ -241,7 +215,7 @@ var quoted = new RegExp(singleQuoted.source + "|" + doubleQuoted.source);
|
|||||||
var quoteBalanced = new RegExp("(?:" + quoted.source + "|[^'\"])*");
|
var quoteBalanced = new RegExp("(?:" + quoted.source + "|[^'\"])*");
|
||||||
// basic types
|
// basic types
|
||||||
var integer = /-?\d+/;
|
var integer = /-?\d+/;
|
||||||
var number = /-?\d+\.?\d*|\.?\d+/;
|
var number = /[+-]?(?:\d+\.?\d*|\.?\d+)/;
|
||||||
var bool = /true|false/;
|
var bool = /true|false/;
|
||||||
// property access
|
// property access
|
||||||
var identifier = /[\w-]+[?]?/;
|
var identifier = /[\w-]+[?]?/;
|
||||||
@@ -304,90 +278,83 @@ function parseLiteral(str) {
|
|||||||
throw new TypeError("cannot parse '" + str + "' as literal");
|
throw new TypeError("cannot parse '" + str + "' as literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
function captureStack() {
|
var LiquidError = /** @class */ (function (_super) {
|
||||||
if (Error.captureStackTrace) {
|
__extends(LiquidError, _super);
|
||||||
Error.captureStackTrace(this, this.constructor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var LiquidError = /** @class */ (function () {
|
|
||||||
function LiquidError(err, token) {
|
function LiquidError(err, token) {
|
||||||
this.input = token.input;
|
var _this = _super.call(this, err.message) || this;
|
||||||
this.file = token.file;
|
_this.originalError = err;
|
||||||
this.originalError = err;
|
_this.token = token;
|
||||||
this.token = token;
|
return _this;
|
||||||
}
|
}
|
||||||
LiquidError.prototype.captureStackTrace = function (obj) {
|
LiquidError.prototype.update = function () {
|
||||||
this.name = obj.constructor.name;
|
|
||||||
captureStack.call(obj);
|
|
||||||
var err = this.originalError;
|
var err = this.originalError;
|
||||||
var context = mkContext(this.input, this.token.line);
|
var context = mkContext(this.token);
|
||||||
this.message = mkMessage(err.message, this.token);
|
this.message = mkMessage(err.message, this.token);
|
||||||
this.stack = this.message + '\n' + context +
|
this.stack = this.message + '\n' + context +
|
||||||
'\n' + (this.stack || this.message) +
|
'\n' + this.stack + '\nFrom ' + err.stack;
|
||||||
(err.stack ? '\nFrom ' + err.stack : '');
|
|
||||||
};
|
};
|
||||||
return LiquidError;
|
return LiquidError;
|
||||||
}());
|
}(Error));
|
||||||
var TokenizationError = /** @class */ (function (_super) {
|
var TokenizationError = /** @class */ (function (_super) {
|
||||||
__extends(TokenizationError, _super);
|
__extends(TokenizationError, _super);
|
||||||
function TokenizationError(message, token) {
|
function TokenizationError(message, token) {
|
||||||
var _this = _super.call(this, { message: message }, token) || this;
|
var _this = _super.call(this, new Error(message), token) || this;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_this.name = 'TokenizationError';
|
||||||
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return TokenizationError;
|
return TokenizationError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
TokenizationError.prototype = create(Error.prototype);
|
|
||||||
TokenizationError.prototype.constructor = TokenizationError;
|
|
||||||
var ParseError = /** @class */ (function (_super) {
|
var ParseError = /** @class */ (function (_super) {
|
||||||
__extends(ParseError, _super);
|
__extends(ParseError, _super);
|
||||||
function ParseError(err, token) {
|
function ParseError(err, token) {
|
||||||
var _this = _super.call(this, err, token) || this;
|
var _this = _super.call(this, err, token) || this;
|
||||||
|
_this.name = 'ParseError';
|
||||||
_this.message = err.message;
|
_this.message = err.message;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return ParseError;
|
return ParseError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
ParseError.prototype = create(Error.prototype);
|
|
||||||
ParseError.prototype.constructor = ParseError;
|
|
||||||
var RenderError = /** @class */ (function (_super) {
|
var RenderError = /** @class */ (function (_super) {
|
||||||
__extends(RenderError, _super);
|
__extends(RenderError, _super);
|
||||||
function RenderError(err, tpl) {
|
function RenderError(err, tpl) {
|
||||||
var _this = _super.call(this, err, tpl.token) || this;
|
var _this = _super.call(this, err, tpl.token) || this;
|
||||||
|
_this.name = 'RenderError';
|
||||||
_this.message = err.message;
|
_this.message = err.message;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return RenderError;
|
return RenderError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
RenderError.prototype = create(Error.prototype);
|
var RenderBreakError = /** @class */ (function (_super) {
|
||||||
RenderError.prototype.constructor = RenderError;
|
__extends(RenderBreakError, _super);
|
||||||
var RenderBreakError = /** @class */ (function () {
|
|
||||||
function RenderBreakError(message) {
|
function RenderBreakError(message) {
|
||||||
captureStack.call(this);
|
var _this = _super.call(this, message) || this;
|
||||||
this.message = message + '';
|
_this.resolvedHTML = '';
|
||||||
|
_this.name = 'RenderBreakError';
|
||||||
|
_this.message = message + '';
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
return RenderBreakError;
|
return RenderBreakError;
|
||||||
}());
|
}(Error));
|
||||||
RenderBreakError.prototype = create(Error.prototype);
|
var AssertionError = /** @class */ (function (_super) {
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError;
|
__extends(AssertionError, _super);
|
||||||
var AssertionError = /** @class */ (function () {
|
|
||||||
function AssertionError(message) {
|
function AssertionError(message) {
|
||||||
captureStack.call(this);
|
var _this = _super.call(this, message) || this;
|
||||||
this.message = message + '';
|
_this.name = 'AssertionError';
|
||||||
|
_this.message = message + '';
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
return AssertionError;
|
return AssertionError;
|
||||||
}());
|
}(Error));
|
||||||
AssertionError.prototype = create(Error.prototype);
|
function mkContext(token) {
|
||||||
AssertionError.prototype.constructor = AssertionError;
|
var lines = token.input.split('\n');
|
||||||
function mkContext(input, targetLine) {
|
var begin = Math.max(token.line - 2, 1);
|
||||||
var lines = input.split('\n');
|
var end = Math.min(token.line + 3, lines.length);
|
||||||
var begin = Math.max(targetLine - 2, 1);
|
|
||||||
var end = Math.min(targetLine + 3, lines.length);
|
|
||||||
var context = range(begin, end + 1)
|
var context = range(begin, end + 1)
|
||||||
.map(function (lineNumber) {
|
.map(function (lineNumber) {
|
||||||
var indicator = (lineNumber === targetLine) ? '>> ' : ' ';
|
var indicator = (lineNumber === token.line) ? '>> ' : ' ';
|
||||||
var num = padStart(String(lineNumber), String(end).length);
|
var num = padStart(String(lineNumber), String(end).length);
|
||||||
var text = lines[lineNumber - 1];
|
var text = lines[lineNumber - 1];
|
||||||
return "" + indicator + num + "| " + text;
|
return "" + indicator + num + "| " + text;
|
||||||
@@ -396,13 +363,9 @@ function mkContext(input, targetLine) {
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
function mkMessage(msg, token) {
|
function mkMessage(msg, token) {
|
||||||
msg = msg || '';
|
if (token.file)
|
||||||
if (token.file) {
|
msg += ", file:" + token.file;
|
||||||
msg += ', file:' + token.file;
|
msg += ", line:" + token.line + ", col:" + token.col;
|
||||||
}
|
|
||||||
if (token.line) {
|
|
||||||
msg += ", line:" + token.line + ", col:" + token.col;
|
|
||||||
}
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -462,12 +425,13 @@ var Scope = /** @class */ (function () {
|
|||||||
function Scope(ctx, opts) {
|
function Scope(ctx, opts) {
|
||||||
if (ctx === void 0) { ctx = {}; }
|
if (ctx === void 0) { ctx = {}; }
|
||||||
this.blocks = {};
|
this.blocks = {};
|
||||||
|
this.groups = {};
|
||||||
this.blockMode = BlockMode$1.OUTPUT;
|
this.blockMode = BlockMode$1.OUTPUT;
|
||||||
this.opts = applyDefault(opts);
|
this.opts = applyDefault(opts);
|
||||||
this.contexts = [ctx || {}];
|
this.contexts = [ctx || {}];
|
||||||
}
|
}
|
||||||
Scope.prototype.getAll = function () {
|
Scope.prototype.getAll = function () {
|
||||||
return this.contexts.reduce(function (ctx, val) { return assign(ctx, val); }, create(null));
|
return this.contexts.reduce(function (ctx, val) { return __assign(ctx, val); }, {});
|
||||||
};
|
};
|
||||||
Scope.prototype.get = function (path$$1) {
|
Scope.prototype.get = function (path$$1) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -490,6 +454,7 @@ var Scope = /** @class */ (function () {
|
|||||||
scope[key] = {};
|
scope[key] = {};
|
||||||
}
|
}
|
||||||
scope = scope[key];
|
scope = scope[key];
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Scope.prototype.unshift = function (ctx) {
|
Scope.prototype.unshift = function (ctx) {
|
||||||
@@ -724,10 +689,12 @@ function trimRight(token, greedy) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Token = /** @class */ (function () {
|
var Token = /** @class */ (function () {
|
||||||
function Token(raw, col, input, file, line) {
|
function Token(raw, input, line, col, file) {
|
||||||
|
this.type = 'notset';
|
||||||
this.col = col;
|
this.col = col;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
|
this.value = raw;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
@@ -736,8 +703,8 @@ var Token = /** @class */ (function () {
|
|||||||
|
|
||||||
var HTMLToken = /** @class */ (function (_super) {
|
var HTMLToken = /** @class */ (function (_super) {
|
||||||
__extends(HTMLToken, _super);
|
__extends(HTMLToken, _super);
|
||||||
function HTMLToken(str, begin, input, file, line) {
|
function HTMLToken(str, input, line, col, file) {
|
||||||
var _this = _super.call(this, str, begin, input, file, line) || this;
|
var _this = _super.call(this, str, input, line, col, file) || this;
|
||||||
_this.type = 'html';
|
_this.type = 'html';
|
||||||
_this.value = str;
|
_this.value = str;
|
||||||
return _this;
|
return _this;
|
||||||
@@ -747,10 +714,10 @@ var HTMLToken = /** @class */ (function (_super) {
|
|||||||
|
|
||||||
var DelimitedToken = /** @class */ (function (_super) {
|
var DelimitedToken = /** @class */ (function (_super) {
|
||||||
__extends(DelimitedToken, _super);
|
__extends(DelimitedToken, _super);
|
||||||
function DelimitedToken(raw, value, pos, input, file, line) {
|
function DelimitedToken(raw, value, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, input, line, pos, file) || this;
|
||||||
_this.trimLeft = value[0] === '-';
|
_this.trimLeft = value[0] === '-';
|
||||||
_this.trimRight = value[value.length - 1] === '-';
|
_this.trimRight = last(value) === '-';
|
||||||
_this.value = value
|
_this.value = value
|
||||||
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
|
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
|
||||||
.trim();
|
.trim();
|
||||||
@@ -761,8 +728,8 @@ var DelimitedToken = /** @class */ (function (_super) {
|
|||||||
|
|
||||||
var TagToken = /** @class */ (function (_super) {
|
var TagToken = /** @class */ (function (_super) {
|
||||||
__extends(TagToken, _super);
|
__extends(TagToken, _super);
|
||||||
function TagToken(raw, value$$1, pos, input, file, line) {
|
function TagToken(raw, value$$1, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, value$$1, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, value$$1, input, line, pos, file) || this;
|
||||||
_this.type = 'tag';
|
_this.type = 'tag';
|
||||||
var match = _this.value.match(tagLine);
|
var match = _this.value.match(tagLine);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
@@ -777,8 +744,8 @@ var TagToken = /** @class */ (function (_super) {
|
|||||||
|
|
||||||
var OutputToken = /** @class */ (function (_super) {
|
var OutputToken = /** @class */ (function (_super) {
|
||||||
__extends(OutputToken, _super);
|
__extends(OutputToken, _super);
|
||||||
function OutputToken(raw, value, pos, input, file, line) {
|
function OutputToken(raw, value, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, value, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, value, input, line, pos, file) || this;
|
||||||
_this.type = 'output';
|
_this.type = 'output';
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -816,7 +783,7 @@ var Tokenizer = /** @class */ (function () {
|
|||||||
if (state === ParseState.HTML) {
|
if (state === ParseState.HTML) {
|
||||||
if (input.substr(p, outputL.length) === outputL) {
|
if (input.substr(p, outputL.length) === outputL) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
buffer = outputL;
|
buffer = outputL;
|
||||||
line = curLine;
|
line = curLine;
|
||||||
col = p - lineBegin + 1;
|
col = p - lineBegin + 1;
|
||||||
@@ -826,7 +793,7 @@ var Tokenizer = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
else if (input.substr(p, tagL.length) === tagL) {
|
else if (input.substr(p, tagL.length) === tagL) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
buffer = tagL;
|
buffer = tagL;
|
||||||
line = curLine;
|
line = curLine;
|
||||||
col = p - lineBegin + 1;
|
col = p - lineBegin + 1;
|
||||||
@@ -837,7 +804,7 @@ var Tokenizer = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
|
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
|
||||||
buffer += outputR;
|
buffer += outputR;
|
||||||
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), col, input, file, line));
|
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), input, line, col, file));
|
||||||
p += outputR.length;
|
p += outputR.length;
|
||||||
buffer = '';
|
buffer = '';
|
||||||
line = curLine;
|
line = curLine;
|
||||||
@@ -847,7 +814,7 @@ var Tokenizer = /** @class */ (function () {
|
|||||||
}
|
}
|
||||||
else if (input.substr(p, tagR.length) === tagR) {
|
else if (input.substr(p, tagR.length) === tagR) {
|
||||||
buffer += tagR;
|
buffer += tagR;
|
||||||
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), col, input, file, line));
|
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), input, line, col, file));
|
||||||
p += tagR.length;
|
p += tagR.length;
|
||||||
buffer = '';
|
buffer = '';
|
||||||
line = curLine;
|
line = curLine;
|
||||||
@@ -860,10 +827,10 @@ var Tokenizer = /** @class */ (function () {
|
|||||||
if (state !== ParseState.HTML) {
|
if (state !== ParseState.HTML) {
|
||||||
var t = state === ParseState.OUTPUT ? 'output' : 'tag';
|
var t = state === ParseState.OUTPUT ? 'output' : 'tag';
|
||||||
var str = buffer.length > 16 ? buffer.slice(0, 13) + '...' : buffer;
|
var str = buffer.length > 16 ? buffer.slice(0, 13) + '...' : buffer;
|
||||||
throw new TokenizationError(new Error(t + " \"" + str + "\" not closed"), new Token(buffer, col, input, file, line));
|
throw new TokenizationError(t + " \"" + str + "\" not closed", new Token(buffer, input, line, col, file));
|
||||||
}
|
}
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
whiteSpaceCtrl(tokens, this.options);
|
whiteSpaceCtrl(tokens, this.options);
|
||||||
return tokens;
|
return tokens;
|
||||||
};
|
};
|
||||||
@@ -896,11 +863,11 @@ var Render = /** @class */ (function () {
|
|||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 5];
|
||||||
case 4:
|
case 4:
|
||||||
e_1 = _b.sent();
|
e_1 = _b.sent();
|
||||||
if (e_1 instanceof RenderBreakError) {
|
if (e_1.name === 'RenderBreakError') {
|
||||||
e_1.resolvedHTML = html;
|
e_1.resolvedHTML = html;
|
||||||
throw e_1;
|
throw e_1;
|
||||||
}
|
}
|
||||||
throw e_1 instanceof RenderError ? e_1 : new RenderError(e_1, tpl);
|
throw e_1.name === 'RenderError' ? e_1 : new RenderError(e_1, tpl);
|
||||||
case 5:
|
case 5:
|
||||||
_i++;
|
_i++;
|
||||||
return [3 /*break*/, 1];
|
return [3 /*break*/, 1];
|
||||||
@@ -946,11 +913,7 @@ function evalExp(exp, scope) {
|
|||||||
if ((match = exp.match(rangeLine))) {
|
if ((match = exp.match(rangeLine))) {
|
||||||
var low = evalValue(match[1], scope);
|
var low = evalValue(match[1], scope);
|
||||||
var high = evalValue(match[2], scope);
|
var high = evalValue(match[2], scope);
|
||||||
var range = [];
|
return range(low, high + 1);
|
||||||
for (var j = low; j <= high; j++) {
|
|
||||||
range.push(j);
|
|
||||||
}
|
|
||||||
return range;
|
|
||||||
}
|
}
|
||||||
return evalValue(exp, scope);
|
return evalValue(exp, scope);
|
||||||
}
|
}
|
||||||
@@ -1071,8 +1034,7 @@ var Filter = /** @class */ (function () {
|
|||||||
};
|
};
|
||||||
Filter.prototype.render = function (value$$1, scope) {
|
Filter.prototype.render = function (value$$1, scope) {
|
||||||
var args = this.args.map(function (arg) { return evalValue(arg, scope); });
|
var args = this.args.map(function (arg) { return evalValue(arg, scope); });
|
||||||
args.unshift(value$$1);
|
return this.impl.apply(null, [value$$1].concat(args));
|
||||||
return this.impl.apply(null, args);
|
|
||||||
};
|
};
|
||||||
Filter.register = function (name, filter$$1) {
|
Filter.register = function (name, filter$$1) {
|
||||||
Filter.impls[name] = filter$$1;
|
Filter.impls[name] = filter$$1;
|
||||||
@@ -1087,6 +1049,7 @@ var Filter = /** @class */ (function () {
|
|||||||
var ParseStream = /** @class */ (function () {
|
var ParseStream = /** @class */ (function () {
|
||||||
function ParseStream(tokens, parseToken) {
|
function ParseStream(tokens, parseToken) {
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
|
this.stopRequested = false;
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
this.parseToken = parseToken;
|
this.parseToken = parseToken;
|
||||||
}
|
}
|
||||||
@@ -1100,6 +1063,7 @@ var ParseStream = /** @class */ (function () {
|
|||||||
h(arg);
|
h(arg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
ParseStream.prototype.start = function () {
|
ParseStream.prototype.start = function () {
|
||||||
this.trigger('start');
|
this.trigger('start');
|
||||||
@@ -1107,8 +1071,7 @@ var ParseStream = /** @class */ (function () {
|
|||||||
while (!this.stopRequested && (token = this.tokens.shift())) {
|
while (!this.stopRequested && (token = this.tokens.shift())) {
|
||||||
if (this.trigger('token', token))
|
if (this.trigger('token', token))
|
||||||
continue;
|
continue;
|
||||||
if (token.type === 'tag' &&
|
if (token.type === 'tag' && this.trigger("tag:" + token.name, token)) {
|
||||||
this.trigger("tag:" + token.name, token)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var template = this.parseToken(token, this.tokens);
|
var template = this.parseToken(token, this.tokens);
|
||||||
@@ -1127,16 +1090,14 @@ var ParseStream = /** @class */ (function () {
|
|||||||
|
|
||||||
var default_1 = /** @class */ (function () {
|
var default_1 = /** @class */ (function () {
|
||||||
function default_1(str, strictFilters) {
|
function default_1(str, strictFilters) {
|
||||||
|
this.filters = [];
|
||||||
var match = matchValue(str);
|
var match = matchValue(str);
|
||||||
assert(match, "illegal value string: " + str);
|
assert(match, "illegal value string: " + str);
|
||||||
var initial = match[0];
|
this.initial = match[0];
|
||||||
str = str.substr(match.index + match[0].length);
|
str = str.substr(match.index + match[0].length);
|
||||||
var filters = [];
|
|
||||||
while ((match = filter.exec(str))) {
|
while ((match = filter.exec(str))) {
|
||||||
filters.push([match[0].trim()]);
|
this.filters.push(new Filter(match[0].trim(), strictFilters));
|
||||||
}
|
}
|
||||||
this.initial = initial;
|
|
||||||
this.filters = filters.map(function (str) { return new Filter(str, strictFilters); });
|
|
||||||
}
|
}
|
||||||
default_1.prototype.value = function (scope) {
|
default_1.prototype.value = function (scope) {
|
||||||
return this.filters.reduce(function (prev, filter$$1) { return filter$$1.render(prev, scope); }, evalExp(this.initial, scope));
|
return this.filters.reduce(function (prev, filter$$1) { return filter$$1.render(prev, scope); }, evalExp(this.initial, scope));
|
||||||
@@ -1218,7 +1179,7 @@ var Parser = /** @class */ (function () {
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
var re = new RegExp("(" + identifier.source + ")\\s*=([^]*)");
|
var re = new RegExp("(" + identifier.source + ")\\s*=([^]*)");
|
||||||
var assign$1 = {
|
var assign = {
|
||||||
parse: function (token) {
|
parse: function (token) {
|
||||||
var match = token.args.match(re);
|
var match = token.args.match(re);
|
||||||
assert(match, "illegal token " + token.raw);
|
assert(match, "illegal token " + token.raw);
|
||||||
@@ -1233,12 +1194,6 @@ var assign$1 = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Call functions in serial until someone resolved.
|
|
||||||
* @param iterable the array to iterate with.
|
|
||||||
* @param iteratee returns a new promise.
|
|
||||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* Call functions in serial until someone rejected.
|
* Call functions in serial until someone rejected.
|
||||||
* @param {Array} iterable the array to iterate with.
|
* @param {Array} iterable the array to iterate with.
|
||||||
@@ -1246,7 +1201,7 @@ var assign$1 = {
|
|||||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||||
*/
|
*/
|
||||||
function mapSeries(iterable, iteratee) {
|
function mapSeries(iterable, iteratee) {
|
||||||
var ret = Promise.resolve('init');
|
var ret = Promise.resolve(0);
|
||||||
var result = [];
|
var result = [];
|
||||||
iterable.forEach(function (item, idx) {
|
iterable.forEach(function (item, idx) {
|
||||||
ret = ret
|
ret = ret
|
||||||
@@ -1261,107 +1216,109 @@ var re$1 = new RegExp("^(" + identifier.source + ")\\s+in\\s+" +
|
|||||||
("(?:\\s+" + hash.source + ")*") +
|
("(?:\\s+" + hash.source + ")*") +
|
||||||
"(?:\\s+(reversed))?" +
|
"(?:\\s+(reversed))?" +
|
||||||
("(?:\\s+" + hash.source + ")*$"));
|
("(?:\\s+" + hash.source + ")*$"));
|
||||||
function parse(tagToken, remainTokens) {
|
var For = {
|
||||||
var _this = this;
|
type: 'block',
|
||||||
var match = re$1.exec(tagToken.args);
|
parse: function (tagToken, remainTokens) {
|
||||||
assert(match, "illegal tag: " + tagToken.raw);
|
|
||||||
this.variable = match[1];
|
|
||||||
this.collection = match[2];
|
|
||||||
this.reversed = !!match[3];
|
|
||||||
this.templates = [];
|
|
||||||
this.elseTemplates = [];
|
|
||||||
var p;
|
|
||||||
var stream = this.liquid.parser.parseStream(remainTokens)
|
|
||||||
.on('start', function () { return (p = _this.templates); })
|
|
||||||
.on('tag:else', function () { return (p = _this.elseTemplates); })
|
|
||||||
.on('tag:endfor', function () { return stream.stop(); })
|
|
||||||
.on('template', function (tpl) { return p.push(tpl); })
|
|
||||||
.on('end', function () {
|
|
||||||
throw new Error("tag " + tagToken.raw + " not closed");
|
|
||||||
});
|
|
||||||
stream.start();
|
|
||||||
}
|
|
||||||
function render(scope, hash$$1) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var collection, offset, limit, contexts, html, finished;
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return __generator(this, function (_a) {
|
var match = re$1.exec(tagToken.args);
|
||||||
switch (_a.label) {
|
assert(match, "illegal tag: " + tagToken.raw);
|
||||||
case 0:
|
this.variable = match[1];
|
||||||
collection = evalExp(this.collection, scope);
|
this.collection = match[2];
|
||||||
if (!isArray(collection)) {
|
this.reversed = !!match[3];
|
||||||
if (isString(collection) && collection.length > 0) {
|
this.templates = [];
|
||||||
collection = [collection];
|
this.elseTemplates = [];
|
||||||
}
|
var p;
|
||||||
else if (isObject(collection)) {
|
var stream = this.liquid.parser.parseStream(remainTokens)
|
||||||
collection = Object.keys(collection).map(function (key) { return [key, collection[key]]; });
|
.on('start', function () { return (p = _this.templates); })
|
||||||
}
|
.on('tag:else', function () { return (p = _this.elseTemplates); })
|
||||||
}
|
.on('tag:endfor', function () { return stream.stop(); })
|
||||||
if (!isArray(collection) || !collection.length) {
|
.on('template', function (tpl) { return p.push(tpl); })
|
||||||
return [2 /*return*/, this.liquid.renderer.renderTemplates(this.elseTemplates, scope)];
|
.on('end', function () {
|
||||||
}
|
throw new Error("tag " + tagToken.raw + " not closed");
|
||||||
offset = hash$$1.offset || 0;
|
|
||||||
limit = (hash$$1.limit === undefined) ? collection.length : hash$$1.limit;
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
|
||||||
if (this.reversed)
|
|
||||||
collection.reverse();
|
|
||||||
contexts = collection.map(function (item, i) {
|
|
||||||
var ctx = {};
|
|
||||||
ctx[_this.variable] = item;
|
|
||||||
ctx['forloop'] = {
|
|
||||||
first: i === 0,
|
|
||||||
index: i + 1,
|
|
||||||
index0: i,
|
|
||||||
last: i === collection.length - 1,
|
|
||||||
length: collection.length,
|
|
||||||
rindex: collection.length - i,
|
|
||||||
rindex0: collection.length - i - 1
|
|
||||||
};
|
|
||||||
return ctx;
|
|
||||||
});
|
|
||||||
html = '';
|
|
||||||
finished = false;
|
|
||||||
return [4 /*yield*/, mapSeries(contexts, function (context) { return __awaiter(_this, void 0, void 0, function () {
|
|
||||||
var _a, e_1;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (finished)
|
|
||||||
return [2 /*return*/];
|
|
||||||
scope.push(context);
|
|
||||||
_b.label = 1;
|
|
||||||
case 1:
|
|
||||||
_b.trys.push([1, 3, , 4]);
|
|
||||||
_a = html;
|
|
||||||
return [4 /*yield*/, this.liquid.renderer.renderTemplates(this.templates, scope)];
|
|
||||||
case 2:
|
|
||||||
html = _a + _b.sent();
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 3:
|
|
||||||
e_1 = _b.sent();
|
|
||||||
if (e_1 instanceof RenderBreakError) {
|
|
||||||
html += e_1.resolvedHTML;
|
|
||||||
if (e_1.message === 'break') {
|
|
||||||
finished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw e_1;
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 4:
|
|
||||||
scope.pop(context);
|
|
||||||
return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); })];
|
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
return [2 /*return*/, html];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
stream.start();
|
||||||
}
|
},
|
||||||
var For = { parse: parse, render: render };
|
render: function (scope, hash$$1) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var collection, offset, limit, contexts, html, finished;
|
||||||
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
collection = evalExp(this.collection, scope);
|
||||||
|
if (!isArray(collection)) {
|
||||||
|
if (isString(collection) && collection.length > 0) {
|
||||||
|
collection = [collection];
|
||||||
|
}
|
||||||
|
else if (isObject(collection)) {
|
||||||
|
collection = Object.keys(collection).map(function (key) { return [key, collection[key]]; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isArray(collection) || !collection.length) {
|
||||||
|
return [2 /*return*/, this.liquid.renderer.renderTemplates(this.elseTemplates, scope)];
|
||||||
|
}
|
||||||
|
offset = hash$$1.offset || 0;
|
||||||
|
limit = (hash$$1.limit === undefined) ? collection.length : hash$$1.limit;
|
||||||
|
collection = collection.slice(offset, offset + limit);
|
||||||
|
if (this.reversed)
|
||||||
|
collection.reverse();
|
||||||
|
contexts = collection.map(function (item, i) {
|
||||||
|
var ctx = {};
|
||||||
|
ctx[_this.variable] = item;
|
||||||
|
ctx['forloop'] = {
|
||||||
|
first: i === 0,
|
||||||
|
index: i + 1,
|
||||||
|
index0: i,
|
||||||
|
last: i === collection.length - 1,
|
||||||
|
length: collection.length,
|
||||||
|
rindex: collection.length - i,
|
||||||
|
rindex0: collection.length - i - 1
|
||||||
|
};
|
||||||
|
return ctx;
|
||||||
|
});
|
||||||
|
html = '';
|
||||||
|
finished = false;
|
||||||
|
return [4 /*yield*/, mapSeries(contexts, function (context) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
var _a, e_1;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
switch (_b.label) {
|
||||||
|
case 0:
|
||||||
|
if (finished)
|
||||||
|
return [2 /*return*/];
|
||||||
|
scope.push(context);
|
||||||
|
_b.label = 1;
|
||||||
|
case 1:
|
||||||
|
_b.trys.push([1, 3, , 4]);
|
||||||
|
_a = html;
|
||||||
|
return [4 /*yield*/, this.liquid.renderer.renderTemplates(this.templates, scope)];
|
||||||
|
case 2:
|
||||||
|
html = _a + _b.sent();
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 3:
|
||||||
|
e_1 = _b.sent();
|
||||||
|
if (e_1.name === 'RenderBreakError') {
|
||||||
|
html += e_1.resolvedHTML;
|
||||||
|
if (e_1.message === 'break') {
|
||||||
|
finished = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw e_1;
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 4:
|
||||||
|
scope.pop(context);
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); })];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/, html];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var re$2 = new RegExp("(" + identifier.source + ")");
|
var re$2 = new RegExp("(" + identifier.source + ")");
|
||||||
var capture = {
|
var capture = {
|
||||||
@@ -1548,7 +1505,7 @@ var cycle = {
|
|||||||
render: function (scope) {
|
render: function (scope) {
|
||||||
var group = evalValue(this.group, scope);
|
var group = evalValue(this.group, scope);
|
||||||
var fingerprint = "cycle:" + group + ":" + this.candidates.join(',');
|
var fingerprint = "cycle:" + group + ":" + this.candidates.join(',');
|
||||||
var groups = scope.opts.groups = scope.opts.groups || {};
|
var groups = scope.groups;
|
||||||
var idx = groups[fingerprint];
|
var idx = groups[fingerprint];
|
||||||
if (idx === undefined) {
|
if (idx === undefined) {
|
||||||
idx = groups[fingerprint] = 0;
|
idx = groups[fingerprint] = 0;
|
||||||
@@ -1768,6 +1725,7 @@ var tablerow = {
|
|||||||
ctx[_this.variable] = item;
|
ctx[_this.variable] = item;
|
||||||
return ctx;
|
return ctx;
|
||||||
});
|
});
|
||||||
|
row = 0;
|
||||||
html = '';
|
html = '';
|
||||||
return [4 /*yield*/, mapSeries(contexts, function (context, idx) { return __awaiter(_this, void 0, void 0, function () {
|
return [4 /*yield*/, mapSeries(contexts, function (context, idx) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
var col, _a;
|
var col, _a;
|
||||||
@@ -1854,7 +1812,7 @@ var Continue = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var tags = {
|
var tags = {
|
||||||
assign: assign$1, 'for': For, capture: capture, 'case': Case, comment: comment, include: include, decrement: decrement, increment: increment, cycle: cycle, 'if': If, layout: layout, block: block, raw: raw, tablerow: tablerow, unless: unless, 'break': Break, 'continue': Continue
|
assign: assign, 'for': For, capture: capture, 'case': Case, comment: comment, include: include, decrement: decrement, increment: increment, cycle: cycle, 'if': If, layout: layout, block: block, raw: raw, tablerow: tablerow, unless: unless, 'break': Break, 'continue': Continue
|
||||||
};
|
};
|
||||||
|
|
||||||
var escapeMap = {
|
var escapeMap = {
|
||||||
@@ -1881,14 +1839,13 @@ var html = {
|
|||||||
'escape': escape,
|
'escape': escape,
|
||||||
'escape_once': function (str) { return escape(unescape(str)); },
|
'escape_once': function (str) { return escape(unescape(str)); },
|
||||||
'newline_to_br': function (v) { return v.replace(/\n/g, '<br />'); },
|
'newline_to_br': function (v) { return v.replace(/\n/g, '<br />'); },
|
||||||
'strip_html': function (v) { return String(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''); }
|
'strip_html': function (v) { return v.replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''); }
|
||||||
};
|
};
|
||||||
|
|
||||||
var str = {
|
var str = {
|
||||||
'append': function (v, arg) { return v + arg; },
|
'append': function (v, arg) { return v + arg; },
|
||||||
'prepend': function (v, arg) { return arg + v; },
|
'prepend': function (v, arg) { return arg + v; },
|
||||||
'capitalize': function (str) { return String(str).charAt(0).toUpperCase() + str.slice(1); },
|
'capitalize': function (str) { return String(str).charAt(0).toUpperCase() + str.slice(1); },
|
||||||
'concat': function (v, arg) { return Array.prototype.concat.call(v, arg); },
|
|
||||||
'lstrip': function (v) { return String(v).replace(/^\s+/, ''); },
|
'lstrip': function (v) { return String(v).replace(/^\s+/, ''); },
|
||||||
'downcase': function (v) { return v.toLowerCase(); },
|
'downcase': function (v) { return v.toLowerCase(); },
|
||||||
'upcase': function (str) { return String(str).toUpperCase(); },
|
'upcase': function (str) { return String(str).toUpperCase(); },
|
||||||
@@ -1903,19 +1860,19 @@ var str = {
|
|||||||
'strip': function (v) { return String(v).trim(); },
|
'strip': function (v) { return String(v).trim(); },
|
||||||
'strip_newlines': function (v) { return String(v).replace(/\n/g, ''); },
|
'strip_newlines': function (v) { return String(v).replace(/\n/g, ''); },
|
||||||
'truncate': function (v, l, o) {
|
'truncate': function (v, l, o) {
|
||||||
|
if (l === void 0) { l = 50; }
|
||||||
|
if (o === void 0) { o = '...'; }
|
||||||
v = String(v);
|
v = String(v);
|
||||||
o = (o === undefined) ? '...' : o;
|
|
||||||
l = l || 16;
|
|
||||||
if (v.length <= l)
|
if (v.length <= l)
|
||||||
return v;
|
return v;
|
||||||
return v.substr(0, l - o.length) + o;
|
return v.substr(0, l - o.length) + o;
|
||||||
},
|
},
|
||||||
'truncatewords': function (v, l, o) {
|
'truncatewords': function (v, l, o) {
|
||||||
if (o === undefined)
|
if (l === void 0) { l = 15; }
|
||||||
o = '...';
|
if (o === void 0) { o = '...'; }
|
||||||
var arr = v.split(' ');
|
var arr = v.split(/\s+/);
|
||||||
var ret = arr.slice(0, l).join(' ');
|
var ret = arr.slice(0, l).join(' ');
|
||||||
if (arr.length > l)
|
if (arr.length >= l)
|
||||||
ret += o;
|
ret += o;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -1929,7 +1886,8 @@ var math = {
|
|||||||
'minus': bindFixed(function (v, arg) { return v - arg; }),
|
'minus': bindFixed(function (v, arg) { return v - arg; }),
|
||||||
'modulo': bindFixed(function (v, arg) { return v % arg; }),
|
'modulo': bindFixed(function (v, arg) { return v % arg; }),
|
||||||
'round': function (v, arg) {
|
'round': function (v, arg) {
|
||||||
var amp = Math.pow(10, arg || 0);
|
if (arg === void 0) { arg = 0; }
|
||||||
|
var amp = Math.pow(10, arg);
|
||||||
return Math.round(v * amp) / amp;
|
return Math.round(v * amp) / amp;
|
||||||
},
|
},
|
||||||
'plus': bindFixed(function (v, arg) { return Number(v) + Number(arg); }),
|
'plus': bindFixed(function (v, arg) { return Number(v) + Number(arg); }),
|
||||||
@@ -1959,6 +1917,7 @@ var array = {
|
|||||||
'reverse': function (v) { return v.reverse(); },
|
'reverse': function (v) { return v.reverse(); },
|
||||||
'sort': function (v, arg) { return v.sort(arg); },
|
'sort': function (v, arg) { return v.sort(arg); },
|
||||||
'size': function (v) { return v.length; },
|
'size': function (v) { return v.length; },
|
||||||
|
'concat': function (v, arg) { return Array.prototype.concat.call(v, arg); },
|
||||||
'slice': function (v, begin, length) {
|
'slice': function (v, begin, length) {
|
||||||
if (length === undefined)
|
if (length === undefined)
|
||||||
length = 1;
|
length = 1;
|
||||||
@@ -1967,10 +1926,9 @@ var array = {
|
|||||||
'uniq': function (arr) {
|
'uniq': function (arr) {
|
||||||
var u = {};
|
var u = {};
|
||||||
return (arr || []).filter(function (val) {
|
return (arr || []).filter(function (val) {
|
||||||
if (u.hasOwnProperty(val)) {
|
if (u.hasOwnProperty(String(val)))
|
||||||
return false;
|
return false;
|
||||||
}
|
u[String(val)] = true;
|
||||||
u[val] = true;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2142,7 +2100,7 @@ function strftime (d, format) {
|
|||||||
// Add the format code
|
// Add the format code
|
||||||
var ch = results[0].charAt(1);
|
var ch = results[0].charAt(1);
|
||||||
var func = formatCodes[ch];
|
var func = formatCodes[ch];
|
||||||
output += func ? func.call(this, d) : '%' + ch;
|
output += func ? func(d) : '%' + ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2172,10 +2130,8 @@ var Liquid = /** @class */ (function () {
|
|||||||
function Liquid(opts) {
|
function Liquid(opts) {
|
||||||
if (opts === void 0) { opts = {}; }
|
if (opts === void 0) { opts = {}; }
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
this.cache = {};
|
||||||
this.options = applyDefault(normalize(opts));
|
this.options = applyDefault(normalize(opts));
|
||||||
if (this.options.cache) {
|
|
||||||
this.cache = {};
|
|
||||||
}
|
|
||||||
this.parser = new Parser(this);
|
this.parser = new Parser(this);
|
||||||
this.renderer = new Render();
|
this.renderer = new Render();
|
||||||
this.tokenizer = new Tokenizer(this.options);
|
this.tokenizer = new Tokenizer(this.options);
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+11
-8
@@ -1,26 +1,29 @@
|
|||||||
import Scope from './scope/scope';
|
import Scope from './scope/scope';
|
||||||
import * as Types from './types';
|
import * as Types from './types';
|
||||||
import ITemplate from './template/itemplate';
|
import ITemplate from './template/itemplate';
|
||||||
|
import Render from './render/render';
|
||||||
|
import Parser from './parser/parser';
|
||||||
import ITagImplOptions from './template/tag/itag-impl-options';
|
import ITagImplOptions from './template/tag/itag-impl-options';
|
||||||
import { isTruthy, isFalsy, evalExp, evalValue } from './render/syntax';
|
import { isTruthy, isFalsy, evalExp, evalValue } from './render/syntax';
|
||||||
import { LiquidOptions, NormalizedFullOptions } from './liquid-options';
|
import { LiquidOptions, NormalizedFullOptions } from './liquid-options';
|
||||||
|
import { FilterImpl } from './template/filter/filter-impl';
|
||||||
export default class Liquid {
|
export default class Liquid {
|
||||||
options: NormalizedFullOptions;
|
options: NormalizedFullOptions;
|
||||||
|
renderer: Render;
|
||||||
|
parser: Parser;
|
||||||
private cache;
|
private cache;
|
||||||
private parser;
|
|
||||||
private renderer;
|
|
||||||
private tokenizer;
|
private tokenizer;
|
||||||
constructor(opts?: LiquidOptions);
|
constructor(opts?: LiquidOptions);
|
||||||
parse(html: string, filepath?: string): any[];
|
parse(html: string, filepath?: string): ITemplate[];
|
||||||
render(tpl: Array<ITemplate>, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
render(tpl: Array<ITemplate>, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
||||||
parseAndRender(html: string, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
parseAndRender(html: string, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
||||||
getTemplate(file: any, opts?: LiquidOptions): Promise<any>;
|
getTemplate(file: string, opts?: LiquidOptions): Promise<any>;
|
||||||
renderFile(file: any, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
renderFile(file: string, ctx?: object, opts?: LiquidOptions): Promise<string>;
|
||||||
evalValue(str: string, scope: Scope): any;
|
evalValue(str: string, scope: Scope): any;
|
||||||
registerFilter(name: any, filter: any): void;
|
registerFilter(name: string, filter: FilterImpl): void;
|
||||||
registerTag(name: string, tag: ITagImplOptions): void;
|
registerTag(name: string, tag: ITagImplOptions): void;
|
||||||
plugin(plugin: any): any;
|
plugin(plugin: (this: Liquid, L: typeof Liquid) => void): void;
|
||||||
express(): (filePath: string, ctx: object, cb: (err: Error, html?: string) => void) => void;
|
express(): (this: any, filePath: string, ctx: object, cb: (err: Error | null, html?: string | undefined) => void) => void;
|
||||||
static default: typeof Liquid;
|
static default: typeof Liquid;
|
||||||
static isTruthy: typeof isTruthy;
|
static isTruthy: typeof isTruthy;
|
||||||
static isFalsy: typeof isFalsy;
|
static isFalsy: typeof isFalsy;
|
||||||
|
|||||||
Vendored
+194
-238
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* [email protected].0, https://github.com/harttle/liquidjs
|
* [email protected].1, https://github.com/harttle/liquidjs
|
||||||
* (c) 2016-2019 harttle
|
* (c) 2016-2019 harttle
|
||||||
* Released under the MIT License.
|
* Released under the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -154,32 +154,6 @@
|
|||||||
}
|
}
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
* Assigns own enumerable string keyed properties of source objects to the destination object.
|
|
||||||
* Source objects are applied from left to right.
|
|
||||||
* Subsequent sources overwrite property assignments of previous sources.
|
|
||||||
*
|
|
||||||
* Note: This method mutates object and is loosely based on Object.assign.
|
|
||||||
*
|
|
||||||
* @param {Object} object The destination object.
|
|
||||||
* @param {...Object} sources The source objects.
|
|
||||||
* @return {Object} Returns object.
|
|
||||||
*/
|
|
||||||
function assign(obj) {
|
|
||||||
var srcs = [];
|
|
||||||
for (var _i = 1; _i < arguments.length; _i++) {
|
|
||||||
srcs[_i - 1] = arguments[_i];
|
|
||||||
}
|
|
||||||
obj = isObject(obj) ? obj : {};
|
|
||||||
srcs.forEach(function (src) { return binaryAssign(obj, src); });
|
|
||||||
return obj;
|
|
||||||
}
|
|
||||||
function binaryAssign(target, src) {
|
|
||||||
for (var key in src)
|
|
||||||
if (src.hasOwnProperty(key))
|
|
||||||
target[key] = src[key];
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
function last(arr) {
|
function last(arr) {
|
||||||
return arr[arr.length - 1];
|
return arr[arr.length - 1];
|
||||||
}
|
}
|
||||||
@@ -202,7 +176,7 @@
|
|||||||
* negative — if you'd like a negative range, use a negative step.
|
* negative — if you'd like a negative range, use a negative step.
|
||||||
*/
|
*/
|
||||||
function range(start, stop, step) {
|
function range(start, stop, step) {
|
||||||
if (arguments.length === 1) {
|
if (stop === undefined) {
|
||||||
stop = start;
|
stop = start;
|
||||||
start = 0;
|
start = 0;
|
||||||
}
|
}
|
||||||
@@ -229,7 +203,7 @@
|
|||||||
var quoteBalanced = new RegExp("(?:" + quoted.source + "|[^'\"])*");
|
var quoteBalanced = new RegExp("(?:" + quoted.source + "|[^'\"])*");
|
||||||
// basic types
|
// basic types
|
||||||
var integer = /-?\d+/;
|
var integer = /-?\d+/;
|
||||||
var number = /-?\d+\.?\d*|\.?\d+/;
|
var number = /[+-]?(?:\d+\.?\d*|\.?\d+)/;
|
||||||
var bool = /true|false/;
|
var bool = /true|false/;
|
||||||
// property access
|
// property access
|
||||||
var identifier = /[\w-]+[?]?/;
|
var identifier = /[\w-]+[?]?/;
|
||||||
@@ -292,90 +266,83 @@
|
|||||||
throw new TypeError("cannot parse '" + str + "' as literal");
|
throw new TypeError("cannot parse '" + str + "' as literal");
|
||||||
}
|
}
|
||||||
|
|
||||||
function captureStack() {
|
var LiquidError = /** @class */ (function (_super) {
|
||||||
if (Error.captureStackTrace) {
|
__extends(LiquidError, _super);
|
||||||
Error.captureStackTrace(this, this.constructor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var LiquidError = /** @class */ (function () {
|
|
||||||
function LiquidError(err, token) {
|
function LiquidError(err, token) {
|
||||||
this.input = token.input;
|
var _this = _super.call(this, err.message) || this;
|
||||||
this.file = token.file;
|
_this.originalError = err;
|
||||||
this.originalError = err;
|
_this.token = token;
|
||||||
this.token = token;
|
return _this;
|
||||||
}
|
}
|
||||||
LiquidError.prototype.captureStackTrace = function (obj) {
|
LiquidError.prototype.update = function () {
|
||||||
this.name = obj.constructor.name;
|
|
||||||
captureStack.call(obj);
|
|
||||||
var err = this.originalError;
|
var err = this.originalError;
|
||||||
var context = mkContext(this.input, this.token.line);
|
var context = mkContext(this.token);
|
||||||
this.message = mkMessage(err.message, this.token);
|
this.message = mkMessage(err.message, this.token);
|
||||||
this.stack = this.message + '\n' + context +
|
this.stack = this.message + '\n' + context +
|
||||||
'\n' + (this.stack || this.message) +
|
'\n' + this.stack + '\nFrom ' + err.stack;
|
||||||
(err.stack ? '\nFrom ' + err.stack : '');
|
|
||||||
};
|
};
|
||||||
return LiquidError;
|
return LiquidError;
|
||||||
}());
|
}(Error));
|
||||||
var TokenizationError = /** @class */ (function (_super) {
|
var TokenizationError = /** @class */ (function (_super) {
|
||||||
__extends(TokenizationError, _super);
|
__extends(TokenizationError, _super);
|
||||||
function TokenizationError(message, token) {
|
function TokenizationError(message, token) {
|
||||||
var _this = _super.call(this, { message: message }, token) || this;
|
var _this = _super.call(this, new Error(message), token) || this;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_this.name = 'TokenizationError';
|
||||||
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return TokenizationError;
|
return TokenizationError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
TokenizationError.prototype = create(Error.prototype);
|
|
||||||
TokenizationError.prototype.constructor = TokenizationError;
|
|
||||||
var ParseError = /** @class */ (function (_super) {
|
var ParseError = /** @class */ (function (_super) {
|
||||||
__extends(ParseError, _super);
|
__extends(ParseError, _super);
|
||||||
function ParseError(err, token) {
|
function ParseError(err, token) {
|
||||||
var _this = _super.call(this, err, token) || this;
|
var _this = _super.call(this, err, token) || this;
|
||||||
|
_this.name = 'ParseError';
|
||||||
_this.message = err.message;
|
_this.message = err.message;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return ParseError;
|
return ParseError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
ParseError.prototype = create(Error.prototype);
|
|
||||||
ParseError.prototype.constructor = ParseError;
|
|
||||||
var RenderError = /** @class */ (function (_super) {
|
var RenderError = /** @class */ (function (_super) {
|
||||||
__extends(RenderError, _super);
|
__extends(RenderError, _super);
|
||||||
function RenderError(err, tpl) {
|
function RenderError(err, tpl) {
|
||||||
var _this = _super.call(this, err, tpl.token) || this;
|
var _this = _super.call(this, err, tpl.token) || this;
|
||||||
|
_this.name = 'RenderError';
|
||||||
_this.message = err.message;
|
_this.message = err.message;
|
||||||
_super.prototype.captureStackTrace.call(_this, _this);
|
_super.prototype.update.call(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
return RenderError;
|
return RenderError;
|
||||||
}(LiquidError));
|
}(LiquidError));
|
||||||
RenderError.prototype = create(Error.prototype);
|
var RenderBreakError = /** @class */ (function (_super) {
|
||||||
RenderError.prototype.constructor = RenderError;
|
__extends(RenderBreakError, _super);
|
||||||
var RenderBreakError = /** @class */ (function () {
|
|
||||||
function RenderBreakError(message) {
|
function RenderBreakError(message) {
|
||||||
captureStack.call(this);
|
var _this = _super.call(this, message) || this;
|
||||||
this.message = message + '';
|
_this.resolvedHTML = '';
|
||||||
|
_this.name = 'RenderBreakError';
|
||||||
|
_this.message = message + '';
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
return RenderBreakError;
|
return RenderBreakError;
|
||||||
}());
|
}(Error));
|
||||||
RenderBreakError.prototype = create(Error.prototype);
|
var AssertionError = /** @class */ (function (_super) {
|
||||||
RenderBreakError.prototype.constructor = RenderBreakError;
|
__extends(AssertionError, _super);
|
||||||
var AssertionError = /** @class */ (function () {
|
|
||||||
function AssertionError(message) {
|
function AssertionError(message) {
|
||||||
captureStack.call(this);
|
var _this = _super.call(this, message) || this;
|
||||||
this.message = message + '';
|
_this.name = 'AssertionError';
|
||||||
|
_this.message = message + '';
|
||||||
|
return _this;
|
||||||
}
|
}
|
||||||
return AssertionError;
|
return AssertionError;
|
||||||
}());
|
}(Error));
|
||||||
AssertionError.prototype = create(Error.prototype);
|
function mkContext(token) {
|
||||||
AssertionError.prototype.constructor = AssertionError;
|
var lines = token.input.split('\n');
|
||||||
function mkContext(input, targetLine) {
|
var begin = Math.max(token.line - 2, 1);
|
||||||
var lines = input.split('\n');
|
var end = Math.min(token.line + 3, lines.length);
|
||||||
var begin = Math.max(targetLine - 2, 1);
|
|
||||||
var end = Math.min(targetLine + 3, lines.length);
|
|
||||||
var context = range(begin, end + 1)
|
var context = range(begin, end + 1)
|
||||||
.map(function (lineNumber) {
|
.map(function (lineNumber) {
|
||||||
var indicator = (lineNumber === targetLine) ? '>> ' : ' ';
|
var indicator = (lineNumber === token.line) ? '>> ' : ' ';
|
||||||
var num = padStart(String(lineNumber), String(end).length);
|
var num = padStart(String(lineNumber), String(end).length);
|
||||||
var text = lines[lineNumber - 1];
|
var text = lines[lineNumber - 1];
|
||||||
return "" + indicator + num + "| " + text;
|
return "" + indicator + num + "| " + text;
|
||||||
@@ -384,13 +351,9 @@
|
|||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
function mkMessage(msg, token) {
|
function mkMessage(msg, token) {
|
||||||
msg = msg || '';
|
if (token.file)
|
||||||
if (token.file) {
|
msg += ", file:" + token.file;
|
||||||
msg += ', file:' + token.file;
|
msg += ", line:" + token.line + ", col:" + token.col;
|
||||||
}
|
|
||||||
if (token.line) {
|
|
||||||
msg += ", line:" + token.line + ", col:" + token.col;
|
|
||||||
}
|
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -450,12 +413,13 @@
|
|||||||
function Scope(ctx, opts) {
|
function Scope(ctx, opts) {
|
||||||
if (ctx === void 0) { ctx = {}; }
|
if (ctx === void 0) { ctx = {}; }
|
||||||
this.blocks = {};
|
this.blocks = {};
|
||||||
|
this.groups = {};
|
||||||
this.blockMode = BlockMode$1.OUTPUT;
|
this.blockMode = BlockMode$1.OUTPUT;
|
||||||
this.opts = applyDefault(opts);
|
this.opts = applyDefault(opts);
|
||||||
this.contexts = [ctx || {}];
|
this.contexts = [ctx || {}];
|
||||||
}
|
}
|
||||||
Scope.prototype.getAll = function () {
|
Scope.prototype.getAll = function () {
|
||||||
return this.contexts.reduce(function (ctx, val) { return assign(ctx, val); }, create(null));
|
return this.contexts.reduce(function (ctx, val) { return __assign(ctx, val); }, {});
|
||||||
};
|
};
|
||||||
Scope.prototype.get = function (path) {
|
Scope.prototype.get = function (path) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
@@ -478,6 +442,7 @@
|
|||||||
scope[key] = {};
|
scope[key] = {};
|
||||||
}
|
}
|
||||||
scope = scope[key];
|
scope = scope[key];
|
||||||
|
return false;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
Scope.prototype.unshift = function (ctx) {
|
Scope.prototype.unshift = function (ctx) {
|
||||||
@@ -749,10 +714,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
var Token = /** @class */ (function () {
|
var Token = /** @class */ (function () {
|
||||||
function Token(raw, col, input, file, line) {
|
function Token(raw, input, line, col, file) {
|
||||||
|
this.type = 'notset';
|
||||||
this.col = col;
|
this.col = col;
|
||||||
this.line = line;
|
this.line = line;
|
||||||
this.raw = raw;
|
this.raw = raw;
|
||||||
|
this.value = raw;
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
@@ -761,8 +728,8 @@
|
|||||||
|
|
||||||
var HTMLToken = /** @class */ (function (_super) {
|
var HTMLToken = /** @class */ (function (_super) {
|
||||||
__extends(HTMLToken, _super);
|
__extends(HTMLToken, _super);
|
||||||
function HTMLToken(str, begin, input, file, line) {
|
function HTMLToken(str, input, line, col, file) {
|
||||||
var _this = _super.call(this, str, begin, input, file, line) || this;
|
var _this = _super.call(this, str, input, line, col, file) || this;
|
||||||
_this.type = 'html';
|
_this.type = 'html';
|
||||||
_this.value = str;
|
_this.value = str;
|
||||||
return _this;
|
return _this;
|
||||||
@@ -772,10 +739,10 @@
|
|||||||
|
|
||||||
var DelimitedToken = /** @class */ (function (_super) {
|
var DelimitedToken = /** @class */ (function (_super) {
|
||||||
__extends(DelimitedToken, _super);
|
__extends(DelimitedToken, _super);
|
||||||
function DelimitedToken(raw, value, pos, input, file, line) {
|
function DelimitedToken(raw, value, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, input, line, pos, file) || this;
|
||||||
_this.trimLeft = value[0] === '-';
|
_this.trimLeft = value[0] === '-';
|
||||||
_this.trimRight = value[value.length - 1] === '-';
|
_this.trimRight = last(value) === '-';
|
||||||
_this.value = value
|
_this.value = value
|
||||||
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
|
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
|
||||||
.trim();
|
.trim();
|
||||||
@@ -786,8 +753,8 @@
|
|||||||
|
|
||||||
var TagToken = /** @class */ (function (_super) {
|
var TagToken = /** @class */ (function (_super) {
|
||||||
__extends(TagToken, _super);
|
__extends(TagToken, _super);
|
||||||
function TagToken(raw, value$$1, pos, input, file, line) {
|
function TagToken(raw, value$$1, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, value$$1, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, value$$1, input, line, pos, file) || this;
|
||||||
_this.type = 'tag';
|
_this.type = 'tag';
|
||||||
var match = _this.value.match(tagLine);
|
var match = _this.value.match(tagLine);
|
||||||
if (!match) {
|
if (!match) {
|
||||||
@@ -802,8 +769,8 @@
|
|||||||
|
|
||||||
var OutputToken = /** @class */ (function (_super) {
|
var OutputToken = /** @class */ (function (_super) {
|
||||||
__extends(OutputToken, _super);
|
__extends(OutputToken, _super);
|
||||||
function OutputToken(raw, value, pos, input, file, line) {
|
function OutputToken(raw, value, input, line, pos, file) {
|
||||||
var _this = _super.call(this, raw, value, pos, input, file, line) || this;
|
var _this = _super.call(this, raw, value, input, line, pos, file) || this;
|
||||||
_this.type = 'output';
|
_this.type = 'output';
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
@@ -841,7 +808,7 @@
|
|||||||
if (state === ParseState.HTML) {
|
if (state === ParseState.HTML) {
|
||||||
if (input.substr(p, outputL.length) === outputL) {
|
if (input.substr(p, outputL.length) === outputL) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
buffer = outputL;
|
buffer = outputL;
|
||||||
line = curLine;
|
line = curLine;
|
||||||
col = p - lineBegin + 1;
|
col = p - lineBegin + 1;
|
||||||
@@ -851,7 +818,7 @@
|
|||||||
}
|
}
|
||||||
else if (input.substr(p, tagL.length) === tagL) {
|
else if (input.substr(p, tagL.length) === tagL) {
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
buffer = tagL;
|
buffer = tagL;
|
||||||
line = curLine;
|
line = curLine;
|
||||||
col = p - lineBegin + 1;
|
col = p - lineBegin + 1;
|
||||||
@@ -862,7 +829,7 @@
|
|||||||
}
|
}
|
||||||
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
|
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
|
||||||
buffer += outputR;
|
buffer += outputR;
|
||||||
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), col, input, file, line));
|
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), input, line, col, file));
|
||||||
p += outputR.length;
|
p += outputR.length;
|
||||||
buffer = '';
|
buffer = '';
|
||||||
line = curLine;
|
line = curLine;
|
||||||
@@ -872,7 +839,7 @@
|
|||||||
}
|
}
|
||||||
else if (input.substr(p, tagR.length) === tagR) {
|
else if (input.substr(p, tagR.length) === tagR) {
|
||||||
buffer += tagR;
|
buffer += tagR;
|
||||||
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), col, input, file, line));
|
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), input, line, col, file));
|
||||||
p += tagR.length;
|
p += tagR.length;
|
||||||
buffer = '';
|
buffer = '';
|
||||||
line = curLine;
|
line = curLine;
|
||||||
@@ -885,10 +852,10 @@
|
|||||||
if (state !== ParseState.HTML) {
|
if (state !== ParseState.HTML) {
|
||||||
var t = state === ParseState.OUTPUT ? 'output' : 'tag';
|
var t = state === ParseState.OUTPUT ? 'output' : 'tag';
|
||||||
var str = buffer.length > 16 ? buffer.slice(0, 13) + '...' : buffer;
|
var str = buffer.length > 16 ? buffer.slice(0, 13) + '...' : buffer;
|
||||||
throw new TokenizationError(new Error(t + " \"" + str + "\" not closed"), new Token(buffer, col, input, file, line));
|
throw new TokenizationError(t + " \"" + str + "\" not closed", new Token(buffer, input, line, col, file));
|
||||||
}
|
}
|
||||||
if (buffer)
|
if (buffer)
|
||||||
tokens.push(new HTMLToken(buffer, col, input, file, line));
|
tokens.push(new HTMLToken(buffer, input, line, col, file));
|
||||||
whiteSpaceCtrl(tokens, this.options);
|
whiteSpaceCtrl(tokens, this.options);
|
||||||
return tokens;
|
return tokens;
|
||||||
};
|
};
|
||||||
@@ -921,11 +888,11 @@
|
|||||||
return [3 /*break*/, 5];
|
return [3 /*break*/, 5];
|
||||||
case 4:
|
case 4:
|
||||||
e_1 = _b.sent();
|
e_1 = _b.sent();
|
||||||
if (e_1 instanceof RenderBreakError) {
|
if (e_1.name === 'RenderBreakError') {
|
||||||
e_1.resolvedHTML = html;
|
e_1.resolvedHTML = html;
|
||||||
throw e_1;
|
throw e_1;
|
||||||
}
|
}
|
||||||
throw e_1 instanceof RenderError ? e_1 : new RenderError(e_1, tpl);
|
throw e_1.name === 'RenderError' ? e_1 : new RenderError(e_1, tpl);
|
||||||
case 5:
|
case 5:
|
||||||
_i++;
|
_i++;
|
||||||
return [3 /*break*/, 1];
|
return [3 /*break*/, 1];
|
||||||
@@ -971,11 +938,7 @@
|
|||||||
if ((match = exp.match(rangeLine))) {
|
if ((match = exp.match(rangeLine))) {
|
||||||
var low = evalValue(match[1], scope);
|
var low = evalValue(match[1], scope);
|
||||||
var high = evalValue(match[2], scope);
|
var high = evalValue(match[2], scope);
|
||||||
var range = [];
|
return range(low, high + 1);
|
||||||
for (var j = low; j <= high; j++) {
|
|
||||||
range.push(j);
|
|
||||||
}
|
|
||||||
return range;
|
|
||||||
}
|
}
|
||||||
return evalValue(exp, scope);
|
return evalValue(exp, scope);
|
||||||
}
|
}
|
||||||
@@ -1096,8 +1059,7 @@
|
|||||||
};
|
};
|
||||||
Filter.prototype.render = function (value$$1, scope) {
|
Filter.prototype.render = function (value$$1, scope) {
|
||||||
var args = this.args.map(function (arg) { return evalValue(arg, scope); });
|
var args = this.args.map(function (arg) { return evalValue(arg, scope); });
|
||||||
args.unshift(value$$1);
|
return this.impl.apply(null, [value$$1].concat(args));
|
||||||
return this.impl.apply(null, args);
|
|
||||||
};
|
};
|
||||||
Filter.register = function (name, filter$$1) {
|
Filter.register = function (name, filter$$1) {
|
||||||
Filter.impls[name] = filter$$1;
|
Filter.impls[name] = filter$$1;
|
||||||
@@ -1112,6 +1074,7 @@
|
|||||||
var ParseStream = /** @class */ (function () {
|
var ParseStream = /** @class */ (function () {
|
||||||
function ParseStream(tokens, parseToken) {
|
function ParseStream(tokens, parseToken) {
|
||||||
this.handlers = {};
|
this.handlers = {};
|
||||||
|
this.stopRequested = false;
|
||||||
this.tokens = tokens;
|
this.tokens = tokens;
|
||||||
this.parseToken = parseToken;
|
this.parseToken = parseToken;
|
||||||
}
|
}
|
||||||
@@ -1125,6 +1088,7 @@
|
|||||||
h(arg);
|
h(arg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
ParseStream.prototype.start = function () {
|
ParseStream.prototype.start = function () {
|
||||||
this.trigger('start');
|
this.trigger('start');
|
||||||
@@ -1132,8 +1096,7 @@
|
|||||||
while (!this.stopRequested && (token = this.tokens.shift())) {
|
while (!this.stopRequested && (token = this.tokens.shift())) {
|
||||||
if (this.trigger('token', token))
|
if (this.trigger('token', token))
|
||||||
continue;
|
continue;
|
||||||
if (token.type === 'tag' &&
|
if (token.type === 'tag' && this.trigger("tag:" + token.name, token)) {
|
||||||
this.trigger("tag:" + token.name, token)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var template = this.parseToken(token, this.tokens);
|
var template = this.parseToken(token, this.tokens);
|
||||||
@@ -1152,16 +1115,14 @@
|
|||||||
|
|
||||||
var default_1 = /** @class */ (function () {
|
var default_1 = /** @class */ (function () {
|
||||||
function default_1(str, strictFilters) {
|
function default_1(str, strictFilters) {
|
||||||
|
this.filters = [];
|
||||||
var match = matchValue(str);
|
var match = matchValue(str);
|
||||||
assert(match, "illegal value string: " + str);
|
assert(match, "illegal value string: " + str);
|
||||||
var initial = match[0];
|
this.initial = match[0];
|
||||||
str = str.substr(match.index + match[0].length);
|
str = str.substr(match.index + match[0].length);
|
||||||
var filters = [];
|
|
||||||
while ((match = filter.exec(str))) {
|
while ((match = filter.exec(str))) {
|
||||||
filters.push([match[0].trim()]);
|
this.filters.push(new Filter(match[0].trim(), strictFilters));
|
||||||
}
|
}
|
||||||
this.initial = initial;
|
|
||||||
this.filters = filters.map(function (str) { return new Filter(str, strictFilters); });
|
|
||||||
}
|
}
|
||||||
default_1.prototype.value = function (scope) {
|
default_1.prototype.value = function (scope) {
|
||||||
return this.filters.reduce(function (prev, filter$$1) { return filter$$1.render(prev, scope); }, evalExp(this.initial, scope));
|
return this.filters.reduce(function (prev, filter$$1) { return filter$$1.render(prev, scope); }, evalExp(this.initial, scope));
|
||||||
@@ -1243,7 +1204,7 @@
|
|||||||
}());
|
}());
|
||||||
|
|
||||||
var re = new RegExp("(" + identifier.source + ")\\s*=([^]*)");
|
var re = new RegExp("(" + identifier.source + ")\\s*=([^]*)");
|
||||||
var assign$1 = {
|
var assign = {
|
||||||
parse: function (token) {
|
parse: function (token) {
|
||||||
var match = token.args.match(re);
|
var match = token.args.match(re);
|
||||||
assert(match, "illegal token " + token.raw);
|
assert(match, "illegal token " + token.raw);
|
||||||
@@ -1258,12 +1219,6 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
|
||||||
* Call functions in serial until someone resolved.
|
|
||||||
* @param iterable the array to iterate with.
|
|
||||||
* @param iteratee returns a new promise.
|
|
||||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* Call functions in serial until someone rejected.
|
* Call functions in serial until someone rejected.
|
||||||
* @param {Array} iterable the array to iterate with.
|
* @param {Array} iterable the array to iterate with.
|
||||||
@@ -1271,7 +1226,7 @@
|
|||||||
* The iteratee is invoked with three arguments: (value, index, iterable).
|
* The iteratee is invoked with three arguments: (value, index, iterable).
|
||||||
*/
|
*/
|
||||||
function mapSeries(iterable, iteratee) {
|
function mapSeries(iterable, iteratee) {
|
||||||
var ret = Promise.resolve('init');
|
var ret = Promise.resolve(0);
|
||||||
var result = [];
|
var result = [];
|
||||||
iterable.forEach(function (item, idx) {
|
iterable.forEach(function (item, idx) {
|
||||||
ret = ret
|
ret = ret
|
||||||
@@ -1286,107 +1241,109 @@
|
|||||||
("(?:\\s+" + hash.source + ")*") +
|
("(?:\\s+" + hash.source + ")*") +
|
||||||
"(?:\\s+(reversed))?" +
|
"(?:\\s+(reversed))?" +
|
||||||
("(?:\\s+" + hash.source + ")*$"));
|
("(?:\\s+" + hash.source + ")*$"));
|
||||||
function parse(tagToken, remainTokens) {
|
var For = {
|
||||||
var _this = this;
|
type: 'block',
|
||||||
var match = re$1.exec(tagToken.args);
|
parse: function (tagToken, remainTokens) {
|
||||||
assert(match, "illegal tag: " + tagToken.raw);
|
|
||||||
this.variable = match[1];
|
|
||||||
this.collection = match[2];
|
|
||||||
this.reversed = !!match[3];
|
|
||||||
this.templates = [];
|
|
||||||
this.elseTemplates = [];
|
|
||||||
var p;
|
|
||||||
var stream = this.liquid.parser.parseStream(remainTokens)
|
|
||||||
.on('start', function () { return (p = _this.templates); })
|
|
||||||
.on('tag:else', function () { return (p = _this.elseTemplates); })
|
|
||||||
.on('tag:endfor', function () { return stream.stop(); })
|
|
||||||
.on('template', function (tpl) { return p.push(tpl); })
|
|
||||||
.on('end', function () {
|
|
||||||
throw new Error("tag " + tagToken.raw + " not closed");
|
|
||||||
});
|
|
||||||
stream.start();
|
|
||||||
}
|
|
||||||
function render(scope, hash$$1) {
|
|
||||||
return __awaiter(this, void 0, void 0, function () {
|
|
||||||
var collection, offset, limit, contexts, html, finished;
|
|
||||||
var _this = this;
|
var _this = this;
|
||||||
return __generator(this, function (_a) {
|
var match = re$1.exec(tagToken.args);
|
||||||
switch (_a.label) {
|
assert(match, "illegal tag: " + tagToken.raw);
|
||||||
case 0:
|
this.variable = match[1];
|
||||||
collection = evalExp(this.collection, scope);
|
this.collection = match[2];
|
||||||
if (!isArray(collection)) {
|
this.reversed = !!match[3];
|
||||||
if (isString(collection) && collection.length > 0) {
|
this.templates = [];
|
||||||
collection = [collection];
|
this.elseTemplates = [];
|
||||||
}
|
var p;
|
||||||
else if (isObject(collection)) {
|
var stream = this.liquid.parser.parseStream(remainTokens)
|
||||||
collection = Object.keys(collection).map(function (key) { return [key, collection[key]]; });
|
.on('start', function () { return (p = _this.templates); })
|
||||||
}
|
.on('tag:else', function () { return (p = _this.elseTemplates); })
|
||||||
}
|
.on('tag:endfor', function () { return stream.stop(); })
|
||||||
if (!isArray(collection) || !collection.length) {
|
.on('template', function (tpl) { return p.push(tpl); })
|
||||||
return [2 /*return*/, this.liquid.renderer.renderTemplates(this.elseTemplates, scope)];
|
.on('end', function () {
|
||||||
}
|
throw new Error("tag " + tagToken.raw + " not closed");
|
||||||
offset = hash$$1.offset || 0;
|
|
||||||
limit = (hash$$1.limit === undefined) ? collection.length : hash$$1.limit;
|
|
||||||
collection = collection.slice(offset, offset + limit);
|
|
||||||
if (this.reversed)
|
|
||||||
collection.reverse();
|
|
||||||
contexts = collection.map(function (item, i) {
|
|
||||||
var ctx = {};
|
|
||||||
ctx[_this.variable] = item;
|
|
||||||
ctx['forloop'] = {
|
|
||||||
first: i === 0,
|
|
||||||
index: i + 1,
|
|
||||||
index0: i,
|
|
||||||
last: i === collection.length - 1,
|
|
||||||
length: collection.length,
|
|
||||||
rindex: collection.length - i,
|
|
||||||
rindex0: collection.length - i - 1
|
|
||||||
};
|
|
||||||
return ctx;
|
|
||||||
});
|
|
||||||
html = '';
|
|
||||||
finished = false;
|
|
||||||
return [4 /*yield*/, mapSeries(contexts, function (context) { return __awaiter(_this, void 0, void 0, function () {
|
|
||||||
var _a, e_1;
|
|
||||||
return __generator(this, function (_b) {
|
|
||||||
switch (_b.label) {
|
|
||||||
case 0:
|
|
||||||
if (finished)
|
|
||||||
return [2 /*return*/];
|
|
||||||
scope.push(context);
|
|
||||||
_b.label = 1;
|
|
||||||
case 1:
|
|
||||||
_b.trys.push([1, 3, , 4]);
|
|
||||||
_a = html;
|
|
||||||
return [4 /*yield*/, this.liquid.renderer.renderTemplates(this.templates, scope)];
|
|
||||||
case 2:
|
|
||||||
html = _a + _b.sent();
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 3:
|
|
||||||
e_1 = _b.sent();
|
|
||||||
if (e_1 instanceof RenderBreakError) {
|
|
||||||
html += e_1.resolvedHTML;
|
|
||||||
if (e_1.message === 'break') {
|
|
||||||
finished = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw e_1;
|
|
||||||
return [3 /*break*/, 4];
|
|
||||||
case 4:
|
|
||||||
scope.pop(context);
|
|
||||||
return [2 /*return*/];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}); })];
|
|
||||||
case 1:
|
|
||||||
_a.sent();
|
|
||||||
return [2 /*return*/, html];
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
stream.start();
|
||||||
}
|
},
|
||||||
var For = { parse: parse, render: render };
|
render: function (scope, hash$$1) {
|
||||||
|
return __awaiter(this, void 0, void 0, function () {
|
||||||
|
var collection, offset, limit, contexts, html, finished;
|
||||||
|
var _this = this;
|
||||||
|
return __generator(this, function (_a) {
|
||||||
|
switch (_a.label) {
|
||||||
|
case 0:
|
||||||
|
collection = evalExp(this.collection, scope);
|
||||||
|
if (!isArray(collection)) {
|
||||||
|
if (isString(collection) && collection.length > 0) {
|
||||||
|
collection = [collection];
|
||||||
|
}
|
||||||
|
else if (isObject(collection)) {
|
||||||
|
collection = Object.keys(collection).map(function (key) { return [key, collection[key]]; });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!isArray(collection) || !collection.length) {
|
||||||
|
return [2 /*return*/, this.liquid.renderer.renderTemplates(this.elseTemplates, scope)];
|
||||||
|
}
|
||||||
|
offset = hash$$1.offset || 0;
|
||||||
|
limit = (hash$$1.limit === undefined) ? collection.length : hash$$1.limit;
|
||||||
|
collection = collection.slice(offset, offset + limit);
|
||||||
|
if (this.reversed)
|
||||||
|
collection.reverse();
|
||||||
|
contexts = collection.map(function (item, i) {
|
||||||
|
var ctx = {};
|
||||||
|
ctx[_this.variable] = item;
|
||||||
|
ctx['forloop'] = {
|
||||||
|
first: i === 0,
|
||||||
|
index: i + 1,
|
||||||
|
index0: i,
|
||||||
|
last: i === collection.length - 1,
|
||||||
|
length: collection.length,
|
||||||
|
rindex: collection.length - i,
|
||||||
|
rindex0: collection.length - i - 1
|
||||||
|
};
|
||||||
|
return ctx;
|
||||||
|
});
|
||||||
|
html = '';
|
||||||
|
finished = false;
|
||||||
|
return [4 /*yield*/, mapSeries(contexts, function (context) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
|
var _a, e_1;
|
||||||
|
return __generator(this, function (_b) {
|
||||||
|
switch (_b.label) {
|
||||||
|
case 0:
|
||||||
|
if (finished)
|
||||||
|
return [2 /*return*/];
|
||||||
|
scope.push(context);
|
||||||
|
_b.label = 1;
|
||||||
|
case 1:
|
||||||
|
_b.trys.push([1, 3, , 4]);
|
||||||
|
_a = html;
|
||||||
|
return [4 /*yield*/, this.liquid.renderer.renderTemplates(this.templates, scope)];
|
||||||
|
case 2:
|
||||||
|
html = _a + _b.sent();
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 3:
|
||||||
|
e_1 = _b.sent();
|
||||||
|
if (e_1.name === 'RenderBreakError') {
|
||||||
|
html += e_1.resolvedHTML;
|
||||||
|
if (e_1.message === 'break') {
|
||||||
|
finished = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
throw e_1;
|
||||||
|
return [3 /*break*/, 4];
|
||||||
|
case 4:
|
||||||
|
scope.pop(context);
|
||||||
|
return [2 /*return*/];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); })];
|
||||||
|
case 1:
|
||||||
|
_a.sent();
|
||||||
|
return [2 /*return*/, html];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var re$2 = new RegExp("(" + identifier.source + ")");
|
var re$2 = new RegExp("(" + identifier.source + ")");
|
||||||
var capture = {
|
var capture = {
|
||||||
@@ -1573,7 +1530,7 @@
|
|||||||
render: function (scope) {
|
render: function (scope) {
|
||||||
var group = evalValue(this.group, scope);
|
var group = evalValue(this.group, scope);
|
||||||
var fingerprint = "cycle:" + group + ":" + this.candidates.join(',');
|
var fingerprint = "cycle:" + group + ":" + this.candidates.join(',');
|
||||||
var groups = scope.opts.groups = scope.opts.groups || {};
|
var groups = scope.groups;
|
||||||
var idx = groups[fingerprint];
|
var idx = groups[fingerprint];
|
||||||
if (idx === undefined) {
|
if (idx === undefined) {
|
||||||
idx = groups[fingerprint] = 0;
|
idx = groups[fingerprint] = 0;
|
||||||
@@ -1793,6 +1750,7 @@
|
|||||||
ctx[_this.variable] = item;
|
ctx[_this.variable] = item;
|
||||||
return ctx;
|
return ctx;
|
||||||
});
|
});
|
||||||
|
row = 0;
|
||||||
html = '';
|
html = '';
|
||||||
return [4 /*yield*/, mapSeries(contexts, function (context, idx) { return __awaiter(_this, void 0, void 0, function () {
|
return [4 /*yield*/, mapSeries(contexts, function (context, idx) { return __awaiter(_this, void 0, void 0, function () {
|
||||||
var col, _a;
|
var col, _a;
|
||||||
@@ -1879,7 +1837,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var tags = {
|
var tags = {
|
||||||
assign: assign$1, 'for': For, capture: capture, 'case': Case, comment: comment, include: include, decrement: decrement, increment: increment, cycle: cycle, 'if': If, layout: layout, block: block, raw: raw, tablerow: tablerow, unless: unless, 'break': Break, 'continue': Continue
|
assign: assign, 'for': For, capture: capture, 'case': Case, comment: comment, include: include, decrement: decrement, increment: increment, cycle: cycle, 'if': If, layout: layout, block: block, raw: raw, tablerow: tablerow, unless: unless, 'break': Break, 'continue': Continue
|
||||||
};
|
};
|
||||||
|
|
||||||
var escapeMap = {
|
var escapeMap = {
|
||||||
@@ -1906,14 +1864,13 @@
|
|||||||
'escape': escape,
|
'escape': escape,
|
||||||
'escape_once': function (str) { return escape(unescape(str)); },
|
'escape_once': function (str) { return escape(unescape(str)); },
|
||||||
'newline_to_br': function (v) { return v.replace(/\n/g, '<br />'); },
|
'newline_to_br': function (v) { return v.replace(/\n/g, '<br />'); },
|
||||||
'strip_html': function (v) { return String(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''); }
|
'strip_html': function (v) { return v.replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''); }
|
||||||
};
|
};
|
||||||
|
|
||||||
var str = {
|
var str = {
|
||||||
'append': function (v, arg) { return v + arg; },
|
'append': function (v, arg) { return v + arg; },
|
||||||
'prepend': function (v, arg) { return arg + v; },
|
'prepend': function (v, arg) { return arg + v; },
|
||||||
'capitalize': function (str) { return String(str).charAt(0).toUpperCase() + str.slice(1); },
|
'capitalize': function (str) { return String(str).charAt(0).toUpperCase() + str.slice(1); },
|
||||||
'concat': function (v, arg) { return Array.prototype.concat.call(v, arg); },
|
|
||||||
'lstrip': function (v) { return String(v).replace(/^\s+/, ''); },
|
'lstrip': function (v) { return String(v).replace(/^\s+/, ''); },
|
||||||
'downcase': function (v) { return v.toLowerCase(); },
|
'downcase': function (v) { return v.toLowerCase(); },
|
||||||
'upcase': function (str) { return String(str).toUpperCase(); },
|
'upcase': function (str) { return String(str).toUpperCase(); },
|
||||||
@@ -1928,19 +1885,19 @@
|
|||||||
'strip': function (v) { return String(v).trim(); },
|
'strip': function (v) { return String(v).trim(); },
|
||||||
'strip_newlines': function (v) { return String(v).replace(/\n/g, ''); },
|
'strip_newlines': function (v) { return String(v).replace(/\n/g, ''); },
|
||||||
'truncate': function (v, l, o) {
|
'truncate': function (v, l, o) {
|
||||||
|
if (l === void 0) { l = 50; }
|
||||||
|
if (o === void 0) { o = '...'; }
|
||||||
v = String(v);
|
v = String(v);
|
||||||
o = (o === undefined) ? '...' : o;
|
|
||||||
l = l || 16;
|
|
||||||
if (v.length <= l)
|
if (v.length <= l)
|
||||||
return v;
|
return v;
|
||||||
return v.substr(0, l - o.length) + o;
|
return v.substr(0, l - o.length) + o;
|
||||||
},
|
},
|
||||||
'truncatewords': function (v, l, o) {
|
'truncatewords': function (v, l, o) {
|
||||||
if (o === undefined)
|
if (l === void 0) { l = 15; }
|
||||||
o = '...';
|
if (o === void 0) { o = '...'; }
|
||||||
var arr = v.split(' ');
|
var arr = v.split(/\s+/);
|
||||||
var ret = arr.slice(0, l).join(' ');
|
var ret = arr.slice(0, l).join(' ');
|
||||||
if (arr.length > l)
|
if (arr.length >= l)
|
||||||
ret += o;
|
ret += o;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -1954,7 +1911,8 @@
|
|||||||
'minus': bindFixed(function (v, arg) { return v - arg; }),
|
'minus': bindFixed(function (v, arg) { return v - arg; }),
|
||||||
'modulo': bindFixed(function (v, arg) { return v % arg; }),
|
'modulo': bindFixed(function (v, arg) { return v % arg; }),
|
||||||
'round': function (v, arg) {
|
'round': function (v, arg) {
|
||||||
var amp = Math.pow(10, arg || 0);
|
if (arg === void 0) { arg = 0; }
|
||||||
|
var amp = Math.pow(10, arg);
|
||||||
return Math.round(v * amp) / amp;
|
return Math.round(v * amp) / amp;
|
||||||
},
|
},
|
||||||
'plus': bindFixed(function (v, arg) { return Number(v) + Number(arg); }),
|
'plus': bindFixed(function (v, arg) { return Number(v) + Number(arg); }),
|
||||||
@@ -1984,6 +1942,7 @@
|
|||||||
'reverse': function (v) { return v.reverse(); },
|
'reverse': function (v) { return v.reverse(); },
|
||||||
'sort': function (v, arg) { return v.sort(arg); },
|
'sort': function (v, arg) { return v.sort(arg); },
|
||||||
'size': function (v) { return v.length; },
|
'size': function (v) { return v.length; },
|
||||||
|
'concat': function (v, arg) { return Array.prototype.concat.call(v, arg); },
|
||||||
'slice': function (v, begin, length) {
|
'slice': function (v, begin, length) {
|
||||||
if (length === undefined)
|
if (length === undefined)
|
||||||
length = 1;
|
length = 1;
|
||||||
@@ -1992,10 +1951,9 @@
|
|||||||
'uniq': function (arr) {
|
'uniq': function (arr) {
|
||||||
var u = {};
|
var u = {};
|
||||||
return (arr || []).filter(function (val) {
|
return (arr || []).filter(function (val) {
|
||||||
if (u.hasOwnProperty(val)) {
|
if (u.hasOwnProperty(String(val)))
|
||||||
return false;
|
return false;
|
||||||
}
|
u[String(val)] = true;
|
||||||
u[val] = true;
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2167,7 +2125,7 @@
|
|||||||
// Add the format code
|
// Add the format code
|
||||||
var ch = results[0].charAt(1);
|
var ch = results[0].charAt(1);
|
||||||
var func = formatCodes[ch];
|
var func = formatCodes[ch];
|
||||||
output += func ? func.call(this, d) : '%' + ch;
|
output += func ? func(d) : '%' + ch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2197,10 +2155,8 @@
|
|||||||
function Liquid(opts) {
|
function Liquid(opts) {
|
||||||
if (opts === void 0) { opts = {}; }
|
if (opts === void 0) { opts = {}; }
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
this.cache = {};
|
||||||
this.options = applyDefault(normalize(opts));
|
this.options = applyDefault(normalize(opts));
|
||||||
if (this.options.cache) {
|
|
||||||
this.cache = {};
|
|
||||||
}
|
|
||||||
this.parser = new Parser(this);
|
this.parser = new Parser(this);
|
||||||
this.renderer = new Render();
|
this.renderer = new Render();
|
||||||
this.tokenizer = new Tokenizer(this.options);
|
this.tokenizer = new Tokenizer(this.options);
|
||||||
|
|||||||
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
Vendored
+1
-1
@@ -2,5 +2,5 @@ import Token from './token';
|
|||||||
export default class DelimitedToken extends Token {
|
export default class DelimitedToken extends Token {
|
||||||
trimLeft: boolean;
|
trimLeft: boolean;
|
||||||
trimRight: boolean;
|
trimRight: boolean;
|
||||||
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
|
constructor(raw: string, value: string, input: string, line: number, pos: number, file?: string);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import Token from './token';
|
import Token from './token';
|
||||||
export default class HTMLToken extends Token {
|
export default class HTMLToken extends Token {
|
||||||
constructor(str: any, begin: any, input: any, file: any, line: any);
|
constructor(str: string, input: string, line: number, col: number, file?: string);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+6
-6
@@ -27,9 +27,9 @@ export declare const filter: RegExp;
|
|||||||
export declare const filterCapture: RegExp;
|
export declare const filterCapture: RegExp;
|
||||||
export declare const filterLine: RegExp;
|
export declare const filterLine: RegExp;
|
||||||
export declare const operators: RegExp[];
|
export declare const operators: RegExp[];
|
||||||
export declare function isInteger(str: any): boolean;
|
export declare function isInteger(str: string): boolean;
|
||||||
export declare function isLiteral(str: any): boolean;
|
export declare function isLiteral(str: string): boolean;
|
||||||
export declare function isRange(str: any): boolean;
|
export declare function isRange(str: string): boolean;
|
||||||
export declare function isVariable(str: any): boolean;
|
export declare function isVariable(str: string): boolean;
|
||||||
export declare function matchValue(str: any): RegExpExecArray;
|
export declare function matchValue(str: string): RegExpExecArray | null;
|
||||||
export declare function parseLiteral(str: any): any;
|
export declare function parseLiteral(str: string): string | number | boolean;
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import DelimitedToken from './delimited-token';
|
import DelimitedToken from './delimited-token';
|
||||||
export default class OutputToken extends DelimitedToken {
|
export default class OutputToken extends DelimitedToken {
|
||||||
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
|
constructor(raw: string, value: string, input: string, line: number, pos: number, file?: string);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+4
-5
@@ -1,15 +1,14 @@
|
|||||||
import Token from 'src/parser/token';
|
import Token from 'src/parser/token';
|
||||||
import ITemplate from 'src/template/itemplate';
|
import ITemplate from 'src/template/itemplate';
|
||||||
declare type parseToken = (token: Token, remainTokens: Array<Token>) => ITemplate;
|
declare type ParseToken = ((token: Token, remainTokens: Array<Token>) => ITemplate);
|
||||||
declare type eventHandler = ((arg?: Token | ITemplate) => void);
|
|
||||||
export default class ParseStream {
|
export default class ParseStream {
|
||||||
private tokens;
|
private tokens;
|
||||||
private handlers;
|
private handlers;
|
||||||
private stopRequested;
|
private stopRequested;
|
||||||
private parseToken;
|
private parseToken;
|
||||||
constructor(tokens: Array<Token>, parseToken: parseToken);
|
constructor(tokens: Array<Token>, parseToken: ParseToken);
|
||||||
on(name: string, cb: eventHandler): this;
|
on<T extends ITemplate | Token | undefined>(name: string, cb: (arg: T) => void): ParseStream;
|
||||||
trigger(event: string, arg?: Token | ITemplate): boolean;
|
trigger<T extends Token | ITemplate>(event: string, arg?: T): boolean;
|
||||||
start(): this;
|
start(): this;
|
||||||
stop(): this;
|
stop(): this;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-1
@@ -4,10 +4,11 @@ import Token from './token';
|
|||||||
import Tag from 'src/template/tag/tag';
|
import Tag from 'src/template/tag/tag';
|
||||||
import Output from 'src/template/output';
|
import Output from 'src/template/output';
|
||||||
import HTML from 'src/template/html';
|
import HTML from 'src/template/html';
|
||||||
|
import ITemplate from 'src/template/itemplate';
|
||||||
export default class Parser {
|
export default class Parser {
|
||||||
liquid: Liquid;
|
liquid: Liquid;
|
||||||
constructor(liquid: Liquid);
|
constructor(liquid: Liquid);
|
||||||
parse(tokens: Array<Token>): any[];
|
parse(tokens: Array<Token>): ITemplate[];
|
||||||
parseToken(token: Token, remainTokens: Array<Token>): Tag | Output | HTML;
|
parseToken(token: Token, remainTokens: Array<Token>): Tag | Output | HTML;
|
||||||
parseStream(tokens: Array<Token>): ParseStream;
|
parseStream(tokens: Array<Token>): ParseStream;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -2,5 +2,5 @@ import DelimitedToken from './delimited-token';
|
|||||||
export default class TagToken extends DelimitedToken {
|
export default class TagToken extends DelimitedToken {
|
||||||
name: string;
|
name: string;
|
||||||
args: string;
|
args: string;
|
||||||
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
|
constructor(raw: string, value: string, input: string, line: number, pos: number, file?: string);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-2
@@ -4,7 +4,7 @@ export default class Token {
|
|||||||
col: number;
|
col: number;
|
||||||
raw: string;
|
raw: string;
|
||||||
input: string;
|
input: string;
|
||||||
file: string;
|
file?: string;
|
||||||
value: string;
|
value: string;
|
||||||
constructor(raw: any, col: any, input: any, file: any, line: any);
|
constructor(raw: string, input: string, line: number, col: number, file?: string);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-1
@@ -1,6 +1,7 @@
|
|||||||
|
import Token from './token';
|
||||||
import { NormalizedFullOptions } from '../liquid-options';
|
import { NormalizedFullOptions } from '../liquid-options';
|
||||||
export default class Tokenizer {
|
export default class Tokenizer {
|
||||||
options: NormalizedFullOptions;
|
options: NormalizedFullOptions;
|
||||||
constructor(options?: NormalizedFullOptions);
|
constructor(options?: NormalizedFullOptions);
|
||||||
tokenize(input: string, file?: string): any[];
|
tokenize(input: string, file?: string): Token[];
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-1
@@ -1,3 +1,5 @@
|
|||||||
|
import Scope from 'src/scope/scope';
|
||||||
|
import ITemplate from 'src/template/itemplate';
|
||||||
export default class Render {
|
export default class Render {
|
||||||
renderTemplates(templates: any, scope: any): Promise<string>;
|
renderTemplates(templates: ITemplate[], scope: Scope): Promise<string>;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+3
-2
@@ -1,4 +1,5 @@
|
|||||||
export declare function evalExp(exp: any, scope: any): any;
|
import Scope from 'src/scope/scope';
|
||||||
export declare function evalValue(str: any, scope: any): any;
|
export declare function evalExp(exp: string, scope: Scope): any;
|
||||||
|
export declare function evalValue(str: string, scope: Scope): any;
|
||||||
export declare function isTruthy(val: any): boolean;
|
export declare function isTruthy(val: any): boolean;
|
||||||
export declare function isFalsy(val: any): boolean;
|
export declare function isFalsy(val: any): boolean;
|
||||||
|
|||||||
Vendored
+4
@@ -0,0 +1,4 @@
|
|||||||
|
export default interface IContext {
|
||||||
|
[key: string]: any;
|
||||||
|
liquid_method_missing?: (key: string) => any;
|
||||||
|
}
|
||||||
Vendored
+10
-6
@@ -1,18 +1,22 @@
|
|||||||
import { NormalizedFullOptions } from '../liquid-options';
|
import { NormalizedFullOptions } from '../liquid-options';
|
||||||
import BlockMode from './block-mode';
|
import BlockMode from './block-mode';
|
||||||
|
import IContext from './icontext';
|
||||||
export default class Scope {
|
export default class Scope {
|
||||||
opts: NormalizedFullOptions;
|
opts: NormalizedFullOptions;
|
||||||
contexts: Array<object>;
|
contexts: Array<IContext>;
|
||||||
blocks: object;
|
blocks: object;
|
||||||
|
groups: {
|
||||||
|
[key: string]: number;
|
||||||
|
};
|
||||||
blockMode: BlockMode;
|
blockMode: BlockMode;
|
||||||
constructor(ctx?: object, opts?: NormalizedFullOptions);
|
constructor(ctx?: object, opts?: NormalizedFullOptions);
|
||||||
getAll(): object;
|
getAll(): IContext;
|
||||||
get(path: string): any;
|
get(path: string): any;
|
||||||
set(path: string, v: any): void;
|
set(path: string, v: any): void;
|
||||||
unshift(ctx: object): number;
|
unshift(ctx: object): number;
|
||||||
push(ctx: object): number;
|
push(ctx: object): number;
|
||||||
pop(ctx?: object): object;
|
pop(ctx?: object): object | undefined;
|
||||||
findContextFor(key: string, filter?: ((conttext: object) => boolean)): object;
|
findContextFor(key: string, filter?: ((conttext: object) => boolean)): IContext | null;
|
||||||
readProperty(obj: any, key: any): any;
|
private readProperty;
|
||||||
propertyAccessSeq(str: any): any[];
|
propertyAccessSeq(str: string): string[];
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
export declare type FilterImpl = (value: any, ...args: any[]) => any;
|
||||||
Vendored
+13
@@ -0,0 +1,13 @@
|
|||||||
|
import Scope from 'src/scope/scope';
|
||||||
|
import { FilterImpl } from './filter-impl';
|
||||||
|
export default class Filter {
|
||||||
|
name: string;
|
||||||
|
impl: FilterImpl;
|
||||||
|
args: string[];
|
||||||
|
private static impls;
|
||||||
|
constructor(str: string, strictFilters?: boolean);
|
||||||
|
parseArgs(argList: string): string[];
|
||||||
|
render(value: any, scope: Scope): any;
|
||||||
|
static register(name: string, filter: FilterImpl): void;
|
||||||
|
static clear(): void;
|
||||||
|
}
|
||||||
Vendored
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
import Template from 'src/template/template';
|
import Template from 'src/template/template';
|
||||||
import ITemplate from 'src/template/itemplate';
|
import ITemplate from 'src/template/itemplate';
|
||||||
import Token from 'src/parser/token';
|
import HTMLToken from 'src/parser/html-token';
|
||||||
export default class extends Template implements ITemplate {
|
export default class extends Template<HTMLToken> implements ITemplate {
|
||||||
str: string;
|
str: string;
|
||||||
constructor(token: Token);
|
constructor(token: HTMLToken);
|
||||||
render(): Promise<string>;
|
render(): Promise<string>;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-1
@@ -3,7 +3,7 @@ import Template from 'src/template/template';
|
|||||||
import ITemplate from 'src/template/itemplate';
|
import ITemplate from 'src/template/itemplate';
|
||||||
import Scope from 'src/scope/scope';
|
import Scope from 'src/scope/scope';
|
||||||
import OutputToken from 'src/parser/output-token';
|
import OutputToken from 'src/parser/output-token';
|
||||||
export default class Output extends Template implements ITemplate {
|
export default class Output extends Template<OutputToken> implements ITemplate {
|
||||||
value: Value;
|
value: Value;
|
||||||
constructor(token: OutputToken, strictFilters?: boolean);
|
constructor(token: OutputToken, strictFilters?: boolean);
|
||||||
render(scope: Scope): Promise<string>;
|
render(scope: Scope): Promise<string>;
|
||||||
|
|||||||
Vendored
+18
@@ -0,0 +1,18 @@
|
|||||||
|
import Scope from 'src/scope/scope';
|
||||||
|
import ITagImplOptions from './itag-impl-options';
|
||||||
|
import Liquid from 'src/liquid';
|
||||||
|
import Template from 'src/template/template';
|
||||||
|
import ITemplate from 'src/template/itemplate';
|
||||||
|
import TagToken from 'src/parser/tag-token';
|
||||||
|
import Token from 'src/parser/token';
|
||||||
|
export default class Tag extends Template<TagToken> implements ITemplate {
|
||||||
|
name: string;
|
||||||
|
private impl;
|
||||||
|
static impls: {
|
||||||
|
[key: string]: ITagImplOptions;
|
||||||
|
};
|
||||||
|
constructor(token: TagToken, tokens: Token[], liquid: Liquid);
|
||||||
|
render(scope: Scope): Promise<string>;
|
||||||
|
static register(name: string, tag: ITagImplOptions): void;
|
||||||
|
static clear(): void;
|
||||||
|
}
|
||||||
Vendored
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import Scope from 'src/scope/scope';
|
||||||
/**
|
/**
|
||||||
* Key-Value Pairs Representing Tag Arguments
|
* Key-Value Pairs Representing Tag Arguments
|
||||||
* Example:
|
* Example:
|
||||||
@@ -6,5 +7,5 @@
|
|||||||
*/
|
*/
|
||||||
export default class Hash {
|
export default class Hash {
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
constructor(markup: any, scope: any);
|
constructor(markup: string, scope: Scope);
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -2,4 +2,5 @@ import Liquid from 'src/liquid';
|
|||||||
import ITagImplOptions from './itag-impl-options';
|
import ITagImplOptions from './itag-impl-options';
|
||||||
export default interface ITagImpl extends ITagImplOptions {
|
export default interface ITagImpl extends ITagImplOptions {
|
||||||
liquid: Liquid;
|
liquid: Liquid;
|
||||||
|
[key: string]: any;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-2
@@ -5,9 +5,8 @@ import Template from 'src/template/template';
|
|||||||
import ITemplate from 'src/template/itemplate';
|
import ITemplate from 'src/template/itemplate';
|
||||||
import TagToken from 'src/parser/tag-token';
|
import TagToken from 'src/parser/tag-token';
|
||||||
import Token from 'src/parser/token';
|
import Token from 'src/parser/token';
|
||||||
export default class Tag extends Template implements ITemplate {
|
export default class Tag extends Template<TagToken> implements ITemplate {
|
||||||
name: string;
|
name: string;
|
||||||
token: TagToken;
|
|
||||||
private impl;
|
private impl;
|
||||||
static impls: {
|
static impls: {
|
||||||
[key: string]: ITagImplOptions;
|
[key: string]: ITagImplOptions;
|
||||||
|
|||||||
Vendored
+3
-4
@@ -1,5 +1,4 @@
|
|||||||
import Token from 'src/parser/token';
|
export default abstract class Template<T> {
|
||||||
export default class Template {
|
token: T;
|
||||||
token: Token;
|
constructor(token: T);
|
||||||
constructor(token: any);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
|
import Filter from './filter/filter';
|
||||||
import Scope from 'src/scope/scope';
|
import Scope from 'src/scope/scope';
|
||||||
export default class {
|
export default class {
|
||||||
initial: any;
|
initial: any;
|
||||||
filters: Array<any>;
|
filters: Array<Filter>;
|
||||||
constructor(str: string, strictFilters?: boolean);
|
constructor(str: string, strictFilters?: boolean);
|
||||||
value(scope: Scope): any;
|
value(scope: Scope): any;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+12
-17
@@ -1,30 +1,25 @@
|
|||||||
declare abstract class LiquidError {
|
import Token from 'src/parser/token';
|
||||||
name: string;
|
import ITemplate from 'src/template/itemplate';
|
||||||
message: string;
|
declare abstract class LiquidError extends Error {
|
||||||
stack: string;
|
|
||||||
private file;
|
|
||||||
private input;
|
|
||||||
private token;
|
private token;
|
||||||
private originalError;
|
private originalError;
|
||||||
constructor(err: any, token: any);
|
constructor(err: Error, token: Token);
|
||||||
captureStackTrace(obj: any): void;
|
protected update(): void;
|
||||||
}
|
}
|
||||||
export declare class TokenizationError extends LiquidError {
|
export declare class TokenizationError extends LiquidError {
|
||||||
constructor(message: any, token: any);
|
constructor(message: string, token: Token);
|
||||||
}
|
}
|
||||||
export declare class ParseError extends LiquidError {
|
export declare class ParseError extends LiquidError {
|
||||||
constructor(err: any, token: any);
|
constructor(err: Error, token: Token);
|
||||||
}
|
}
|
||||||
export declare class RenderError extends LiquidError {
|
export declare class RenderError extends LiquidError {
|
||||||
constructor(err: any, tpl: any);
|
constructor(err: Error, tpl: ITemplate);
|
||||||
}
|
}
|
||||||
export declare class RenderBreakError {
|
export declare class RenderBreakError extends Error {
|
||||||
message: string;
|
|
||||||
resolvedHTML: string;
|
resolvedHTML: string;
|
||||||
constructor(message: any);
|
constructor(message: string);
|
||||||
}
|
}
|
||||||
export declare class AssertionError {
|
export declare class AssertionError extends Error {
|
||||||
message: string;
|
constructor(message: string);
|
||||||
constructor(message: any);
|
|
||||||
}
|
}
|
||||||
export {};
|
export {};
|
||||||
|
|||||||
Vendored
+1
-2
@@ -1,2 +1 @@
|
|||||||
export declare function anySeries(iterable: any, iteratee: any): Promise<any>;
|
export declare function mapSeries<T1, T2>(iterable: T1[], iteratee: (item: T1, idx: number, iterable: T1[]) => Promise<T2> | T2): Promise<T2[]>;
|
||||||
export declare function mapSeries(iterable: any, iteratee: any): Promise<any[]>;
|
|
||||||
|
|||||||
Vendored
+1
-1
@@ -1 +1 @@
|
|||||||
export default function (d: any, format: any): string;
|
export default function (d: Date, format: string): string;
|
||||||
|
|||||||
Vendored
+12
-6
@@ -1,15 +1,21 @@
|
|||||||
export declare function isString(value: any): boolean;
|
export declare function isString(value: any): boolean;
|
||||||
export declare function isFunction(value: any): boolean;
|
export declare function isFunction(value: any): boolean;
|
||||||
export declare function promisify(fn: any): (...args: any[]) => Promise<{}>;
|
export declare function promisify<T1, T2>(fn: (arg1: T1, cb: (err: Error | null, result: T2) => void) => void): (arg1: T1) => Promise<T2>;
|
||||||
|
export declare function promisify<T1, T2, T3>(fn: (arg1: T1, arg2: T2, cb: (err: Error | null, result: T3) => void) => void): (arg1: T1, arg2: T2) => Promise<T3>;
|
||||||
export declare function stringify(value: any): string;
|
export declare function stringify(value: any): string;
|
||||||
export declare function create<T1 extends object, T2 extends T1 = T1>(proto: T1): T2;
|
export declare function create<T1 extends object, T2 extends T1 = T1>(proto: T1): T2;
|
||||||
export declare function isNil(value: any): boolean;
|
export declare function isNil(value: any): boolean;
|
||||||
export declare function isArray(value: any): boolean;
|
export declare function isArray(value: any): boolean;
|
||||||
export declare function isError(value: any): boolean;
|
export declare function isError(value: any): boolean;
|
||||||
export declare function forOwn(object: any, iteratee: ((val: any, key: string, obj: object) => boolean | void)): any;
|
export declare function forOwn<T>(object: {
|
||||||
export declare function assign(obj: object, ...srcs: object[]): object;
|
[key: string]: T;
|
||||||
export declare function last(arr: any[]): any;
|
} | undefined, iteratee: ((val: T, key: string, obj: {
|
||||||
export declare function uniq(arr: any[]): any[];
|
[key: string]: T;
|
||||||
|
}) => boolean | void)): {
|
||||||
|
[key: string]: T;
|
||||||
|
};
|
||||||
|
export declare function last<T>(arr: T[]): T;
|
||||||
|
export declare function last(arr: string): string;
|
||||||
export declare function isObject(value: any): boolean;
|
export declare function isObject(value: any): boolean;
|
||||||
export declare function range(start: number, stop?: number, step?: number): any[];
|
export declare function range(start: number, stop?: number, step?: number): number[];
|
||||||
export declare function padStart(str: any, length: number, ch?: string): any;
|
export declare function padStart(str: any, length: number, ch?: string): any;
|
||||||
|
|||||||
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liquidjs",
|
"name": "liquidjs",
|
||||||
"version": "7.2.0",
|
"version": "7.2.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liquidjs",
|
"name": "liquidjs",
|
||||||
"version": "7.2.0",
|
"version": "7.2.1",
|
||||||
"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",
|
||||||
"types": "dist/liquid.d.ts",
|
"types": "dist/liquid.d.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user