Merge pull request #174 from yardstick/drop-context

Allow a Liquid::Drop to be passed into Template#render
This commit is contained in:
Dylan Thacker-Smith
2013-06-10 07:46:06 -07:00
2 changed files with 26 additions and 0 deletions

View File

@@ -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

View File

@@ -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