This commit is contained in:
Jun Yang
2018-03-05 01:34:00 +08:00
parent 11355cbf09
commit c6ff1f7911
3 changed files with 52 additions and 39 deletions
+22 -9
View File
@@ -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.staticValue = match[0];
}
match = lexical.value.exec(token.args);
if (match) {
this.value = match[0]; 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';
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -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": {