From 3d8efe04a743d6fb4c3bc8d198f630f9896b853e Mon Sep 17 00:00:00 2001 From: James MacAulay Date: Fri, 24 Oct 2008 14:50:59 -0400 Subject: [PATCH] filtered variables in for loops --- lib/liquid/tags/for.rb | 2 +- test/standard_tag_test.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index 5fb9d812..4ff86713 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -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 diff --git a/test/standard_tag_test.rb b/test/standard_tag_test.rb index 0b9dc8ac..aae09bda 100644 --- a/test/standard_tag_test.rb +++ b/test/standard_tag_test.rb @@ -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)