Merge branch 'chenos-master'

This commit is contained in:
harttle
2017-03-15 17:13:58 +08:00
3 changed files with 16 additions and 3 deletions
+1 -1
View File
@@ -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/
+2 -1
View File
@@ -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', {
+13 -1
View File
@@ -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');
});
});