7

我正在将我维护的 ruby​​gem 从 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 的标记中做类似事情的语法是什么(如果存在)?

4

3 回答 3

4

好吧,以最简单、快速和肮脏的形式,解决方案很简单——只需使用任何自定义(院子未知)标签名称。例如:

##
# SomeClass documentation here.
#
# @internal_note 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

这里唯一的问题是 yard 会警告您每次出现@internal_note:

[warn]: Unknown tag @internal_note in file ... near line xxx
[warn]: Unknown tag @internal_note in file ... near line yyy
...

我真的认为应该有官方的方法来压制不良警告,但不幸的是我找不到它。不过,您可以尝试以下方法之一:

  1. yardoc -q# 问题:也会抑制有用的信息
  2. 您可以创建文件yardinit.rb,其内容如下:

    YARD::Tags::Library.define_tag('INTERNAL NOTE', :internal_note)
    

    然后生成文档

    yardoc -e './yardinit.rb'
    
  3. 有一个 yard 插件可以抑制所有未知标签警告https://github.com/rubyworks/yard-shutup

    它看起来不是很活泼,gem install yard-shutup也不起作用,但是您可以手动安装并尝试一下

于 2012-01-15T22:35:40.697 回答
4

你可以写

# @comment TODO: This will not be seen
def method(*args)
  ...
end

并在命令行上运行(或将其放入您的.yardopts

$ yard doc --tag comment --hide-tag comment
于 2012-05-20T18:13:56.293 回答
1

您可以使用标识隐藏或转换为庭院评论中的“评论”:

示例 1:

# Show Text1
# Show Text2
# Show Text3

结果:

Show Text1
Show Text2
Show Text3

示例 2:

# Show Text1
  # Show Text2
  # Show Text3

结果:

Show Text2
Show Text3

示例 3:

  # Show Text1
# Show Text2
# Show Text3

结果:

Show Text2
Show Text3

示例 4:

  # Show Text1
# Show Text2
  # Show Text3

结果:

Show Text3

示例 5:

# Show Text2
  # Show Text1
# Show Text3

结果:

Show Text3

示例 6:

  # Show Text1
#
  # Show Text3

结果:

Show Text3

示例 7:

# Show Text2
  #
# Show Text3

结果:

Show Text3
于 2015-05-28T23:21:14.477 回答