Merge pull request #414 from Shopify/to_liquid_context

Call to_liquid in Context invoke
This commit is contained in:
Florian Weingarten
2014-08-12 22:05:52 +02:00
4 changed files with 16 additions and 1 deletions

View File

@@ -105,7 +105,7 @@ module Liquid
end
def invoke(method, *args)
strainer.invoke(method, *args)
strainer.invoke(method, *args).to_liquid
end
# Push new local scope on the stack. use <tt>Context#stack</tt> instead

View File

@@ -220,6 +220,11 @@ class StandardFiltersTest < Minitest::Test
assert_template_result "213", '{{ foo | sort: "bar" | map: "foo" }}', "foo" => TestEnumerable.new
end
def test_first_and_last_call_to_liquid
assert_template_result 'foobar', '{{ foo | first }}', 'foo' => [ThingWithToLiquid.new]
assert_template_result 'foobar', '{{ foo | last }}', 'foo' => [ThingWithToLiquid.new]
end
def test_date
assert_equal 'May', @filters.date(Time.parse("2006-05-05 10:00:00"), "%B")
assert_equal 'June', @filters.date(Time.parse("2006-06-05 10:00:00"), "%B")

View File

@@ -9,6 +9,10 @@ class VariableTest < Minitest::Test
assert_equal 'worked wonderfully', template.render!('test' => 'worked wonderfully')
end
def test_variable_render_calls_to_liquid
assert_template_result 'foobar', '{{ foo }}', 'foo' => ThingWithToLiquid.new
end
def test_simple_with_whitespaces
template = Template.parse(%| {{ test }} |)
assert_equal ' worked ', template.render!('test' => 'worked')

View File

@@ -66,3 +66,9 @@ module Minitest
end
end
end
class ThingWithToLiquid
def to_liquid
'foobar'
end
end