diff --git a/lib/liquid/template.rb b/lib/liquid/template.rb index a4895d8..5e0675f 100644 --- a/lib/liquid/template.rb +++ b/lib/liquid/template.rb @@ -93,6 +93,9 @@ module Liquid context = case args.first when Liquid::Context args.shift + 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, @resource_limits) when nil diff --git a/test/liquid/template_test.rb b/test/liquid/template_test.rb index 6fb68e8..04f1e50 100644 --- a/test/liquid/template_test.rb +++ b/test/liquid/template_test.rb @@ -1,5 +1,19 @@ require 'test_helper' +class TemplateContextDrop < Liquid::Drop + def before_method(method) + method + end + + def foo + 'fizzbuzz' + end + + def baz + @context.registers['lulz'] + end +end + class TemplateTest < Test::Unit::TestCase include Liquid @@ -120,4 +134,13 @@ class TemplateTest < Test::Unit::TestCase assert t.resource_limits[:render_score_current] > 0 assert t.resource_limits[:render_length_current] > 0 end + + 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