diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 254ac72a..19ace466 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -103,7 +103,17 @@ module Liquid # remove the first occurrences of a substring def remove_first(input, 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
tags in front of all newlines in input string def newline_to_br(input) diff --git a/test/standard_tag_test.rb b/test/standard_tag_test.rb index 7b332536..0de995be 100644 --- a/test/standard_tag_test.rb +++ b/test/standard_tag_test.rb @@ -393,6 +393,18 @@ HERE assert_template_result('321','{%for item in array reversed %}{{item}}{%endfor%}',assigns) 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 assigns = {'array' => [ 1, 1, 2, 2, 3, 3] } assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)