mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
5.0.2
This commit is contained in:
Vendored
+133
-129
@@ -1,4 +1,4 @@
|
|||||||
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Liquid = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Liquid = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var strftime = require('./src/util/strftime.js');
|
var strftime = require('./src/util/strftime.js');
|
||||||
@@ -69,7 +69,7 @@ var filters = {
|
|||||||
return v.join(arg);
|
return v.join(arg);
|
||||||
},
|
},
|
||||||
'last': function last(v) {
|
'last': function last(v) {
|
||||||
return v[v.length - 1];
|
return _.last(v);
|
||||||
},
|
},
|
||||||
'lstrip': function lstrip(v) {
|
'lstrip': function lstrip(v) {
|
||||||
return stringify(v).replace(/^\s+/, '');
|
return stringify(v).replace(/^\s+/, '');
|
||||||
@@ -574,7 +574,7 @@ var number = /-?\d+\.?\d*|\.?\d+/;
|
|||||||
var bool = /true|false/;
|
var bool = /true|false/;
|
||||||
|
|
||||||
// peoperty access
|
// peoperty access
|
||||||
var identifier = /[\w-]+/;
|
var identifier = /[\w-]+[?]?/;
|
||||||
var subscript = new RegExp('\\[(?:' + quoted.source + '|[\\w-\\.]+)\\]');
|
var subscript = new RegExp('\\[(?:' + quoted.source + '|[\\w-\\.]+)\\]');
|
||||||
var literal = new RegExp('(?:' + quoted.source + '|' + bool.source + '|' + number.source + ')');
|
var literal = new RegExp('(?:' + quoted.source + '|' + bool.source + '|' + number.source + ')');
|
||||||
var variable = new RegExp(identifier.source + '(?:\\.' + identifier.source + '|' + subscript.source + ')*');
|
var variable = new RegExp(identifier.source + '(?:\\.' + identifier.source + '|' + subscript.source + ')*');
|
||||||
@@ -913,69 +913,80 @@ var assert = require('./util/assert.js');
|
|||||||
|
|
||||||
var Scope = {
|
var Scope = {
|
||||||
getAll: function getAll() {
|
getAll: function getAll() {
|
||||||
var ctx = {};
|
return this.contexts.reduce(function (ctx, val) {
|
||||||
for (var i = this.scopes.length - 1; i >= 0; i--) {
|
return Object.assign(ctx, val);
|
||||||
_.assign(ctx, this.scopes[i]);
|
}, Object.create(null));
|
||||||
}
|
|
||||||
return ctx;
|
|
||||||
},
|
},
|
||||||
get: function get(str) {
|
get: function get(path) {
|
||||||
try {
|
var _this = this;
|
||||||
return this.getPropertyByPath(this.scopes, str);
|
|
||||||
} catch (e) {
|
var paths = this.propertyAccessSeq(path);
|
||||||
if (!/undefined variable/.test(e.message) || this.opts.strict_variables) {
|
var scope = this.findContextFor(paths[0]) || _.last(this.contexts);
|
||||||
throw e;
|
return paths.reduce(function (value, key) {
|
||||||
|
return _this.readProperty(value, key);
|
||||||
|
}, scope);
|
||||||
|
},
|
||||||
|
set: function set(path, v) {
|
||||||
|
var paths = this.propertyAccessSeq(path);
|
||||||
|
var scope = this.findContextFor(paths[0]) || _.last(this.contexts);
|
||||||
|
paths.some(function (key, i) {
|
||||||
|
if (!_.isObject(scope)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
if (i === paths.length - 1) {
|
||||||
},
|
scope[key] = v;
|
||||||
set: function set(k, v) {
|
return true;
|
||||||
var scope = this.findScopeFor(k);
|
}
|
||||||
setPropertyByPath(scope, k, v);
|
if (undefined === scope[key]) {
|
||||||
return this;
|
scope[key] = {};
|
||||||
},
|
}
|
||||||
push: function push(ctx) {
|
scope = scope[key];
|
||||||
assert(ctx, 'trying to push ' + ctx + ' into scopes');
|
});
|
||||||
return this.scopes.push(ctx);
|
|
||||||
},
|
|
||||||
pop: function pop() {
|
|
||||||
return this.scopes.pop();
|
|
||||||
},
|
|
||||||
findScopeFor: function findScopeFor(key) {
|
|
||||||
var i = this.scopes.length - 1;
|
|
||||||
while (i >= 0 && !(key in this.scopes[i])) {
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
if (i < 0) {
|
|
||||||
i = this.scopes.length - 1;
|
|
||||||
}
|
|
||||||
return this.scopes[i];
|
|
||||||
},
|
},
|
||||||
unshift: function unshift(ctx) {
|
unshift: function unshift(ctx) {
|
||||||
assert(ctx, 'trying to push ' + ctx + ' into scopes');
|
return this.contexts.unshift(ctx);
|
||||||
return this.scopes.unshift(ctx);
|
|
||||||
},
|
},
|
||||||
shift: function shift() {
|
push: function push(ctx) {
|
||||||
return this.scopes.shift();
|
return this.contexts.push(ctx);
|
||||||
},
|
},
|
||||||
|
pop: function pop(ctx) {
|
||||||
getPropertyByPath: function getPropertyByPath(scopes, path) {
|
if (!arguments.length) {
|
||||||
var paths = this.propertyAccessSeq(path + '');
|
return this.contexts.pop();
|
||||||
if (!paths.length) {
|
|
||||||
throw new TypeError('undefined variable: ' + path);
|
|
||||||
}
|
}
|
||||||
var key = paths.shift();
|
var i = this.contexts.findIndex(function (scope) {
|
||||||
var value = getValueFromScopes(key, scopes);
|
return scope === ctx;
|
||||||
if (_.isNil(value)) {
|
});
|
||||||
throw new TypeError('undefined variable: ' + key);
|
if (i === -1) {
|
||||||
|
throw new TypeError('scope not found, cannot pop');
|
||||||
}
|
}
|
||||||
while (paths.length) {
|
return this.contexts.splice(i, 1)[0];
|
||||||
key = paths.shift();
|
},
|
||||||
value = getValueFromParent(key, value);
|
findContextFor: function findContextFor(key, filter) {
|
||||||
if (_.isNil(value)) {
|
filter = filter || function () {
|
||||||
throw new TypeError('undefined variable: ' + key);
|
return true;
|
||||||
|
};
|
||||||
|
for (var i = this.contexts.length - 1; i >= 0; i--) {
|
||||||
|
var candidate = this.contexts[i];
|
||||||
|
if (!filter(candidate)) continue;
|
||||||
|
if (key in candidate) {
|
||||||
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return null;
|
||||||
|
},
|
||||||
|
readProperty: function readProperty(obj, key) {
|
||||||
|
var val = void 0;
|
||||||
|
if (key === 'size' && (_.isArray(obj) || _.isString(obj))) {
|
||||||
|
val = obj.length;
|
||||||
|
} else if (_.isNil(obj)) {
|
||||||
|
val = undefined;
|
||||||
|
} else {
|
||||||
|
val = obj[key];
|
||||||
|
}
|
||||||
|
if (_.isNil(val) && this.opts.strict_variables) {
|
||||||
|
throw new TypeError('undefined variable: ' + key);
|
||||||
|
}
|
||||||
|
return val;
|
||||||
},
|
},
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -987,9 +998,10 @@ var Scope = {
|
|||||||
* accessSeq("foo[bar.coo]") // ['foo', 'bar'], for bar.coo == 'bar'
|
* accessSeq("foo[bar.coo]") // ['foo', 'bar'], for bar.coo == 'bar'
|
||||||
*/
|
*/
|
||||||
propertyAccessSeq: function propertyAccessSeq(str) {
|
propertyAccessSeq: function propertyAccessSeq(str) {
|
||||||
|
str = String(str);
|
||||||
var seq = [];
|
var seq = [];
|
||||||
var name = '';
|
var name = '';
|
||||||
var j;
|
var j = void 0;
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < str.length) {
|
while (i < str.length) {
|
||||||
switch (str[i]) {
|
switch (str[i]) {
|
||||||
@@ -1029,6 +1041,10 @@ var Scope = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
push();
|
push();
|
||||||
|
|
||||||
|
if (!seq.length) {
|
||||||
|
throw new TypeError('invalid path:"' + str + '"');
|
||||||
|
}
|
||||||
return seq;
|
return seq;
|
||||||
|
|
||||||
function push() {
|
function push() {
|
||||||
@@ -1038,40 +1054,6 @@ var Scope = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
function setPropertyByPath(obj, path, val) {
|
|
||||||
var paths = (path + '').replace(/\[/g, '.').replace(/\]/g, '').split('.');
|
|
||||||
for (var i = 0; i < paths.length; i++) {
|
|
||||||
var key = paths[i];
|
|
||||||
if (!_.isObject(obj)) {
|
|
||||||
// cannot set property of non-object
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// for end point
|
|
||||||
if (i === paths.length - 1) {
|
|
||||||
return obj[key] = val;
|
|
||||||
}
|
|
||||||
// if path not exist
|
|
||||||
if (undefined === obj[key]) {
|
|
||||||
obj[key] = {};
|
|
||||||
}
|
|
||||||
obj = obj[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function getValueFromParent(key, value) {
|
|
||||||
return key === 'size' && (_.isArray(value) || _.isString(value)) ? value.length : value[key];
|
|
||||||
}
|
|
||||||
|
|
||||||
function getValueFromScopes(key, scopes) {
|
|
||||||
for (var i = scopes.length - 1; i > -1; i--) {
|
|
||||||
var scope = scopes[i];
|
|
||||||
if (scope.hasOwnProperty(key)) {
|
|
||||||
return scope[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new TypeError('undefined variable: ' + key);
|
|
||||||
}
|
|
||||||
|
|
||||||
function matchRightBracket(str, begin) {
|
function matchRightBracket(str, begin) {
|
||||||
var stack = 1; // count of '[' - count of ']'
|
var stack = 1; // count of '[' - count of ']'
|
||||||
for (var i = begin; i < str.length; i++) {
|
for (var i = begin; i < str.length; i++) {
|
||||||
@@ -1098,10 +1080,17 @@ exports.factory = function (ctx, opts) {
|
|||||||
};
|
};
|
||||||
var scope = Object.create(Scope);
|
var scope = Object.create(Scope);
|
||||||
scope.opts = _.assign(defaultOptions, opts);
|
scope.opts = _.assign(defaultOptions, opts);
|
||||||
scope.scopes = [ctx || {}];
|
scope.contexts = [ctx || {}];
|
||||||
return scope;
|
return scope;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
exports.types = {
|
||||||
|
AssignScope: Object.create(null),
|
||||||
|
CaptureScope: Object.create(null),
|
||||||
|
IncrementScope: Object.create(null),
|
||||||
|
DecrementScope: Object.create(null)
|
||||||
|
};
|
||||||
|
|
||||||
},{"./lexical.js":7,"./util/assert.js":15,"./util/underscore.js":20}],12:[function(require,module,exports){
|
},{"./lexical.js":7,"./util/assert.js":15,"./util/underscore.js":20}],12:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
@@ -1171,7 +1160,7 @@ var assert = require('./util/assert.js');
|
|||||||
|
|
||||||
function hash(markup, scope) {
|
function hash(markup, scope) {
|
||||||
var obj = {};
|
var obj = {};
|
||||||
var match;
|
var match = void 0;
|
||||||
lexical.hashCapture.lastIndex = 0;
|
lexical.hashCapture.lastIndex = 0;
|
||||||
while (match = lexical.hashCapture.exec(markup)) {
|
while (match = lexical.hashCapture.exec(markup)) {
|
||||||
var k = match[1];
|
var k = match[1];
|
||||||
@@ -1768,18 +1757,11 @@ function assign(object) {
|
|||||||
object = isObject(object) ? object : {};
|
object = isObject(object) ? object : {};
|
||||||
var srcs = Array.prototype.slice.call(arguments, 1);
|
var srcs = Array.prototype.slice.call(arguments, 1);
|
||||||
srcs.forEach(function (src) {
|
srcs.forEach(function (src) {
|
||||||
_assignBinary(object, src);
|
return Object.assign(object, src);
|
||||||
});
|
});
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
function _assignBinary(dst, src) {
|
|
||||||
forOwn(src, function (v, k) {
|
|
||||||
dst[k] = v;
|
|
||||||
});
|
|
||||||
return dst;
|
|
||||||
}
|
|
||||||
|
|
||||||
function last(arr) {
|
function last(arr) {
|
||||||
return arr[arr.length - 1];
|
return arr[arr.length - 1];
|
||||||
}
|
}
|
||||||
@@ -1852,6 +1834,7 @@ exports.uniq = uniq;
|
|||||||
var resolve = require('resolve-url');
|
var resolve = require('resolve-url');
|
||||||
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
|
var splitPathRe = /^(\/?|)([\s\S]*?)((?:\.{1,2}|[^/]+?|)(\.[^./]*|))(?:[/]*)$/;
|
||||||
var urlRe = /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/;
|
var urlRe = /^(?:\w+:)?\/\/([^\s.]+\.\S{2}|localhost[:?\d]*)\S*$/;
|
||||||
|
var _ = require('./underscore');
|
||||||
|
|
||||||
// https://github.com/jinder/path/blob/master/path.js#L567
|
// https://github.com/jinder/path/blob/master/path.js#L567
|
||||||
exports.extname = function (path) {
|
exports.extname = function (path) {
|
||||||
@@ -1867,13 +1850,13 @@ exports.resolve = function (root, path) {
|
|||||||
if (Object.prototype.toString.call(root) === '[object Array]') {
|
if (Object.prototype.toString.call(root) === '[object Array]') {
|
||||||
root = root[0];
|
root = root[0];
|
||||||
}
|
}
|
||||||
if (root && root.charAt(root.length - 1) !== '/') {
|
if (root && _.last(root) !== '/') {
|
||||||
root += '/';
|
root += '/';
|
||||||
}
|
}
|
||||||
return resolve(root, path);
|
return resolve(root, path);
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"resolve-url":5}],22:[function(require,module,exports){
|
},{"./underscore":20,"resolve-url":5}],22:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var _ = require('./util/underscore.js');
|
var _ = require('./util/underscore.js');
|
||||||
@@ -1931,6 +1914,7 @@ var Liquid = require('..');
|
|||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
var re = new RegExp('(' + lexical.identifier.source + ')\\s*=(.*)');
|
var re = new RegExp('(' + lexical.identifier.source + ')\\s*=(.*)');
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
var types = require('../src/scope').types;
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('assign', {
|
liquid.registerTag('assign', {
|
||||||
@@ -1941,19 +1925,22 @@ module.exports = function (liquid) {
|
|||||||
this.value = match[2];
|
this.value = match[2];
|
||||||
},
|
},
|
||||||
render: function render(scope) {
|
render: function render(scope) {
|
||||||
scope.set(this.key, liquid.evalValue(this.value, scope));
|
var ctx = Object.create(types.AssignScope);
|
||||||
|
ctx[this.key] = liquid.evalValue(this.value, scope);
|
||||||
|
scope.push(ctx);
|
||||||
return Promise.resolve('');
|
return Promise.resolve('');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":15}],24:[function(require,module,exports){
|
},{"..":2,"../src/scope":11,"../src/util/assert.js":15}],24:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
var re = new RegExp('(' + lexical.identifier.source + ')');
|
var re = new RegExp('(' + lexical.identifier.source + ')');
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
var types = require('../src/scope.js').types;
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('capture', {
|
liquid.registerTag('capture', {
|
||||||
@@ -1980,13 +1967,15 @@ module.exports = function (liquid) {
|
|||||||
var _this2 = this;
|
var _this2 = this;
|
||||||
|
|
||||||
return liquid.renderer.renderTemplates(this.templates, scope).then(function (html) {
|
return liquid.renderer.renderTemplates(this.templates, scope).then(function (html) {
|
||||||
scope.set(_this2.variable, html);
|
var ctx = Object.create(types.CaptureScope);
|
||||||
|
ctx[_this2.variable] = html;
|
||||||
|
scope.push(ctx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":15}],25:[function(require,module,exports){
|
},{"..":2,"../src/scope.js":11,"../src/util/assert.js":15}],25:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
@@ -2104,6 +2093,7 @@ module.exports = function (liquid) {
|
|||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
var types = require('../src/scope').types;
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('decrement', {
|
liquid.registerTag('decrement', {
|
||||||
@@ -2113,14 +2103,22 @@ module.exports = function (liquid) {
|
|||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var v = scope.get(this.variable);
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
if (typeof v !== 'number') v = 0;
|
return Object.getPrototypeOf(ctx) !== types.CaptureScope && Object.getPrototypeOf(ctx) !== types.AssignScope;
|
||||||
scope.set(this.variable, v - 1);
|
});
|
||||||
|
if (!context) {
|
||||||
|
context = Object.create(types.DecrementScope);
|
||||||
|
scope.unshift(context);
|
||||||
|
}
|
||||||
|
if (typeof context[this.variable] !== 'number') {
|
||||||
|
context[this.variable] = 0;
|
||||||
|
}
|
||||||
|
return --context[this.variable];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":15}],29:[function(require,module,exports){
|
},{"..":2,"../src/scope":11,"../src/util/assert.js":15}],29:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
@@ -2216,7 +2214,7 @@ module.exports = function (liquid) {
|
|||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return scope.pop();
|
return scope.pop(context);
|
||||||
});
|
});
|
||||||
}).catch(function (e) {
|
}).catch(function (e) {
|
||||||
if (e instanceof RenderBreakError && e.message === 'break') {
|
if (e instanceof RenderBreakError && e.message === 'break') {
|
||||||
@@ -2324,7 +2322,7 @@ module.exports = function (liquid) {
|
|||||||
scope.push(hash);
|
scope.push(hash);
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
}).then(function (html) {
|
}).then(function (html) {
|
||||||
scope.pop();
|
scope.pop(hash);
|
||||||
scope.opts.blocks = originBlocks;
|
scope.opts.blocks = originBlocks;
|
||||||
scope.opts.blockMode = originBlockMode;
|
scope.opts.blockMode = originBlockMode;
|
||||||
return html;
|
return html;
|
||||||
@@ -2339,6 +2337,7 @@ module.exports = function (liquid) {
|
|||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
|
var types = require('../src/scope').types;
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('increment', {
|
liquid.registerTag('increment', {
|
||||||
@@ -2348,14 +2347,24 @@ module.exports = function (liquid) {
|
|||||||
this.variable = match[0];
|
this.variable = match[0];
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var v = scope.get(this.variable);
|
var context = scope.findContextFor(this.variable, function (ctx) {
|
||||||
if (typeof v !== 'number') v = 0;
|
return Object.getPrototypeOf(ctx) !== types.CaptureScope && Object.getPrototypeOf(ctx) !== types.AssignScope;
|
||||||
scope.set(this.variable, v + 1);
|
});
|
||||||
|
if (!context) {
|
||||||
|
context = Object.create(types.IncrementScope);
|
||||||
|
scope.unshift(context);
|
||||||
|
}
|
||||||
|
if (typeof context[this.variable] !== 'number') {
|
||||||
|
context[this.variable] = 0;
|
||||||
|
}
|
||||||
|
var val = context[this.variable];
|
||||||
|
context[this.variable]++;
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":15}],33:[function(require,module,exports){
|
},{"..":2,"../src/scope":11,"../src/util/assert.js":15}],33:[function(require,module,exports){
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = function (engine) {
|
module.exports = function (engine) {
|
||||||
@@ -2416,14 +2425,11 @@ module.exports = function (liquid) {
|
|||||||
}
|
}
|
||||||
return liquid.getTemplate(layout, scope.opts.root);
|
return liquid.getTemplate(layout, scope.opts.root);
|
||||||
}).then(function (templates) {
|
}).then(function (templates) {
|
||||||
// push the hash
|
|
||||||
scope.push(hash);
|
scope.push(hash);
|
||||||
scope.opts.blockMode = 'output';
|
scope.opts.blockMode = 'output';
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
})
|
}).then(function (partial) {
|
||||||
// pop the hash
|
scope.pop(hash);
|
||||||
.then(function (partial) {
|
|
||||||
scope.pop();
|
|
||||||
return partial;
|
return partial;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -2479,16 +2485,15 @@ module.exports = function (liquid) {
|
|||||||
var stream = liquid.parser.parseStream(remainTokens);
|
var stream = liquid.parser.parseStream(remainTokens);
|
||||||
stream.on('token', function (token) {
|
stream.on('token', function (token) {
|
||||||
if (token.name === 'endraw') stream.stop();else _this.tokens.push(token);
|
if (token.name === 'endraw') stream.stop();else _this.tokens.push(token);
|
||||||
}).on('end', function (x) {
|
}).on('end', function () {
|
||||||
throw new Error('tag ' + tagToken.raw + ' not closed');
|
throw new Error('tag ' + tagToken.raw + ' not closed');
|
||||||
});
|
});
|
||||||
stream.start();
|
stream.start();
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var tokens = this.tokens.map(function (token) {
|
return this.tokens.map(function (token) {
|
||||||
return token.raw;
|
return token.raw;
|
||||||
}).join('');
|
}).join('');
|
||||||
return Promise.resolve(tokens);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -2545,11 +2550,10 @@ module.exports = function (liquid) {
|
|||||||
// build array of arguments to pass to sequential promises...
|
// build array of arguments to pass to sequential promises...
|
||||||
collection = collection.slice(offset, offset + limit);
|
collection = collection.slice(offset, offset + limit);
|
||||||
if (!cols) cols = collection.length;
|
if (!cols) cols = collection.length;
|
||||||
var contexts = [];
|
var contexts = collection.map(function (item, i) {
|
||||||
collection.some(function (item, i) {
|
|
||||||
var ctx = {};
|
var ctx = {};
|
||||||
ctx[_this2.variable] = item;
|
ctx[_this2.variable] = item;
|
||||||
contexts.push(ctx);
|
return ctx;
|
||||||
});
|
});
|
||||||
|
|
||||||
return mapSeries(contexts, function (context, idx) {
|
return mapSeries(contexts, function (context, idx) {
|
||||||
@@ -2617,4 +2621,4 @@ module.exports = function (liquid) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2}]},{},[2])(2)
|
},{"..":2}]},{},[2])(2)
|
||||||
});
|
});
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liquidjs",
|
"name": "liquidjs",
|
||||||
"version": "5.0.1",
|
"version": "5.0.2",
|
||||||
"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": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user