mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Remove some legacy Ruby 1.8 compatibility code
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
## 3.0.0 / not yet released / branch "master"
|
## 3.0.0 / not yet released / branch "master"
|
||||||
|
|
||||||
* ...
|
* ...
|
||||||
|
* Remove some legacy Ruby 1.8 compatibility code, see #276 [Florian Weingarten, fw42]
|
||||||
* Add default filter to standard filters, see #267 [Derrick Reimer, djreimer]
|
* Add default filter to standard filters, see #267 [Derrick Reimer, djreimer]
|
||||||
* Add optional strict parsing and warn parsing, see #235 [Tristan Hume, trishume]
|
* Add optional strict parsing and warn parsing, see #235 [Tristan Hume, trishume]
|
||||||
* Add I18n syntax error translation, see #241 [Simon Hørup Eskildsen, Sirupsen]
|
* Add I18n syntax error translation, see #241 [Simon Hørup Eskildsen, Sirupsen]
|
||||||
|
|||||||
+4
-5
@@ -59,13 +59,12 @@ module Liquid
|
|||||||
# Check for method existence without invoking respond_to?, which creates symbols
|
# Check for method existence without invoking respond_to?, which creates symbols
|
||||||
def self.invokable?(method_name)
|
def self.invokable?(method_name)
|
||||||
unless @invokable_methods
|
unless @invokable_methods
|
||||||
# Ruby 1.8 compatibility: call to_s on method names (which are strings in 1.8, but already symbols in 1.9)
|
blacklist = Liquid::Drop.public_instance_methods + [:each]
|
||||||
blacklist = (Liquid::Drop.public_instance_methods + [:each]).map(&:to_s)
|
|
||||||
if include?(Enumerable)
|
if include?(Enumerable)
|
||||||
blacklist += Enumerable.public_instance_methods.map(&:to_s)
|
blacklist += Enumerable.public_instance_methods
|
||||||
blacklist -= [:sort, :count, :first, :min, :max, :include?].map(&:to_s)
|
blacklist -= [:sort, :count, :first, :min, :max, :include?]
|
||||||
end
|
end
|
||||||
whitelist = [:to_liquid] + (public_instance_methods.map(&:to_s) - blacklist.map(&:to_s))
|
whitelist = [:to_liquid] + (public_instance_methods - blacklist)
|
||||||
@invokable_methods = Set.new(whitelist.map(&:to_s))
|
@invokable_methods = Set.new(whitelist.map(&:to_s))
|
||||||
end
|
end
|
||||||
@invokable_methods.include?(method_name.to_s)
|
@invokable_methods.include?(method_name.to_s)
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ module Liquid
|
|||||||
if input.nil? then return end
|
if input.nil? then return end
|
||||||
l = length.to_i - truncate_string.length
|
l = length.to_i - truncate_string.length
|
||||||
l = 0 if l < 0
|
l = 0 if l < 0
|
||||||
truncated = RUBY_VERSION[0,3] == "1.8" ? input.scan(/./mu)[0...l].to_s : input[0...l]
|
input.length > length.to_i ? input[0...l] + truncate_string : input
|
||||||
input.length > length.to_i ? truncated + truncate_string : input
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def truncatewords(input, words = 15, truncate_string = "...")
|
def truncatewords(input, words = 15, truncate_string = "...")
|
||||||
|
|||||||
Reference in New Issue
Block a user