move slice_collection optimization to utils

This commit is contained in:
Tom Burns
2013-11-24 14:00:23 -05:00
parent 2c26a880f0
commit e667352629
3 changed files with 17 additions and 10 deletions
+1 -1
View File
@@ -23,7 +23,7 @@ module Liquid
from = @attributes['offset'] ? context[@attributes['offset']].to_i : 0
to = @attributes['limit'] ? from + context[@attributes['limit']].to_i : nil
collection = Utils.slice_collection_using_each(collection, from, to)
collection = Utils.slice_collection(collection, from, to)
length = collection.length
+1 -5
View File
@@ -75,11 +75,7 @@ module Liquid
limit = context[@attributes['limit']]
to = limit ? limit.to_i + from : nil
segment = if (from != 0 || to != nil) && collection.respond_to?(:load_slice)
collection.load_slice(from, to)
else
Utils.slice_collection_using_each(collection, from, to)
end
segment = Utils.slice_collection(collection, from, to)
return render_else(context) if segment.empty?
+15 -4
View File
@@ -1,5 +1,20 @@
module Liquid
module Utils
def self.slice_collection(collection, from, to)
if (from != 0 || to != nil) && collection.respond_to?(:load_slice)
collection.load_slice(from, to)
else
slice_collection_using_each(collection, from, to)
end
end
def self.non_blank_string?(collection)
collection.is_a?(String) && collection != ''
end
private
def self.slice_collection_using_each(collection, from, to)
segments = []
index = 0
@@ -22,9 +37,5 @@ module Liquid
segments
end
def self.non_blank_string?(collection)
collection.is_a?(String) && collection != ''
end
end
end