Merge pull request #1414 from Shopify/fix/echo-parse-tree-visitor

Add ParseTreeVisitor to Echo tag
This commit is contained in:
Charles-Philippe Clermont
2021-03-24 09:38:48 -04:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -12,6 +12,8 @@ module Liquid
# {% echo user | link %} # {% echo user | link %}
# #
class Echo < Tag class Echo < Tag
attr_reader :variable
def initialize(tag_name, markup, parse_context) def initialize(tag_name, markup, parse_context)
super super
@variable = Variable.new(markup, parse_context) @variable = Variable.new(markup, parse_context)
@@ -20,6 +22,12 @@ module Liquid
def render(context) def render(context)
@variable.render_to_output_buffer(context, +'') @variable.render_to_output_buffer(context, +'')
end end
class ParseTreeVisitor < Liquid::ParseTreeVisitor
def children
[@node.variable]
end
end
end end
Template.register_tag('echo', Echo) Template.register_tag('echo', Echo)

View File

@@ -26,6 +26,13 @@ class ParseTreeVisitorTest < Minitest::Test
) )
end end
def test_echo
assert_equal(
["test"],
visit(%({% echo test %}))
)
end
def test_if_condition def test_if_condition
assert_equal( assert_equal(
["test"], ["test"],