Merge pull request #69 from trans/master

Added split filter
This commit is contained in:
Tobias Lütke
2011-09-05 13:01:15 -07:00
2 changed files with 13 additions and 0 deletions
+5
View File
@@ -53,6 +53,11 @@ module Liquid
wordlist.length > l ? wordlist[0..l].join(" ") + truncate_string : input wordlist.length > l ? wordlist[0..l].join(" ") + truncate_string : input
end end
# Split input string into an array of substrings separated by given pattern.
def split(input, pattern)
input.split(pattern)
end
def strip_html(input) def strip_html(input)
input.to_s.gsub(/<script.*?<\/script>/, '').gsub(/<.*?>/, '') input.to_s.gsub(/<script.*?<\/script>/, '').gsub(/<.*?>/, '')
end end
+8
View File
@@ -39,6 +39,14 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal '1234567890', @filters.truncate('1234567890') assert_equal '1234567890', @filters.truncate('1234567890')
end end
def test_strip
assert_equal ['12','34'], @filters.split('12~34', '~')
assert_equal ['A? ',' ,Z'], @filters.split('A? ~ ~ ~ ,Z', '~ ~ ~')
assert_equal ['A?Z'], @filters.split('A?Z', '~')
# Regexp works although Liquid does not support.
assert_equal ['A','Z'], @filters.split('AxZ', /x/)
end
def test_escape def test_escape
assert_equal '&lt;strong&gt;', @filters.escape('<strong>') assert_equal '&lt;strong&gt;', @filters.escape('<strong>')
assert_equal '&lt;strong&gt;', @filters.h('<strong>') assert_equal '&lt;strong&gt;', @filters.h('<strong>')