mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-03 09:05:13 -07:00
Resolve literals faster.
This commit is contained in:
+12
-10
@@ -111,6 +111,14 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
LITERALS = {
|
||||||
|
nil => nil, 'nil' => nil, 'null' => nil, '' => nil,
|
||||||
|
'true' => true,
|
||||||
|
'false' => false,
|
||||||
|
'blank' => :blank?,
|
||||||
|
'empty' => :empty?
|
||||||
|
}
|
||||||
|
|
||||||
# Look up variable, either resolve directly after considering the name. We can directly handle
|
# Look up variable, either resolve directly after considering the name. We can directly handle
|
||||||
# Strings, digits, floats and booleans (true,false).
|
# Strings, digits, floats and booleans (true,false).
|
||||||
# If no match is made we lookup the variable in the current scope and
|
# If no match is made we lookup the variable in the current scope and
|
||||||
@@ -120,17 +128,10 @@ module Liquid
|
|||||||
# Example:
|
# Example:
|
||||||
# products == empty #=> products.empty?
|
# products == empty #=> products.empty?
|
||||||
def resolve(key)
|
def resolve(key)
|
||||||
|
if LITERALS.key?(key)
|
||||||
|
LITERALS[key]
|
||||||
|
else
|
||||||
case key
|
case key
|
||||||
when nil, 'nil', 'null', ''
|
|
||||||
nil
|
|
||||||
when 'true'
|
|
||||||
true
|
|
||||||
when 'false'
|
|
||||||
false
|
|
||||||
when 'blank'
|
|
||||||
:blank?
|
|
||||||
when 'empty'
|
|
||||||
:empty?
|
|
||||||
when /^'(.*)'$/ # Single quoted strings
|
when /^'(.*)'$/ # Single quoted strings
|
||||||
$1.to_s
|
$1.to_s
|
||||||
when /^"(.*)"$/ # Double quoted strings
|
when /^"(.*)"$/ # Double quoted strings
|
||||||
@@ -145,6 +146,7 @@ module Liquid
|
|||||||
variable(key)
|
variable(key)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Fetches an object starting at the local scope and then moving up the hierachy
|
# Fetches an object starting at the local scope and then moving up the hierachy
|
||||||
def find_variable(key)
|
def find_variable(key)
|
||||||
|
|||||||
Reference in New Issue
Block a user