mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
filtered variables in for loops
This commit is contained in:
@@ -42,7 +42,7 @@ module Liquid
|
|||||||
# forloop.last:: Returns true if the item is the last item.
|
# forloop.last:: Returns true if the item is the last item.
|
||||||
#
|
#
|
||||||
class For < Block
|
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)
|
def initialize(tag_name, markup, tokens)
|
||||||
if markup =~ Syntax
|
if markup =~ Syntax
|
||||||
|
|||||||
@@ -99,6 +99,10 @@ HERE
|
|||||||
assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
|
assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
|
||||||
end
|
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
|
def test_limiting
|
||||||
assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
|
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)
|
assert_template_result('12','{%for i in array limit:2 %}{{ i }}{%endfor%}',assigns)
|
||||||
|
|||||||
Reference in New Issue
Block a user