Remove body attr_reader and initiliaze @body instance variable in parse method

This commit is contained in:
James Meng
2025-06-06 13:08:06 -07:00
parent 79a771d724
commit 8548b96a97
2 changed files with 6 additions and 7 deletions
+3 -4
View File
@@ -30,15 +30,14 @@ module Liquid
class Doc < Block
NO_UNEXPECTED_ARGS = /\A\s*\z/
attr_reader :body
def initialize(tag_name, markup, parse_context)
super
@body = +""
ensure_valid_markup(tag_name, markup, parse_context)
end
def parse(tokens)
@body = +""
while (token = tokens.shift)
tag_name = token =~ BlockBody::FullTokenPossiblyInvalid && Regexp.last_match(2)
@@ -64,7 +63,7 @@ module Liquid
end
def nodelist
[]
[@body]
end
private
+3 -3
View File
@@ -32,7 +32,7 @@ class DocTagUnitTest < Minitest::Test
end
.visit
assert_equal(doc_content, doc_tag.body)
assert_equal(doc_content, doc_tag.nodelist.first.to_s)
end
def test_doc_tag_does_not_support_extra_arguments
@@ -132,7 +132,7 @@ class DocTagUnitTest < Minitest::Test
end
def test_doc_tag_captures_token_before_enddoc
template_source = "{% doc %}{{ incomplete{% enddoc %}"
template_source = "{% doc %}{{ incomplete{% enddoc %}"
doc_tag = nil
ParseTreeVisitor
@@ -142,7 +142,7 @@ class DocTagUnitTest < Minitest::Test
end
.visit
assert_equal("{{ incomplete", doc_tag.body)
assert_equal("{{ incomplete", doc_tag.nodelist.first.to_s)
end
def test_doc_tag_preserves_error_line_numbers