mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
Enable Instance Assigns to survive many renders
This commit is contained in:
@@ -143,11 +143,12 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def instance_assigns
|
def instance_assigns
|
||||||
@instance_assigns ||= {}
|
@instance_assigns ||= []
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_outer_scope
|
def new_outer_scope
|
||||||
@instance_assigns = {}
|
@instance_assigns.unshift(last = {})
|
||||||
|
last
|
||||||
end
|
end
|
||||||
|
|
||||||
def errors
|
def errors
|
||||||
|
|||||||
@@ -42,6 +42,18 @@ class TemplateTest < Minitest::Test
|
|||||||
assert_equal 'from instance assigns', t.parse("{{ foo }}").render!
|
assert_equal 'from instance assigns', t.parse("{{ foo }}").render!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_instance_assigns_persist_on_same_template_object_between_many_parses
|
||||||
|
t = Template.new
|
||||||
|
assert_equal 'from instance assigns', t.parse("{% assign foo = 'from instance assigns' %}{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns', t.parse("{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns', t.parse("{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns', t.parse("{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns second', t.parse("{% assign foo = 'from instance assigns second' %}{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns second', t.parse("{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns second', t.parse("{{ foo }}").render!
|
||||||
|
assert_equal 'from instance assigns second', t.parse("{{ foo }}").render!
|
||||||
|
end
|
||||||
|
|
||||||
def test_warnings_is_not_exponential_time
|
def test_warnings_is_not_exponential_time
|
||||||
str = "false"
|
str = "false"
|
||||||
100.times do
|
100.times do
|
||||||
@@ -58,6 +70,14 @@ class TemplateTest < Minitest::Test
|
|||||||
assert_equal 'foofoo', t.render!
|
assert_equal 'foofoo', t.render!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_instance_assigns_persist_on_same_template_parsing_between_many_renders
|
||||||
|
t = Template.new.parse("{{ foo }}{% assign foo = 'foo' %}{{ foo }}")
|
||||||
|
assert_equal 'foo', t.render!
|
||||||
|
assert_equal 'foofoo', t.render!
|
||||||
|
assert_equal 'foofoo', t.render!
|
||||||
|
assert_equal 'foofoo', t.render!
|
||||||
|
end
|
||||||
|
|
||||||
def test_custom_assigns_do_not_persist_on_same_template
|
def test_custom_assigns_do_not_persist_on_same_template
|
||||||
t = Template.new
|
t = Template.new
|
||||||
assert_equal 'from custom assigns', t.parse("{{ foo }}").render!('foo' => 'from custom assigns')
|
assert_equal 'from custom assigns', t.parse("{{ foo }}").render!('foo' => 'from custom assigns')
|
||||||
|
|||||||
Reference in New Issue
Block a user