mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-15 04:10:40 -07:00
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:
+1
-1
@@ -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
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user