chore(release): 7.2.0 [skip ci]

# [7.2.0](https://github.com/harttle/liquidjs/compare/v7.1.0...v7.2.0) (2019-02-20)

### Features

* override output/tag delimiter, fixes [#54](https://github.com/harttle/liquidjs/issues/54) ([d20a043](https://github.com/harttle/liquidjs/commit/d20a043))
This commit is contained in:
semantic-release-bot
2019-02-20 17:12:01 +00:00
parent d20a043fbb
commit 4171b2e023
17 changed files with 156 additions and 90 deletions
+7
View File
@@ -1,3 +1,10 @@
# [7.2.0](https://github.com/harttle/liquidjs/compare/v7.1.0...v7.2.0) (2019-02-20)
### Features
* override output/tag delimiter, fixes [#54](https://github.com/harttle/liquidjs/issues/54) ([d20a043](https://github.com/harttle/liquidjs/commit/d20a043))
# [7.1.0](https://github.com/harttle/liquidjs/compare/v7.0.2...v7.1.0) (2019-02-20)
+24 -5
View File
@@ -15,15 +15,34 @@ export interface LiquidOptions {
trim_tag_right?: boolean;
/** `trim_tag_left` is similar to `trim_tag_right`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
trim_tag_left?: boolean;
/** ``trim_value_right` is used to strip blank characters (including ` `, `\t`, and `\r`) from the right of values (`{{ }}`) until `\n` (inclusive). Defaults to `false`. */
trim_value_right?: boolean;
/** `trim_value_left` is similar to `trim_value_right`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
trim_value_left?: boolean;
/** ``trim_output_right` is used to strip blank characters (including ` `, `\t`, and `\r`) from the right of values (`{{ }}`) until `\n` (inclusive). Defaults to `false`. */
trim_output_right?: boolean;
/** `trim_output_left` is similar to `trim_output_right`, whereas the `\n` is exclusive. Defaults to `false`. See Whitespace Control for details. */
trim_output_left?: boolean;
/** `tag_delimiter_left` and `tag_delimiter_right` are used to override the delimiter for liquid tags **/
tag_delimiter_left?: string;
tag_delimiter_right?: string;
/** `output_delimiter_left` and `output_delimiter_right` are used to override the delimiter for liquid outputs **/
output_delimiter_left?: string;
output_delimiter_right?: string;
/** `greedy` is used to specify whether `trim_left`/`trim_right` is greedy. When set to `true`, all consecutive blank characters including `\n` will be trimed regardless of line breaks. Defaults to `true`. */
greedy?: boolean;
}
export interface NormalizedOptions extends LiquidOptions {
root?: string[];
}
export declare const defaultOptions: NormalizedOptions;
export interface NormalizedFullOptions extends NormalizedOptions {
root: string[];
extname: string;
cache: boolean;
dynamicPartials: boolean;
strict_filters: boolean;
strict_variables: boolean;
trim_tag_right: boolean;
trim_tag_left: boolean;
trim_output_right: boolean;
trim_output_left: boolean;
greedy: boolean;
}
export declare function normalize(options: LiquidOptions): NormalizedOptions;
export declare function applyDefault(options: NormalizedOptions): NormalizedFullOptions;
+53 -33
View File
@@ -1,5 +1,5 @@
/*
* liquidjs@7.1.0, https://github.com/harttle/liquidjs
* liquidjs@7.2.0, https://github.com/harttle/liquidjs
* (c) 2016-2019 harttle
* Released under the MIT License.
*/
@@ -413,6 +413,7 @@ function assert (predicate, message) {
}
}
/* eslint-disable camelcase */
var defaultOptions = {
root: ['.'],
cache: false,
@@ -420,9 +421,13 @@ var defaultOptions = {
dynamicPartials: true,
trim_tag_right: false,
trim_tag_left: false,
trim_value_right: false,
trim_value_left: false,
trim_output_right: false,
trim_output_left: false,
greedy: true,
tag_delimiter_left: '{%',
tag_delimiter_right: '%}',
output_delimiter_left: '{{',
output_delimiter_right: '}}',
strict_filters: false,
strict_variables: false
};
@@ -433,6 +438,9 @@ function normalize(options) {
}
return options;
}
function applyDefault(options) {
return __assign({}, defaultOptions, options);
}
function normalizeStringArray(value) {
if (isArray(value))
return value;
@@ -453,10 +461,9 @@ var BlockMode$1 = BlockMode;
var Scope = /** @class */ (function () {
function Scope(ctx, opts) {
if (ctx === void 0) { ctx = {}; }
if (opts === void 0) { opts = defaultOptions; }
this.blocks = {};
this.blockMode = BlockMode$1.OUTPUT;
this.opts = __assign({}, defaultOptions, opts);
this.opts = applyDefault(opts);
this.contexts = [ctx || {}];
}
Scope.prototype.getAll = function () {
@@ -693,7 +700,7 @@ function shouldTrimLeft(token, inRaw, options) {
if (token.type === 'tag')
return token.trimLeft || options.trim_tag_left;
if (token.type === 'output')
return token.trimLeft || options.trim_value_left;
return token.trimLeft || options.trim_output_left;
}
function shouldTrimRight(token, inRaw, options) {
if (inRaw)
@@ -701,7 +708,7 @@ function shouldTrimRight(token, inRaw, options) {
if (token.type === 'tag')
return token.trimRight || options.trim_tag_right;
if (token.type === 'output')
return token.trimRight || options.trim_value_right;
return token.trimRight || options.trim_output_right;
}
function trimLeft(token, greedy) {
if (!token || token.type !== 'html')
@@ -740,11 +747,13 @@ var HTMLToken = /** @class */ (function (_super) {
var DelimitedToken = /** @class */ (function (_super) {
__extends(DelimitedToken, _super);
function DelimitedToken(raw, pos, input, file, line) {
function DelimitedToken(raw, value, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
_this.trimLeft = raw[2] === '-';
_this.trimRight = raw[raw.length - 3] === '-';
_this.value = raw.slice(_this.trimLeft ? 3 : 2, _this.trimRight ? -3 : -2).trim();
_this.trimLeft = value[0] === '-';
_this.trimRight = value[value.length - 1] === '-';
_this.value = value
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
.trim();
return _this;
}
return DelimitedToken;
@@ -752,8 +761,8 @@ var DelimitedToken = /** @class */ (function (_super) {
var TagToken = /** @class */ (function (_super) {
__extends(TagToken, _super);
function TagToken(raw, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
function TagToken(raw, value$$1, pos, input, file, line) {
var _this = _super.call(this, raw, value$$1, pos, input, file, line) || this;
_this.type = 'tag';
var match = _this.value.match(tagLine);
if (!match) {
@@ -768,8 +777,8 @@ var TagToken = /** @class */ (function (_super) {
var OutputToken = /** @class */ (function (_super) {
__extends(OutputToken, _super);
function OutputToken(raw, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
function OutputToken(raw, value, pos, input, file, line) {
var _this = _super.call(this, raw, value, pos, input, file, line) || this;
_this.type = 'output';
return _this;
}
@@ -784,11 +793,14 @@ var ParseState;
})(ParseState || (ParseState = {}));
var Tokenizer = /** @class */ (function () {
function Tokenizer(options) {
if (options === void 0) { options = defaultOptions; }
this.options = options;
this.options = applyDefault(options);
}
Tokenizer.prototype.tokenize = function (input, file) {
var tokens = [];
var tagL = this.options.tag_delimiter_left;
var tagR = this.options.tag_delimiter_right;
var outputL = this.options.output_delimiter_left;
var outputR = this.options.output_delimiter_right;
var p = 0;
var curLine = 1;
var state = ParseState.HTML;
@@ -801,33 +813,42 @@ var Tokenizer = /** @class */ (function () {
curLine++;
lineBegin = p + 1;
}
var bin = input.substr(p, 2);
if (state === ParseState.HTML) {
if (bin === '{{' || bin === '{%') {
if (input.substr(p, outputL.length) === outputL) {
if (buffer)
tokens.push(new HTMLToken(buffer, col, input, file, line));
buffer = bin;
buffer = outputL;
line = curLine;
col = p - lineBegin + 1;
p += 2;
state = bin === '{{' ? ParseState.OUTPUT : ParseState.TAG;
p += outputL.length;
state = ParseState.OUTPUT;
continue;
}
else if (input.substr(p, tagL.length) === tagL) {
if (buffer)
tokens.push(new HTMLToken(buffer, col, input, file, line));
buffer = tagL;
line = curLine;
col = p - lineBegin + 1;
p += tagL.length;
state = ParseState.TAG;
continue;
}
}
else if (state === ParseState.OUTPUT && bin === '}}') {
buffer += '}}';
tokens.push(new OutputToken(buffer, col, input, file, line));
p += 2;
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
buffer += outputR;
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), col, input, file, line));
p += outputR.length;
buffer = '';
line = curLine;
col = p - lineBegin + 1;
state = ParseState.HTML;
continue;
}
else if (bin === '%}') {
buffer += '%}';
tokens.push(new TagToken(buffer, col, input, file, line));
p += 2;
else if (input.substr(p, tagR.length) === tagR) {
buffer += tagR;
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), col, input, file, line));
p += tagR.length;
buffer = '';
line = curLine;
col = p - lineBegin + 1;
@@ -2151,11 +2172,10 @@ var Liquid = /** @class */ (function () {
function Liquid(opts) {
if (opts === void 0) { opts = {}; }
var _this = this;
var options = __assign({}, defaultOptions, normalize(opts));
if (options.cache) {
this.options = applyDefault(normalize(opts));
if (this.options.cache) {
this.cache = {};
}
this.options = options;
this.parser = new Parser(this);
this.renderer = new Render();
this.tokenizer = new Tokenizer(this.options);
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -3,9 +3,9 @@ import * as Types from './types';
import ITemplate from './template/itemplate';
import ITagImplOptions from './template/tag/itag-impl-options';
import { isTruthy, isFalsy, evalExp, evalValue } from './render/syntax';
import { LiquidOptions, NormalizedOptions } from './liquid-options';
import { LiquidOptions, NormalizedFullOptions } from './liquid-options';
export default class Liquid {
options: NormalizedOptions;
options: NormalizedFullOptions;
private cache;
private parser;
private renderer;
+53 -33
View File
@@ -1,5 +1,5 @@
/*
* liquidjs@7.1.0, https://github.com/harttle/liquidjs
* liquidjs@7.2.0, https://github.com/harttle/liquidjs
* (c) 2016-2019 harttle
* Released under the MIT License.
*/
@@ -401,6 +401,7 @@
}
}
/* eslint-disable camelcase */
var defaultOptions = {
root: ['.'],
cache: false,
@@ -408,9 +409,13 @@
dynamicPartials: true,
trim_tag_right: false,
trim_tag_left: false,
trim_value_right: false,
trim_value_left: false,
trim_output_right: false,
trim_output_left: false,
greedy: true,
tag_delimiter_left: '{%',
tag_delimiter_right: '%}',
output_delimiter_left: '{{',
output_delimiter_right: '}}',
strict_filters: false,
strict_variables: false
};
@@ -421,6 +426,9 @@
}
return options;
}
function applyDefault(options) {
return __assign({}, defaultOptions, options);
}
function normalizeStringArray(value) {
if (isArray(value))
return value;
@@ -441,10 +449,9 @@
var Scope = /** @class */ (function () {
function Scope(ctx, opts) {
if (ctx === void 0) { ctx = {}; }
if (opts === void 0) { opts = defaultOptions; }
this.blocks = {};
this.blockMode = BlockMode$1.OUTPUT;
this.opts = __assign({}, defaultOptions, opts);
this.opts = applyDefault(opts);
this.contexts = [ctx || {}];
}
Scope.prototype.getAll = function () {
@@ -718,7 +725,7 @@
if (token.type === 'tag')
return token.trimLeft || options.trim_tag_left;
if (token.type === 'output')
return token.trimLeft || options.trim_value_left;
return token.trimLeft || options.trim_output_left;
}
function shouldTrimRight(token, inRaw, options) {
if (inRaw)
@@ -726,7 +733,7 @@
if (token.type === 'tag')
return token.trimRight || options.trim_tag_right;
if (token.type === 'output')
return token.trimRight || options.trim_value_right;
return token.trimRight || options.trim_output_right;
}
function trimLeft(token, greedy) {
if (!token || token.type !== 'html')
@@ -765,11 +772,13 @@
var DelimitedToken = /** @class */ (function (_super) {
__extends(DelimitedToken, _super);
function DelimitedToken(raw, pos, input, file, line) {
function DelimitedToken(raw, value, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
_this.trimLeft = raw[2] === '-';
_this.trimRight = raw[raw.length - 3] === '-';
_this.value = raw.slice(_this.trimLeft ? 3 : 2, _this.trimRight ? -3 : -2).trim();
_this.trimLeft = value[0] === '-';
_this.trimRight = value[value.length - 1] === '-';
_this.value = value
.slice(_this.trimLeft ? 1 : 0, _this.trimRight ? -1 : value.length)
.trim();
return _this;
}
return DelimitedToken;
@@ -777,8 +786,8 @@
var TagToken = /** @class */ (function (_super) {
__extends(TagToken, _super);
function TagToken(raw, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
function TagToken(raw, value$$1, pos, input, file, line) {
var _this = _super.call(this, raw, value$$1, pos, input, file, line) || this;
_this.type = 'tag';
var match = _this.value.match(tagLine);
if (!match) {
@@ -793,8 +802,8 @@
var OutputToken = /** @class */ (function (_super) {
__extends(OutputToken, _super);
function OutputToken(raw, pos, input, file, line) {
var _this = _super.call(this, raw, pos, input, file, line) || this;
function OutputToken(raw, value, pos, input, file, line) {
var _this = _super.call(this, raw, value, pos, input, file, line) || this;
_this.type = 'output';
return _this;
}
@@ -809,11 +818,14 @@
})(ParseState || (ParseState = {}));
var Tokenizer = /** @class */ (function () {
function Tokenizer(options) {
if (options === void 0) { options = defaultOptions; }
this.options = options;
this.options = applyDefault(options);
}
Tokenizer.prototype.tokenize = function (input, file) {
var tokens = [];
var tagL = this.options.tag_delimiter_left;
var tagR = this.options.tag_delimiter_right;
var outputL = this.options.output_delimiter_left;
var outputR = this.options.output_delimiter_right;
var p = 0;
var curLine = 1;
var state = ParseState.HTML;
@@ -826,33 +838,42 @@
curLine++;
lineBegin = p + 1;
}
var bin = input.substr(p, 2);
if (state === ParseState.HTML) {
if (bin === '{{' || bin === '{%') {
if (input.substr(p, outputL.length) === outputL) {
if (buffer)
tokens.push(new HTMLToken(buffer, col, input, file, line));
buffer = bin;
buffer = outputL;
line = curLine;
col = p - lineBegin + 1;
p += 2;
state = bin === '{{' ? ParseState.OUTPUT : ParseState.TAG;
p += outputL.length;
state = ParseState.OUTPUT;
continue;
}
else if (input.substr(p, tagL.length) === tagL) {
if (buffer)
tokens.push(new HTMLToken(buffer, col, input, file, line));
buffer = tagL;
line = curLine;
col = p - lineBegin + 1;
p += tagL.length;
state = ParseState.TAG;
continue;
}
}
else if (state === ParseState.OUTPUT && bin === '}}') {
buffer += '}}';
tokens.push(new OutputToken(buffer, col, input, file, line));
p += 2;
else if (state === ParseState.OUTPUT && input.substr(p, outputR.length) === outputR) {
buffer += outputR;
tokens.push(new OutputToken(buffer, buffer.slice(outputL.length, -outputR.length), col, input, file, line));
p += outputR.length;
buffer = '';
line = curLine;
col = p - lineBegin + 1;
state = ParseState.HTML;
continue;
}
else if (bin === '%}') {
buffer += '%}';
tokens.push(new TagToken(buffer, col, input, file, line));
p += 2;
else if (input.substr(p, tagR.length) === tagR) {
buffer += tagR;
tokens.push(new TagToken(buffer, buffer.slice(tagL.length, -tagR.length), col, input, file, line));
p += tagR.length;
buffer = '';
line = curLine;
col = p - lineBegin + 1;
@@ -2176,11 +2197,10 @@
function Liquid(opts) {
if (opts === void 0) { opts = {}; }
var _this = this;
var options = __assign({}, defaultOptions, normalize(opts));
if (options.cache) {
this.options = applyDefault(normalize(opts));
if (this.options.cache) {
this.cache = {};
}
this.options = options;
this.parser = new Parser(this);
this.renderer = new Render();
this.tokenizer = new Tokenizer(this.options);
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -2,5 +2,5 @@ import Token from './token';
export default class DelimitedToken extends Token {
trimLeft: boolean;
trimRight: boolean;
constructor(raw: any, pos: any, input: any, file: any, line: any);
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
}
+1 -1
View File
@@ -1,4 +1,4 @@
import DelimitedToken from './delimited-token';
export default class OutputToken extends DelimitedToken {
constructor(raw: any, pos: any, input: any, file: any, line: any);
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
}
+1 -1
View File
@@ -2,5 +2,5 @@ import DelimitedToken from './delimited-token';
export default class TagToken extends DelimitedToken {
name: string;
args: string;
constructor(raw: any, pos: any, input: any, file: any, line: any);
constructor(raw: any, value: any, pos: any, input: any, file: any, line: any);
}
+3 -3
View File
@@ -1,6 +1,6 @@
import { LiquidOptions } from 'src/liquid-options';
import { NormalizedFullOptions } from '../liquid-options';
export default class Tokenizer {
options: LiquidOptions;
constructor(options?: LiquidOptions);
options: NormalizedFullOptions;
constructor(options?: NormalizedFullOptions);
tokenize(input: string, file?: string): any[];
}
+2 -2
View File
@@ -1,3 +1,3 @@
import Token from 'src/parser/token';
import { LiquidOptions } from 'src/liquid-options';
export default function whiteSpaceCtrl(tokens: Token[], options: LiquidOptions): void;
import { NormalizedFullOptions } from 'src/liquid-options';
export default function whiteSpaceCtrl(tokens: Token[], options: NormalizedFullOptions): void;
+3 -3
View File
@@ -1,11 +1,11 @@
import { NormalizedOptions } from '../liquid-options';
import { NormalizedFullOptions } from '../liquid-options';
import BlockMode from './block-mode';
export default class Scope {
opts: NormalizedOptions;
opts: NormalizedFullOptions;
contexts: Array<object>;
blocks: object;
blockMode: BlockMode;
constructor(ctx?: object, opts?: NormalizedOptions);
constructor(ctx?: object, opts?: NormalizedFullOptions);
getAll(): object;
get(path: string): any;
set(path: string, v: any): void;
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liquidjs",
"version": "7.1.0",
"version": "7.2.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liquidjs",
"version": "7.1.0",
"version": "7.2.0",
"description": "Liquid template engine by pure JavaScript: compatible to shopify, easy to extend.",
"main": "dist/liquid.common.js",
"types": "dist/liquid.d.ts",