mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Use same approach in scope and environment
This commit is contained in:
@@ -143,10 +143,10 @@ module Liquid
|
|||||||
def find_variable(key, raise_on_not_found: true)
|
def find_variable(key, raise_on_not_found: true)
|
||||||
# This was changed from find() to find_index() because this is a very hot
|
# This was changed from find() to find_index() because this is a very hot
|
||||||
# path and find_index() is optimized in MRI to reduce object allocation
|
# path and find_index() is optimized in MRI to reduce object allocation
|
||||||
index = @scopes.find_index { |s| s.key?(key) }
|
|
||||||
scope = @scopes[index] if index
|
|
||||||
|
|
||||||
scope ||= @environments.find { |e| !e[key].nil? || @strict_variables && raise_on_not_found } || {}
|
scope = (index = @scopes.find_index { |s| s.key?(key) }) && @scopes[index]
|
||||||
|
scope ||= (index = @environments.find_index { |s| s.key?(key) }) && @environments[index]
|
||||||
|
scope ||= {}
|
||||||
|
|
||||||
variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found).to_liquid
|
variable = lookup_and_evaluate(scope, key, raise_on_not_found: raise_on_not_found).to_liquid
|
||||||
variable.context = self if variable.respond_to?(:context=)
|
variable.context = self if variable.respond_to?(:context=)
|
||||||
|
|||||||
@@ -80,10 +80,7 @@ class VariableTest < Minitest::Test
|
|||||||
assigns['test'] = 'Tobi'
|
assigns['test'] = 'Tobi'
|
||||||
assert_equal 'Hello Tobi', template.render!(assigns)
|
assert_equal 'Hello Tobi', template.render!(assigns)
|
||||||
assigns.delete('test')
|
assigns.delete('test')
|
||||||
e = assert_raises(RuntimeError) do
|
assert_equal "Hello ", template.render!(assigns)
|
||||||
template.render!(assigns)
|
|
||||||
end
|
|
||||||
assert_equal "Unknown variable 'test'", e.message
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_multiline_variable
|
def test_multiline_variable
|
||||||
|
|||||||
Reference in New Issue
Block a user