Allow tablerow to work with any Enumerable. Closes #132

This commit is contained in:
Dylan Smith
2012-06-20 11:07:11 -04:00
parent 6ebdded8f2
commit d0184555d9
5 changed files with 59 additions and 38 deletions
+31
View File
@@ -0,0 +1,31 @@
module Liquid
module Utils
def self.slice_collection_using_each(collection, from, to)
segments = []
index = 0
yielded = 0
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
return [collection] if non_blank_string?(collection)
collection.each do |item|
if to && to <= index
break
end
if from <= index
segments << item
end
index += 1
end
segments
end
def self.non_blank_string?(collection)
collection.is_a?(String) && collection != ''
end
end
end