From 076ae903c0dc9c838297dce4609e9f97fbaf383f Mon Sep 17 00:00:00 2001 From: Daniel Huckstep Date: Wed, 5 Jun 2013 20:27:14 -0600 Subject: [PATCH] Make sure the context gets set --- lib/liquid/template.rb | 7 +++++-- test/liquid/template_test.rb | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index 3585dfc2..a65063c9 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -93,8 +93,11 @@ module Liquid context = case args.first when Liquid::Context args.shift - when Hash, Liquid::Drop - Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits) + when Liquid::Drop + 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 Context.new(assigns, instance_assigns, registers, @rethrow_errors, @resource_limits) else diff --git a/test/liquid/template_test.rb b/test/liquid/template_test.rb index 22e1edae..04f1e508 100644 --- a/test/liquid/template_test.rb +++ b/test/liquid/template_test.rb @@ -8,6 +8,10 @@ class TemplateContextDrop < Liquid::Drop def foo 'fizzbuzz' end + + def baz + @context.registers['lulz'] + end end class TemplateTest < Test::Unit::TestCase @@ -133,8 +137,10 @@ class TemplateTest < Test::Unit::TestCase def test_can_use_drop_as_context t = Template.new + t.registers['lulz'] = 'haha' drop = TemplateContextDrop.new assert_equal 'fizzbuzz', t.parse('{{foo}}').render(drop) assert_equal 'bar', t.parse('{{bar}}').render(drop) + assert_equal 'haha', t.parse("{{baz}}").render(drop) end end # TemplateTest