Fix to make for tag iterate objects like Shopify liquid.

Ref: https://github.com/Shopify/liquid/wiki/Liquid-for-Designers#allowed-collection-types
This commit is contained in:
Mehdi Jaffery
2017-10-18 05:41:43 -05:00
committed by Jun Yang
parent d08ad6dc97
commit 118624ca7d
2 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ module.exports = function (liquid) {
if (_.isString(collection) && collection.length > 0) {
collection = [collection]
} else if (_.isObject(collection)) {
collection = Object.keys(collection)
collection = Object.keys(collection).map((key) => [key, collection[key]])
}
}
if (!Array.isArray(collection) || !collection.length) {
+2 -2
View File
@@ -28,9 +28,9 @@ describe('tags/for', function () {
})
it('should support object', function () {
var src = '{%for key in obj%}{{key}}-{%else%}b{%endfor%}'
var src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}'
return expect(liquid.parseAndRender(src, ctx))
.to.eventually.equal('foo-coo-')
.to.eventually.equal('foo,bar-coo,haa-')
})
describe('scope', function () {