Revert "Revert "Added backwards compatibility for 1.8.7 String.each returning itself (and 1.9.3 not supporting .each).""

This reverts commit bce0033c65.
This commit is contained in:
Kristian PD
2012-01-20 16:54:26 -05:00
parent bce0033c65
commit 2b04590d4b
3 changed files with 205 additions and 167 deletions

View File

@@ -75,7 +75,8 @@ module Liquid
collection = context[@collection_name]
collection = collection.to_a if collection.is_a?(Range)
return render_else(context) unless collection.respond_to?(:each)
# 1.8.7 compatibility
return render_else(context) unless collection.respond_to?(:each) or collection.is_a?(String)
from = if @attributes['offset'] == 'continue'
context.registers[:for][@name].to_i
@@ -123,6 +124,10 @@ module Liquid
segments = []
index = 0
yielded = 0
# 1.8.7 compatibility
return [collection] if collection.is_a?(String)
collection.each do |item|
if to && to <= index