mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-20 06:50:47 -07:00
3.1.1
This commit is contained in:
Vendored
+50
-37
@@ -2164,41 +2164,41 @@ var candidatesRE = new RegExp(lexical.value.source, 'g');
|
|||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('cycle', {
|
liquid.registerTag('cycle', {
|
||||||
|
|
||||||
parse: function parse(tagToken, remainTokens) {
|
parse: function parse(tagToken, remainTokens) {
|
||||||
var match = groupRE.exec(tagToken.args);
|
var match = groupRE.exec(tagToken.args);
|
||||||
assert(match, 'illegal tag: ' + tagToken.raw);
|
assert(match, 'illegal tag: ' + tagToken.raw);
|
||||||
|
|
||||||
this.group = match[1] || '';
|
this.group = match[1] || '';
|
||||||
var candidates = match[2];
|
var candidates = match[2];
|
||||||
|
|
||||||
this.candidates = [];
|
this.candidates = [];
|
||||||
|
|
||||||
while (match = candidatesRE.exec(candidates)) {
|
while (match = candidatesRE.exec(candidates)) {
|
||||||
this.candidates.push(match[0]);
|
this.candidates.push(match[0]);
|
||||||
}
|
}
|
||||||
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
assert(this.candidates.length, 'empty candidates: ' + tagToken.raw);
|
||||||
},
|
},
|
||||||
|
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var group = Liquid.evalValue(this.group, scope);
|
var group = Liquid.evalValue(this.group, scope);
|
||||||
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
var fingerprint = 'cycle:' + group + ':' + this.candidates.join(',');
|
||||||
|
|
||||||
var groups = scope.opts.groups = scope.opts.groups || {};
|
var groups = scope.opts.groups = scope.opts.groups || {};
|
||||||
var idx = groups[fingerprint];
|
var idx = groups[fingerprint];
|
||||||
|
|
||||||
if (idx === undefined) {
|
if (idx === undefined) {
|
||||||
idx = groups[fingerprint] = 0;
|
idx = groups[fingerprint] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var candidate = this.candidates[idx];
|
var candidate = this.candidates[idx];
|
||||||
idx = (idx + 1) % this.candidates.length;
|
idx = (idx + 1) % this.candidates.length;
|
||||||
groups[fingerprint] = idx;
|
groups[fingerprint] = idx;
|
||||||
|
|
||||||
return Promise.resolve(Liquid.evalValue(candidate, scope));
|
return Promise.resolve(Liquid.evalValue(candidate, scope));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":18,"any-promise":3}],31:[function(require,module,exports){
|
},{"..":2,"../src/util/assert.js":18,"any-promise":3}],31:[function(require,module,exports){
|
||||||
@@ -2391,14 +2391,21 @@ module.exports = function (liquid) {
|
|||||||
var Liquid = require('..');
|
var Liquid = require('..');
|
||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
var withRE = new RegExp('with\\s+(' + lexical.value.source + ')');
|
var withRE = new RegExp('with\\s+(' + lexical.value.source + ')');
|
||||||
|
var staticFileRE = /\S+/;
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('include', {
|
liquid.registerTag('include', {
|
||||||
parse: function parse(token) {
|
parse: function parse(token) {
|
||||||
var match = lexical.value.exec(token.args);
|
var match = staticFileRE.exec(token.args);
|
||||||
assert(match, 'illegal token ' + token.raw);
|
if (match) {
|
||||||
this.value = match[0];
|
this.staticValue = match[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
match = lexical.value.exec(token.args);
|
||||||
|
if (match) {
|
||||||
|
this.value = match[0];
|
||||||
|
}
|
||||||
|
|
||||||
match = withRE.exec(token.args);
|
match = withRE.exec(token.args);
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -2406,10 +2413,8 @@ module.exports = function (liquid) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var filepath = this.value;
|
var filepath = scope.opts.dynamicPartials ? Liquid.evalValue(this.value, scope) : this.staticValue;
|
||||||
if (scope.opts.dynamicPartials) {
|
assert(filepath, 'cannot include with empty filename');
|
||||||
filepath = Liquid.evalValue(this.value, scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
var originBlocks = scope.opts.blocks;
|
var originBlocks = scope.opts.blocks;
|
||||||
var originBlockMode = scope.opts.blockMode;
|
var originBlockMode = scope.opts.blockMode;
|
||||||
@@ -2481,6 +2486,7 @@ var Liquid = require('..');
|
|||||||
var Promise = require('any-promise');
|
var Promise = require('any-promise');
|
||||||
var lexical = Liquid.lexical;
|
var lexical = Liquid.lexical;
|
||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
var staticFileRE = /\S+/;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* blockMode:
|
* blockMode:
|
||||||
@@ -2491,14 +2497,21 @@ var assert = require('../src/util/assert.js');
|
|||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
liquid.registerTag('layout', {
|
liquid.registerTag('layout', {
|
||||||
parse: function parse(token, remainTokens) {
|
parse: function parse(token, remainTokens) {
|
||||||
var match = lexical.value.exec(token.args);
|
var match = staticFileRE.exec(token.args);
|
||||||
assert(match, 'illegal token ' + token.raw);
|
if (match) {
|
||||||
|
this.staticLayout = match[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
match = lexical.value.exec(token.args);
|
||||||
|
if (match) {
|
||||||
|
this.layout = match[0];
|
||||||
|
}
|
||||||
|
|
||||||
this.layout = match[0];
|
|
||||||
this.tpls = liquid.parser.parse(remainTokens);
|
this.tpls = liquid.parser.parse(remainTokens);
|
||||||
},
|
},
|
||||||
render: function render(scope, hash) {
|
render: function render(scope, hash) {
|
||||||
var layout = scope.opts.dynamicPartials ? Liquid.evalValue(this.layout, scope) : this.layout;
|
var layout = scope.opts.dynamicPartials ? Liquid.evalValue(this.layout, scope) : this.staticLayout;
|
||||||
|
assert(layout, 'cannot apply layout with empty filename');
|
||||||
|
|
||||||
// render the remaining tokens immediately
|
// render the remaining tokens immediately
|
||||||
scope.opts.blockMode = 'store';
|
scope.opts.blockMode = 'store';
|
||||||
|
|||||||
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": "3.1.0",
|
"version": "3.1.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": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user