使用 YARD 进行 Ruby 文档的内部评论?
我正在将我维护的 rubygem 从 RDoc 切换到 YARD 文档。但是,代码中有一些关键注释只需要保留在代码中,而不应该出现在文档中。例如:
##
# SomeClass documentation here.
#--
# CRITICAL comment that should be in the code but not in the documentation,
# and must be at this particular spot in the code.
#++
# more documentation that follows the critical comment block, but this part
# should be in the generated documentation
class SomeClass
...
end
RDoc 支持 #--
和 #++
门,但 YARD 不支持。在 YARD 标记中执行类似操作的语法(如果存在)是什么?
I'm in the process of switching over a rubygem I maintain from RDoc to YARD documentation. However, there are some critical comments in the code that need to remain only in the code and should not show up in the documentation. For instance:
##
# SomeClass documentation here.
#--
# CRITICAL comment that should be in the code but not in the documentation,
# and must be at this particular spot in the code.
#++
# more documentation that follows the critical comment block, but this part
# should be in the generated documentation
class SomeClass
...
end
RDoc honors the #--
and #++
gates, but YARD does not. What (if it exists) is the syntax for doing an analogous thing in YARD's markup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,以最简单、快速和肮脏的形式,解决方案很容易 -
只需使用任何自定义(码未知)标签名称。例如:
这里唯一的问题是yard会警告您每次出现@internal_note:
我真的认为应该有官方方法来抑制不需要的警告,但不幸的是我找不到它。不过,您可以尝试以下操作之一:
yardoc -q
# Problem: will subpurged有用的信息您可以创建文件
yardinit.rb
,其中包含以下内容:然后生成文档
生成文档
有一个yard插件可以抑制所有未知标签警告https://github.com/rubyworks/yard-shutup
它看起来不太活跃,
gem installyard-shutup
不起作用,但你可以手动安装它并尝试一下Well, in its simplest, quick and dirty form, solution is easy -
just use any custom (unknown to yard) tag name. For example:
The only issue here is that yard will warn you about each occurrence of @internal_note:
I really think there should be official way to suppress the undesirable warnings, but unfortunately I couldn't find it. Nevertheless, you may try one of the following:
yardoc -q
# problem: will suppress useful info tooyou may create file
yardinit.rb
, with the following content:and then generate docs with
there is a yard plugin to suppress all unknown tag warning https://github.com/rubyworks/yard-shutup
it doesn't look very alive, and
gem install yard-shutup
doesn't work, but you may install it by hand and give it a try您可以编写
并在命令行上运行(或将其放入您的
.yardopts
中)You can write
And run on the command line (or put it into your
.yardopts
)您可以使用标识在码注释中隐藏或转换为“注释”:
示例 1:
结果:
示例 2:
结果:
示例 3:
结果:
示例 4:
结果:
示例 5:
结果:
示例 6:
结果:
示例 7:
结果:
You can use identation to hide or convert to "comment" in yard comment:
Example 1:
Result:
Example 2:
Result:
Example 3:
Result:
Example 4:
Result:
Example 5:
Result:
Example 6:
Result:
Example 7:
Result: