mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Merge pull request #1414 from Shopify/fix/echo-parse-tree-visitor
Add ParseTreeVisitor to Echo tag
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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"],
|
||||||
|
|||||||
Reference in New Issue
Block a user