mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 07:05:12 -07:00
Allow a Liquid::Drop to be passed into Template#render
This commit is contained in:
@@ -93,6 +93,8 @@ module Liquid
|
|||||||
context = case args.first
|
context = case args.first
|
||||||
when Liquid::Context
|
when Liquid::Context
|
||||||
args.shift
|
args.shift
|
||||||
|
when Liquid::Drop
|
||||||
|
Context.new(args.shift, instance_assigns, registers, @rethrow_errors)
|
||||||
when Hash
|
when Hash
|
||||||
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
Context.new([args.shift, assigns], instance_assigns, registers, @rethrow_errors, @resource_limits)
|
||||||
when nil
|
when nil
|
||||||
|
|||||||
@@ -1,5 +1,15 @@
|
|||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
|
class TemplateContextDrop < Liquid::Drop
|
||||||
|
def before_method(method)
|
||||||
|
method
|
||||||
|
end
|
||||||
|
|
||||||
|
def foo
|
||||||
|
'foo'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
class TemplateTest < Test::Unit::TestCase
|
class TemplateTest < Test::Unit::TestCase
|
||||||
include Liquid
|
include Liquid
|
||||||
|
|
||||||
@@ -120,4 +130,11 @@ class TemplateTest < Test::Unit::TestCase
|
|||||||
assert t.resource_limits[:render_score_current] > 0
|
assert t.resource_limits[:render_score_current] > 0
|
||||||
assert t.resource_limits[:render_length_current] > 0
|
assert t.resource_limits[:render_length_current] > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_can_use_drop_as_context
|
||||||
|
t = Template.new
|
||||||
|
drop = TemplateContextDrop.new
|
||||||
|
assert_equal 'foo', t.parse('{{foo}}').render(drop)
|
||||||
|
assert_equal 'bar', t.parse('{{bar}}').render(drop)
|
||||||
|
end
|
||||||
end # TemplateTest
|
end # TemplateTest
|
||||||
|
|||||||
Reference in New Issue
Block a user