filtered variables in for loops

This commit is contained in:
James MacAulay 2008-10-24 14:50:59 -04:00
parent edf7b5577b
commit 3d8efe04a7
2 changed files with 5 additions and 1 deletions

View File

@ -42,7 +42,7 @@ module Liquid
# forloop.last:: Returns true if the item is the last item.
#
class For < Block
Syntax = /(\w+)\s+in\s+(#{VariableSignature}+)\s*(reversed)?/
Syntax = /(\w+)\s+in\s+(#{Expression}+)\s*(reversed)?/
def initialize(tag_name, markup, tokens)
if markup =~ Syntax

View File

@ -99,6 +99,10 @@ HERE
assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
end
def test_for_with_filtered_expressions
assert_template_result('abc','{% for letter in letters|sort %}{{ letter }}{% endfor %}', 'letters' => %w{c b a})
end
def test_limiting
assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
assert_template_result('12','{%for i in array limit:2 %}{{ i }}{%endfor%}',assigns)