mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Adopt 'undef context='
This commit is contained in:
@@ -31,10 +31,10 @@ module Liquid
|
|||||||
@self_context.variable_defined?(key)
|
@self_context.variable_defined?(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
undef context
|
|
||||||
|
|
||||||
def to_liquid
|
def to_liquid
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
undef context=
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -151,8 +151,10 @@ module Liquid
|
|||||||
|
|
||||||
c
|
c
|
||||||
when Liquid::Drop
|
when Liquid::Drop
|
||||||
drop = args.shift
|
drop = args.shift
|
||||||
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
|
c = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
|
||||||
|
drop.context = c if drop.respond_to?(:context=)
|
||||||
|
c
|
||||||
when Hash
|
when Hash
|
||||||
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
|
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits, {}, @environment)
|
||||||
when nil
|
when nil
|
||||||
|
|||||||
@@ -69,12 +69,12 @@ class SelfDropContextTest < Minitest::Test
|
|||||||
assert_template_result('42', source)
|
assert_template_result('42', source)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_drop_context_writer_is_a_noop
|
def test_self_drop_context_setter_is_undefined
|
||||||
context = Context.new
|
context = Context.new
|
||||||
drop = SelfDrop.new(context)
|
drop = SelfDrop.new(context)
|
||||||
assert(drop.respond_to?(:context=))
|
refute(drop.respond_to?(:context=))
|
||||||
drop.context = Context.new
|
|
||||||
assert_nil(drop.instance_variable_get(:@context))
|
assert_template_result('42', '{{ self.x }}', { 'x' => 42 })
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_self_drop_with_strict_variables_does_not_raise_for_defined_var
|
def test_self_drop_with_strict_variables_does_not_raise_for_defined_var
|
||||||
@@ -88,4 +88,11 @@ class SelfDropContextTest < Minitest::Test
|
|||||||
result = t.render({}, strict_variables: true)
|
result = t.render({}, strict_variables: true)
|
||||||
assert_equal('', result)
|
assert_equal('', result)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_self_drop_can_be_passed_as_bare_drop_to_render
|
||||||
|
t = Template.parse('{{ self.x }}')
|
||||||
|
drop = SelfDrop.new(Context.new({ 'x' => 42 }))
|
||||||
|
result = t.render(drop)
|
||||||
|
assert_equal('42', result)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user