From 2d1f05799f43b02b5b47f94f488eff93e20badd3 Mon Sep 17 00:00:00 2001 From: Jun Yang Date: Sat, 18 Feb 2017 17:14:51 +0800 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a6edd30d7..1e89d4104 100644 --- a/README.md +++ b/README.md @@ -209,7 +209,7 @@ engine.registerTag('upper', { ## Contribution Guide 1. Write a [test][test] to define the feature you want. -2. Just initiate an issue, or optionally: +2. File an issue, or optionally: 3. Get your test pass and make a pull request. [nunjucks]: http://mozilla.github.io/nunjucks/ From 48bee428d575ce59acc2d4d870e783eb6669907e Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 15 Mar 2017 16:59:24 +0800 Subject: [PATCH 2/3] reversed position eg: - reversed limit:4 offset:2 - limit:4 reversed offset:2 - limit:4 offset:2 reversed --- tags/for.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tags/for.js b/tags/for.js index 97f0f18a7..ba2c75cef 100644 --- a/tags/for.js +++ b/tags/for.js @@ -6,7 +6,8 @@ const assert = require('../src/util/assert.js'); const re = new RegExp(`^(${lexical.identifier.source})\\s+in\\s+` + `(${lexical.value.source})` + `(?:\\s+${lexical.hash.source})*` + - `(?:\\s+(reversed))?$`); + `(?:\\s+(reversed))?` + + `(?:\\s+${lexical.hash.source})*`); module.exports = function(liquid) { liquid.registerTag('for', { From 0f4edc5b53168c6d57f95a87262d83f5aa5d5159 Mon Sep 17 00:00:00 2001 From: harttle Date: Wed, 15 Mar 2017 17:13:05 +0800 Subject: [PATCH 3/3] add unit test for #21 --- tags/for.js | 2 +- test/tags/for.js | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tags/for.js b/tags/for.js index ba2c75cef..e75ed1d20 100644 --- a/tags/for.js +++ b/tags/for.js @@ -7,7 +7,7 @@ const re = new RegExp(`^(${lexical.identifier.source})\\s+in\\s+` + `(${lexical.value.source})` + `(?:\\s+${lexical.hash.source})*` + `(?:\\s+(reversed))?` + - `(?:\\s+${lexical.hash.source})*`); + `(?:\\s+${lexical.hash.source})*$`); module.exports = function(liquid) { liquid.registerTag('for', { diff --git a/test/tags/for.js b/test/tags/for.js index fc26b15bc..6872286fd 100644 --- a/test/tags/for.js +++ b/test/tags/for.js @@ -74,9 +74,21 @@ describe('tags/for', function() { .to.eventually.equal('67'); }); - it('should support for reversed', function() { + it('should support for reversed in the last position', function() { var src = '{% for i in (1..5) limit:2 reversed %}{{ i }}{% endfor %}'; return expect(liquid.parseAndRender(src, ctx)) .to.eventually.equal('21'); }); + + it('should support for reversed in the middle position', function() { + var src = '{% for i in (1..5) reversed limit:2 %}{{ i }}{% endfor %}'; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('21'); + }); + + it('should support for reversed in the first position', function() { + var src = '{% for i in (1..5) offset:2 reversed limit:4 %}{{ i }}{% endfor %}'; + return expect(liquid.parseAndRender(src, ctx)) + .to.eventually.equal('543'); + }); });