mirror of
https://github.com/kemko/liquid.git
synced 2026-01-04 17:25:41 +03:00
Merge pull request #174 from yardstick/drop-context
Allow a Liquid::Drop to be passed into Template#render
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user