diff --git a/.travis.yml b/.travis.yml index 7b3ed3b54..e723df420 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: - - "node" - - "lts/*" + - "8" + - "6" - "4" before_script: - npm install -g mocha diff --git a/tags/tablerow.js b/tags/tablerow.js index 027f2106b..eaa0fb96e 100644 --- a/tags/tablerow.js +++ b/tags/tablerow.js @@ -32,17 +32,17 @@ module.exports = function (liquid) { render: function (scope, hash) { var collection = Liquid.evalExp(this.collection, scope) || [] - var html = '' + var html = '' var offset = hash.offset || 0 var limit = (hash.limit === undefined) ? collection.length : hash.limit var cols = hash.cols var row var col - if (!cols) throw new Error(`illegal cols: ${cols}`) // build array of arguments to pass to sequential promises... collection = collection.slice(offset, offset + limit) + if (!cols) cols = collection.length var contexts = [] collection.some((item, i) => { var ctx = {} @@ -76,7 +76,6 @@ module.exports = function (liquid) { if (row > 0) { html += '' } - html += '
' return html }) } diff --git a/test/tags/tablerow.js b/test/tags/tablerow.js index 61de6aec7..82d62378e 100644 --- a/test/tags/tablerow.js +++ b/test/tags/tablerow.js @@ -5,28 +5,39 @@ chai.use(require('chai-as-promised')) describe('tags/tablerow', function () { var liquid = Liquid() - + it('should support tablerow', function () { + var src = '{% tablerow i in (1..3)%}{{ i }}{% endtablerow %}' + var dst = '123' + return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) + }) + + it('should support cols', function () { var src = '{% tablerow i in alpha cols:2 %}{{ i }}{% endtablerow %}' var ctx = { alpha: ['a', 'b', 'c'] } - var dst = '' + + var dst = '' + - '' + - '
ab
c
' + 'c' return expect(liquid.parseAndRender(src, ctx)).to.eventually.equal(dst) }) + it('should support cols set to 0', function () { + var src = '{% tablerow i in (1..3) cols:0 %}{{ i }}{% endtablerow %}' + var dst = '123' + return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) + }) + it('should support empty tablerow', function () { var src = '{% tablerow i in (1..0) cols:2 %}{{ i }}{% endtablerow %}' - var dst = '
' + var dst = '' return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) }) it('should support empty array', function () { var src = '{% tablerow i in alpha.z cols:2 %}{{ i }}{% endtablerow %}' - var dst = '
' + var dst = '' return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) }) @@ -38,39 +49,24 @@ describe('tags/tablerow', function () { it('should support tablerow with range', function () { var src = '{% tablerow i in (1..5) cols:2 %}{{ i }}{% endtablerow %}' - var dst = '' + + var dst = '' + '' + - '' + - '
12
34
5
' + '5' return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) }) - it('tablerow should throw on illegal cols 1', function () { - var src = '{% tablerow i in (1..5) cols:0 %}{{ i }}{% endtablerow %}' - return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/illegal cols: 0/) - }) - it('tablerow should throw on illegal cols 2', function () { - var src = '{% tablerow i in (1..5) %}{{ i }}{% endtablerow %}' - return expect(liquid.parseAndRender(src)) - .to.be.rejectedWith(/illegal cols: undefined/) - }) - it('should support tablerow with limit', function () { var src = '{% tablerow i in (1..5) cols:2 limit:3 %}{{ i }}{% endtablerow %}' - var dst = '' + + var dst = '' + - '' + - '
12
3
' + '3' return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) }) it('should support tablerow with offset', function () { var src = '{% tablerow i in (1..5) cols:2 offset:3 %}{{ i }}{% endtablerow %}' - var dst = '' + - '' + - '
45
' + var dst = '45' return expect(liquid.parseAndRender(src)).to.eventually.equal(dst) }) })