mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-19 14:30:38 -07:00
1.9.7
This commit is contained in:
Vendored
+91
-94
@@ -2092,7 +2092,9 @@ module.exports = function (liquid) {
|
|||||||
if (_.isString(collection) && collection.length > 0) {
|
if (_.isString(collection) && collection.length > 0) {
|
||||||
collection = [collection];
|
collection = [collection];
|
||||||
} else if (_.isObject(collection)) {
|
} else if (_.isObject(collection)) {
|
||||||
collection = Object.keys(collection);
|
collection = Object.keys(collection).map(function (key) {
|
||||||
|
return [key, collection[key]];
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!Array.isArray(collection) || !collection.length) {
|
if (!Array.isArray(collection) || !collection.length) {
|
||||||
@@ -2210,38 +2212,37 @@ var withRE = new RegExp('with\\s+(' + lexical.value.source + ')');
|
|||||||
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', {
|
||||||
|
parse: function parse(token) {
|
||||||
|
var match = lexical.value.exec(token.args);
|
||||||
|
assert(match, 'illegal token ' + token.raw);
|
||||||
|
this.value = match[0];
|
||||||
|
|
||||||
liquid.registerTag('include', {
|
match = withRE.exec(token.args);
|
||||||
parse: function parse(token) {
|
if (match) {
|
||||||
var match = lexical.value.exec(token.args);
|
this.with = match[1];
|
||||||
assert(match, 'illegal token ' + token.raw);
|
}
|
||||||
this.value = match[0];
|
},
|
||||||
|
render: function render(scope, hash) {
|
||||||
|
var filepath = Liquid.evalValue(this.value, scope);
|
||||||
|
|
||||||
match = withRE.exec(token.args);
|
var register = scope.get('liquid');
|
||||||
if (match) {
|
var originBlocks = register.blocks;
|
||||||
this.with = match[1];
|
register.blocks = {};
|
||||||
}
|
|
||||||
},
|
|
||||||
render: function render(scope, hash) {
|
|
||||||
var filepath = Liquid.evalValue(this.value, scope);
|
|
||||||
|
|
||||||
var register = scope.get('liquid');
|
if (this.with) {
|
||||||
var originBlocks = register.blocks;
|
hash[filepath] = Liquid.evalValue(this.with, scope);
|
||||||
register.blocks = {};
|
}
|
||||||
|
return liquid.getTemplate(filepath, register.root).then(function (templates) {
|
||||||
if (this.with) {
|
scope.push(hash);
|
||||||
hash[filepath] = Liquid.evalValue(this.with, scope);
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
}
|
}).then(function (html) {
|
||||||
return liquid.getTemplate(filepath, register.root).then(function (templates) {
|
scope.pop();
|
||||||
scope.push(hash);
|
register.blocks = originBlocks;
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
return html;
|
||||||
}).then(function (html) {
|
});
|
||||||
scope.pop();
|
}
|
||||||
register.blocks = originBlocks;
|
});
|
||||||
return html;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":16}],31:[function(require,module,exports){
|
},{"..":2,"../src/util/assert.js":16}],31:[function(require,module,exports){
|
||||||
@@ -2296,76 +2297,72 @@ var lexical = Liquid.lexical;
|
|||||||
var assert = require('../src/util/assert.js');
|
var assert = require('../src/util/assert.js');
|
||||||
|
|
||||||
module.exports = function (liquid) {
|
module.exports = function (liquid) {
|
||||||
|
liquid.registerTag('layout', {
|
||||||
|
parse: function parse(token, remainTokens) {
|
||||||
|
var match = lexical.value.exec(token.args);
|
||||||
|
assert(match, 'illegal token ' + token.raw);
|
||||||
|
|
||||||
liquid.registerTag('layout', {
|
this.layout = match[0];
|
||||||
parse: function parse(token, remainTokens) {
|
this.tpls = liquid.parser.parse(remainTokens);
|
||||||
var match = lexical.value.exec(token.args);
|
},
|
||||||
assert(match, 'illegal token ' + token.raw);
|
render: function render(scope, hash) {
|
||||||
|
var layout = Liquid.evalValue(this.layout, scope);
|
||||||
|
var register = scope.get('liquid');
|
||||||
|
|
||||||
this.layout = match[0];
|
// render the remaining tokens immediately
|
||||||
this.tpls = liquid.parser.parse(remainTokens);
|
return liquid.renderer.renderTemplates(this.tpls, scope)
|
||||||
},
|
// now register.blocks contains rendered blocks
|
||||||
render: function render(scope, hash) {
|
.then(function () {
|
||||||
var layout = Liquid.evalValue(this.layout, scope);
|
return liquid.getTemplate(layout, register.root);
|
||||||
var register = scope.get('liquid');
|
}).then(function (templates) {
|
||||||
|
// push the hash
|
||||||
|
scope.push(hash);
|
||||||
|
// render the parent
|
||||||
|
return liquid.renderer.renderTemplates(templates, scope);
|
||||||
|
})
|
||||||
|
// pop the hash
|
||||||
|
.then(function (partial) {
|
||||||
|
scope.pop();
|
||||||
|
return partial;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// render the remaining tokens immediately
|
liquid.registerTag('block', {
|
||||||
return liquid.renderer.renderTemplates(this.tpls, scope)
|
parse: function parse(token, remainTokens) {
|
||||||
// now register.blocks contains rendered blocks
|
var _this = this;
|
||||||
.then(function () {
|
|
||||||
return liquid.getTemplate(layout, register.root);
|
|
||||||
})
|
|
||||||
// push the hash
|
|
||||||
.then(function (templates) {
|
|
||||||
return scope.push(hash), templates;
|
|
||||||
})
|
|
||||||
// render the parent
|
|
||||||
.then(function (templates) {
|
|
||||||
return liquid.renderer.renderTemplates(templates, scope);
|
|
||||||
})
|
|
||||||
// pop the hash
|
|
||||||
.then(function (partial) {
|
|
||||||
return scope.pop(), partial;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
liquid.registerTag('block', {
|
var match = /\w+/.exec(token.args);
|
||||||
parse: function parse(token, remainTokens) {
|
this.block = match ? match[0] : 'anonymous';
|
||||||
var _this = this;
|
|
||||||
|
|
||||||
var match = /\w+/.exec(token.args);
|
this.tpls = [];
|
||||||
this.block = match ? match[0] : 'anonymous';
|
var stream = liquid.parser.parseStream(remainTokens).on('tag:endblock', function () {
|
||||||
|
return stream.stop();
|
||||||
|
}).on('template', function (tpl) {
|
||||||
|
return _this.tpls.push(tpl);
|
||||||
|
}).on('end', function () {
|
||||||
|
throw new Error('tag ' + token.raw + ' not closed');
|
||||||
|
});
|
||||||
|
stream.start();
|
||||||
|
},
|
||||||
|
render: function render(scope) {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
this.tpls = [];
|
var register = scope.get('liquid');
|
||||||
var stream = liquid.parser.parseStream(remainTokens).on('tag:endblock', function () {
|
var html = register.blocks[this.block];
|
||||||
return stream.stop();
|
// if not defined yet
|
||||||
}).on('template', function (tpl) {
|
if (html === undefined) {
|
||||||
return _this.tpls.push(tpl);
|
return liquid.renderer.renderTemplates(this.tpls, scope).then(function (partial) {
|
||||||
}).on('end', function () {
|
register.blocks[_this2.block] = partial;
|
||||||
throw new Error('tag ' + token.raw + ' not closed');
|
return partial;
|
||||||
});
|
});
|
||||||
stream.start();
|
} else {
|
||||||
},
|
// if already defined by desendents
|
||||||
render: function render(scope) {
|
register.blocks[this.block] = html;
|
||||||
var _this2 = this;
|
return Promise.resolve(html);
|
||||||
|
}
|
||||||
var register = scope.get('liquid');
|
}
|
||||||
var html = register.blocks[this.block];
|
});
|
||||||
// if not defined yet
|
|
||||||
if (html === undefined) {
|
|
||||||
return liquid.renderer.renderTemplates(this.tpls, scope).then(function (partial) {
|
|
||||||
register.blocks[_this2.block] = partial;
|
|
||||||
return partial;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// if already defined by desendents
|
|
||||||
else {
|
|
||||||
register.blocks[this.block] = html;
|
|
||||||
return Promise.resolve(html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
},{"..":2,"../src/util/assert.js":16,"any-promise":3}],34:[function(require,module,exports){
|
},{"..":2,"../src/util/assert.js":16,"any-promise":3}],34:[function(require,module,exports){
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Generated
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liquidjs",
|
"name": "liquidjs",
|
||||||
"version": "1.9.6",
|
"version": "1.9.7",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "liquidjs",
|
"name": "liquidjs",
|
||||||
"version": "1.9.6",
|
"version": "1.9.7",
|
||||||
"description": "A Liquid template engine for Node.js and browsers, with all shopify/liquid features.",
|
"description": "A Liquid template engine for Node.js and browsers, with all shopify/liquid features.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user