mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Added append/prepend filters
This commit is contained in:
@@ -103,7 +103,17 @@ module Liquid
|
|||||||
# remove the first occurrences of a substring
|
# remove the first occurrences of a substring
|
||||||
def remove_first(input, string)
|
def remove_first(input, string)
|
||||||
input.to_s.sub(string, '')
|
input.to_s.sub(string, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# add one string to another
|
||||||
|
def append(input, string)
|
||||||
|
input.to_s + string.to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
# prepend a string to another
|
||||||
|
def prepend(input, string)
|
||||||
|
string.to_s + input.to_s
|
||||||
|
end
|
||||||
|
|
||||||
# Add <br /> tags in front of all newlines in input string
|
# Add <br /> tags in front of all newlines in input string
|
||||||
def newline_to_br(input)
|
def newline_to_br(input)
|
||||||
|
|||||||
@@ -393,6 +393,18 @@ HERE
|
|||||||
assert_template_result('321','{%for item in array reversed %}{{item}}{%endfor%}',assigns)
|
assert_template_result('321','{%for item in array reversed %}{{item}}{%endfor%}',assigns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_append
|
||||||
|
assigns = {'a' => 'bc', 'b' => 'd' }
|
||||||
|
assert_template_result('bcd',"{{ a | append: 'd'}}",assigns)
|
||||||
|
assert_template_result('bcd',"{{ a | append: b}}",assigns)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_prepend
|
||||||
|
assigns = {'a' => 'bc', 'b' => 'a' }
|
||||||
|
assert_template_result('abc',"{{ a | prepend: 'a'}}",assigns)
|
||||||
|
assert_template_result('abc',"{{ a | prepend: b}}",assigns)
|
||||||
|
end
|
||||||
|
|
||||||
def test_ifchanged
|
def test_ifchanged
|
||||||
assigns = {'array' => [ 1, 1, 2, 2, 3, 3] }
|
assigns = {'array' => [ 1, 1, 2, 2, 3, 3] }
|
||||||
assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
||||||
|
|||||||
Reference in New Issue
Block a user