Implement nodelist in the Doc tag so it may be visited

This commit is contained in:
Guilherme Carreiro
2025-02-26 12:05:13 +01:00
parent a398b4cc74
commit 71e5d21c5f
3 changed files with 28 additions and 1 deletions
+4
View File
@@ -55,6 +55,10 @@ module Liquid
true
end
def nodelist
[]
end
private
def ensure_valid_markup(tag_name, markup, parse_context)
+1 -1
View File
@@ -2,5 +2,5 @@
# frozen_string_literal: true
module Liquid
VERSION = "5.8.0"
VERSION = "5.8.1"
end
+23
View File
@@ -49,6 +49,7 @@ class BlockUnitTest < Minitest::Test
def test_comment_tag_with_block
template = Liquid::Template.parse(" {% comment %} {% endcomment %} ")
assert_equal([String, Comment, String], block_types(template.root.nodelist))
assert_equal(3, template.root.nodelist.size)
end
@@ -59,9 +60,31 @@ class BlockUnitTest < Minitest::Test
assert_equal(3, template.root.nodelist.size)
end
def test_doc_tag_visitor
template_source = '{% doc %}{% enddoc %}'
assert_equal(
[Liquid::Doc],
visit(template_source),
)
end
private
def block_types(nodelist)
nodelist.collect(&:class)
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