使用 Doxygen 生成 JavaScript 文档
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7320464/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Generate JavaScript documentation with Doxygen
提问by John Archer
I use PHP and JavaScript in my project, which I entirely code with netbeans 7.0.1. I really like how netbeans includes and uses the JavaDoc commenting style, both for PHP and JS code.
我在我的项目中使用 PHP 和 JavaScript,我完全用 netbeans 7.0.1 编码。我真的很喜欢 netbeans 如何包含和使用 JavaDoc 注释样式,包括 PHP 和 JS 代码。
Now, I want to generate the code documentation from PHP as well as JS code. I know there are several ways doing it, but my main aim is to have the documentation for both parts in onedocumentation.
现在,我想从 PHP 和 JS 代码生成代码文档。我知道有几种方法可以做到这一点,但我的主要目标是在一个文档中包含两个部分的文档。
To explain it further: So e.g., I could use Doxygen and process the PHP files and JsDoc to process the JS files. The result would be, that I now have two different docs in two different folders - a result which I don't like. As I mentioned, I want both in one documentation.
进一步解释一下:例如,我可以使用 Doxygen 并处理 PHP 文件和 JsDoc 来处理 JS 文件。结果是,我现在在两个不同的文件夹中有两个不同的文档——这是我不喜欢的结果。正如我所提到的,我希望在一个文档中同时包含两者。
So, first I went the way via using the doxygen helper js2doxy.pl (http://jsunit.berlios.de/internal.html), but that wasn't flexible enough. It works well with "normal" defined functions, but not with anonymous js functions.
所以,首先我通过使用 doxygen 助手 js2doxy.pl (http://jsunit.berlios.de/internal.html) 走这条路,但这不够灵活。它适用于“普通”定义的函数,但不适用于匿名 js 函数。
After a bit of trying a lot I thought why not alter the FILE_PATTERNS option of document to process .js files, as the JavaDoc style of the comments are nearly identical to the ones used with PHP. And well, the result looks promising, butsome functions are missing in the doc.
经过一番尝试,我想为什么不改变文档的 FILE_PATTERNS 选项来处理 .js 文件,因为注释的 JavaDoc 样式几乎与 PHP 使用的相同。好吧,结果看起来很有希望,但文档中缺少一些功能。
Here are examples:
以下是示例:
/**
* Definitions for the languages.
* @memberof Language
*/
Language.Definitions = (function()
{
...
}
This works very well, I can see the documentation. But:
这很好用,我可以看到文档。但:
**
* Definitions for the languages
* @memberof Language
*/
Language.Definitions = (function()
{
var Translations = {};
/**
* Replaces strings.
* @memberof Language
* @param string translation Translation string
* @param array parameters (optional) List of parameters
*
* @return string replaced string
*/
function replaceStrings(translation, parameters)
{
...
}
In this example I see the docs for Language.Definitions but not for replaceStrings(). Do you have any idea, what I am doing wrong? The same construct is process by JsDoc very well.
在这个例子中,我看到了 Language.Definitions 的文档,但没有看到 replaceStrings() 的文档。你有什么想法,我做错了什么?JsDoc 很好地处理了相同的构造。
Also (part of Language.Definitions) ...
另外(语言.定义的一部分)......
...
return {
/**
* Initialize translations
*
* @memberof Language
*/
initTranslations: function()
{
...
}
...
}
... is not shown in the documentation.
...没有显示在文档中。
I also wouldn't mind if someone would show me how to best merge the two outputs of doxygen and JsDoc into one documentation.
如果有人会告诉我如何最好地将 doxygen 和 JsDoc 的两个输出合并到一个文档中,我也不介意。
Thanks a lot in advance!
非常感谢!
Greetings!
你好!
采纳答案by Wagner Pinheiro
See the special command \fnto explicitly declare the function in the doxygen, preferably in the header of source, like this:
请参阅特殊命令\fn在 doxygen 中明确声明该函数,最好在源头中,如下所示:
/*!
* Language
* Declare the root class
* \Class Language
*/
/*!
* definitions is a property in the Language class
* \property Definitions definitions
*/
/*!
* Document the Definitions static class that used as property in the Language class
* \Class Definitions
*/
/*!
* Replaces strings
* Document the static method for the Definitions class
* \fn string replaceStrings(translation, parameters)
* \memberof Definitions
* \param string translation Translation string
* \param array parameters (optional) List of parameters
* \return string replaced string
*/
Language.definitions = (function()
{
var Translations = {};
function replaceStrings(translation, parameters)
{
...
}