Slice filter for arrays.

This commit is contained in:
Florian Weingarten
2014-08-05 17:59:31 +00:00
parent 66ae7f3ec0
commit fb6f9c1c13
2 changed files with 20 additions and 1 deletions
+6 -1
View File
@@ -45,7 +45,12 @@ module Liquid
def slice(input, offset, length=nil)
offset = Integer(offset)
length = length ? Integer(length) : 1
input.to_s.slice(offset, length) || ''
if input.is_a?(Array)
input.slice(offset, length) || []
else
input.to_s.slice(offset, length) || ''
end
end
# Truncate a string down to x characters