mirror of
https://github.com/Shopify/liquid.git
synced 2025-09-21 00:00:32 -04:00
filtered variables in for loops
This commit is contained in:
parent
edf7b5577b
commit
3d8efe04a7
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user