Implement nodelist in the Doc tag so it may be visited

This commit is contained in:
Guilherme Carreiro
2025-02-26 13:14:39 +01:00
committed by Guilherme Carreiro
parent a398b4cc74
commit 6453a0ea48
4 changed files with 33 additions and 1 deletions
+4
View File
@@ -2,6 +2,10 @@
## 5.8.1 (unreleased) ## 5.8.1 (unreleased)
## 5.8.1
* Fix `{% doc %}` tag to be visitable [Guilherme Carreiro]
## 5.8.0 ## 5.8.0
* Introduce the new `{% doc %}` tag [Guilherme Carreiro] * Introduce the new `{% doc %}` tag [Guilherme Carreiro]
+4
View File
@@ -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)
+1 -1
View File
@@ -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
+24
View File
@@ -157,4 +157,28 @@ class DocTagUnitTest < Minitest::Test
assert_template_result('', "{% doc %}123{% enddoc\nxyz %}") assert_template_result('', "{% doc %}123{% enddoc\nxyz %}")
assert_template_result('', "{% doc %}123{% enddoc\n xyz enddoc %}") assert_template_result('', "{% doc %}123{% enddoc\n xyz enddoc %}")
end end
def test_doc_tag_visitor
template_source = '{% doc %}{% enddoc %}'
assert_equal(
[Liquid::Doc],
visit(template_source),
)
end
private
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