Make truncate work for Ruby 1.8

This commit is contained in:
Florian Weingarten
2013-06-17 12:05:02 -04:00
parent f488058789
commit b81469d183

View File

@@ -43,7 +43,8 @@ module Liquid
if input.nil? then return end
l = length.to_i - truncate_string.length
l = 0 if l < 0
input.length > length.to_i ? input[0...l] + truncate_string : input
truncated = RUBY_VERSION[0,3] == "1.8" ? input.scan(/./mu)[0...l].to_s : input[0...l]
input.length > length.to_i ? truncated + truncate_string : input
end
def truncatewords(input, words = 15, truncate_string = "...")