jlongster/nunjucks — pull request #49 by novocaine (2013-01-26 01:50:19+00:00)
Title: add support for array unpacking in for + add dictsort filter

i started off adding dictsort but then realised nunjucks needs to support array unpacking first so it can process the outputted array of arrays. so i stuck that in.

notes

* changed the lexer to process n comma separated variables in for loop unpacking expr (not just 2)

* emit code for separate processing of for loops with unpacking expressions when passed an array. unfortunately this check has to happen at runtime so we are now emitting an if block with two cases, which will have a small impact on generated code size. there might be a way of emitting the two alternate loops with less duplication; the code inside the loops is very similar so maybe it could be inside some local scoped function (or even use goto.. >:)

* added tests

* the dictsort implementation should be the same as jinja's which just returns a sorted list of tuples (array of arrays in js).