mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-04 01:25:14 -07:00
Implement nodelist in the Doc tag so it may be visited
This commit is contained in:
@@ -55,6 +55,10 @@ module Liquid
|
|||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def nodelist
|
||||||
|
[]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def ensure_valid_markup(tag_name, markup, parse_context)
|
def ensure_valid_markup(tag_name, markup, parse_context)
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module Liquid
|
module Liquid
|
||||||
VERSION = "5.8.0"
|
VERSION = "5.8.1"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ class BlockUnitTest < Minitest::Test
|
|||||||
|
|
||||||
def test_comment_tag_with_block
|
def test_comment_tag_with_block
|
||||||
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
|
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
|
||||||
|
|
||||||
assert_equal([String, Comment, String], block_types(template.root.nodelist))
|
assert_equal([String, Comment, String], block_types(template.root.nodelist))
|
||||||
assert_equal(3, template.root.nodelist.size)
|
assert_equal(3, template.root.nodelist.size)
|
||||||
end
|
end
|
||||||
@@ -59,9 +60,31 @@ class BlockUnitTest < Minitest::Test
|
|||||||
assert_equal(3, template.root.nodelist.size)
|
assert_equal(3, template.root.nodelist.size)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_doc_tag_visitor
|
||||||
|
template_source = '{% doc %}{% enddoc %}'
|
||||||
|
|
||||||
|
assert_equal(
|
||||||
|
[Liquid::Doc],
|
||||||
|
visit(template_source),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def block_types(nodelist)
|
def block_types(nodelist)
|
||||||
nodelist.collect(&:class)
|
nodelist.collect(&:class)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def traversal(template)
|
||||||
|
ParseTreeVisitor
|
||||||
|
.for(Template.parse(template).root)
|
||||||
|
.add_callback_for(Liquid::Doc) do |tag|
|
||||||
|
tag_class = tag.class
|
||||||
|
tag_class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def visit(template)
|
||||||
|
traversal(template).visit.flatten.compact
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user