mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-04 01:25:14 -07:00
Make sure the context gets set
This commit is contained in:
@@ -93,8 +93,11 @@ module Liquid
|
|||||||
context = case args.first
|
context = case args.first
|
||||||
when Liquid::Context
|
when Liquid::Context
|
||||||
args.shift
|
args.shift
|
||||||
when Hash, Liquid::Drop
|
when Liquid::Drop
|
||||||
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
drop = args.shift
|
||||||
|
drop.context = Context.new([drop, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
||||||
|
when Hash
|
||||||
|
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors)
|
||||||
when nil
|
when nil
|
||||||
Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits)
|
Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits)
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ class TemplateContextDrop < Liquid::Drop
|
|||||||
def foo
|
def foo
|
||||||
'fizzbuzz'
|
'fizzbuzz'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def baz
|
||||||
|
@context.registers['lulz']
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TemplateTest < Test::Unit::TestCase
|
class TemplateTest < Test::Unit::TestCase
|
||||||
@@ -133,8 +137,10 @@ class TemplateTest < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_can_use_drop_as_context
|
def test_can_use_drop_as_context
|
||||||
t = Template.new
|
t = Template.new
|
||||||
|
t.registers['lulz'] = 'haha'
|
||||||
drop = TemplateContextDrop.new
|
drop = TemplateContextDrop.new
|
||||||
assert_equal 'fizzbuzz', t.parse('{{foo}}').render(drop)
|
assert_equal 'fizzbuzz', t.parse('{{foo}}').render(drop)
|
||||||
assert_equal 'bar', t.parse('{{bar}}').render(drop)
|
assert_equal 'bar', t.parse('{{bar}}').render(drop)
|
||||||
|
assert_equal 'haha', t.parse("{{baz}}").render(drop)
|
||||||
end
|
end
|
||||||
end # TemplateTest
|
end # TemplateTest
|
||||||
|
|||||||
Reference in New Issue
Block a user