使用 YARD 记录模型属性
我正在使用 YARD 为我的 Rails 应用程序生成文档,并使用 makrdown 作为脚本解析器。大多数文档功能开箱即用,效果很好。但是,我还想将模型属性记录为一个,记录模型上的可用属性列表,以及两个,以描述它们的语义含义。
我在 YARD 中找不到对此的任何特殊支持,我基本上只能在类注释中简单地列出属性。有没有一种方法可以记录动态生成的模型属性,以便它们像标准属性/方法一样出现在文档中?
PS 我已经使用 annodate-models gem 在类列表的顶部生成基本模式转储,但这并不是我真正想要的。
I'm using YARD to generate docs for my rails app with makrdown as the script parser. Most of the documentation features just work great right out of the box. However, I'd also like to document the model attributes to one, record the list of available attributes on a model and two, to describe their semantic meaning.
I wasn't able to find any special support for this in YARD and I'm basically left with simply listing out the attributes in the class comments. Is there a way to document the dynamically generated model attributes so that they appear in the documentation like standard attributes/methods?
P.S. I've used the annodate-models gem to generate a basic schema dump at the top of the class listing but that's not really what I want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来 YARD 现在有自己的
@!attribute
(注意感叹号)用于此目的标签:http://rubydoc.info/docs/yard/file/docs/Tags.md#attribute
示例:
这将生成很好的属性文档。唯一需要注意的是,您始终保持文档最新,因为当您从数据库等中删除属性时,没有人会检查您是否从文档中删除属性。
It seems that YARD now has its own
@!attribute
(notice the exclamation mark) tag for this purpose:http://rubydoc.info/docs/yard/file/docs/Tags.md#attribute
Example:
This will result in nice documentation of your attributes. The only thing to watch out is that you always keep your documentation up to date because nobody will check whether you remove an attribute from your documentation when you deleted it from the database, etc.
经过一段时间的搜索后,我手动将属性文档添加到模型文件中。这当然不理想,但希望模型结构不会发生太大变化。
我为该项目创建了一个 .yardopts 文件,并使用yard命令行选项创建了两个新标签来标记它们:
这些标签为我提供了用于标记属性和关联的特定标签;它们将显示在文档中的“属性”和“关联”标题下。我可以添加这一点:
也许有人会为 YARD 编写一个插件来解析注释模型输出。
After quite a while searching around, I punted and manually added the documentation for the attributes to the model files. This is certainly not ideal, but hopefully the model structure won't change a whole lot.
I created a .yardopts file for the project and used the yard command-line options to create two new tags for marking these up:
These provide me with specific tags for marking up the attributes and associations; they will show up grouped under the "Attributes" and "Associations" headings in the documentation. I can add this:
Maybe someone will write a plugin for YARD that will parse out the annotate-models output.