mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 19:00:39 -07:00
Expose tag body in the Doc tag
This commit is contained in:
@@ -30,8 +30,11 @@ module Liquid
|
|||||||
class Doc < Block
|
class Doc < Block
|
||||||
NO_UNEXPECTED_ARGS = /\A\s*\z/
|
NO_UNEXPECTED_ARGS = /\A\s*\z/
|
||||||
|
|
||||||
|
attr_reader :body
|
||||||
|
|
||||||
def initialize(tag_name, markup, parse_context)
|
def initialize(tag_name, markup, parse_context)
|
||||||
super
|
super
|
||||||
|
@body = +""
|
||||||
ensure_valid_markup(tag_name, markup, parse_context)
|
ensure_valid_markup(tag_name, markup, parse_context)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -43,8 +46,10 @@ module Liquid
|
|||||||
|
|
||||||
if tag_name == block_delimiter
|
if tag_name == block_delimiter
|
||||||
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
|
parse_context.trim_whitespace = (token[-3] == WhitespaceControl)
|
||||||
|
@body << Regexp.last_match(1) if Regexp.last_match(1) != ""
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@body << token unless token.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
raise_tag_never_closed(block_name)
|
raise_tag_never_closed(block_name)
|
||||||
|
|||||||
@@ -20,6 +20,21 @@ class DocTagUnitTest < Minitest::Test
|
|||||||
assert_template_result('', template)
|
assert_template_result('', template)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_doc_tag_body_content
|
||||||
|
doc_content = " Documentation content\n @param {string} foo - test\n"
|
||||||
|
template_source = "{% doc %}#{doc_content}{% enddoc %}"
|
||||||
|
|
||||||
|
doc_tag = nil
|
||||||
|
ParseTreeVisitor
|
||||||
|
.for(Template.parse(template_source).root)
|
||||||
|
.add_callback_for(Liquid::Doc) do |tag|
|
||||||
|
doc_tag = tag
|
||||||
|
end
|
||||||
|
.visit
|
||||||
|
|
||||||
|
assert_equal(doc_content, doc_tag.body)
|
||||||
|
end
|
||||||
|
|
||||||
def test_doc_tag_does_not_support_extra_arguments
|
def test_doc_tag_does_not_support_extra_arguments
|
||||||
error = assert_raises(Liquid::SyntaxError) do
|
error = assert_raises(Liquid::SyntaxError) do
|
||||||
template = <<~LIQUID.chomp
|
template = <<~LIQUID.chomp
|
||||||
|
|||||||
Reference in New Issue
Block a user