我正在记录一个NodeJS + Express项目,我希望能够从JavaScript文件中引用特定的更少的视图和Jade模板。例如:
/** Displays the homepage using the {@link views/index} view. Requires {@link stylesheets/news.less} for styling the news section. */
exports.index = function(req, res){
res.render( 'index', { title: 'Welcome' } );
};
除了能够链接到非JS文件之外,我还希望它们与其他内容一起出现在侧边栏中。
我可以在每个.less
/.jade
文件中放入一个头,并告诉JSDoc通过项目的conf.json
解析它们,但是.我不想让JSDoc真正解析它们,因为那样会很混乱。
发布于 2013-07-11 13:08:26
我通过在我的views.jsdoc
目录中创建一个views
文件和在我的stylesheets
目录中创建一个stylesheets.jsdoc
文件来解决这个问题。在.jsdoc
中,我将LESS和JADE文件声明为外部文件,每个文件都有自己的块注释。示例:
views.jsdoc
/**
* The homepage view. Uses the {@link external:views/news} widget to render each news article.
* @external views/index
* @extends external:views/layout
*/
/**
* The news widget.
* @external views/news
*/
/**
* The base layout from which all other views inherit from.
* @external views/layout
*/
发布于 2015-12-31 07:14:52
您可以使用随commentsOnly
附带的内置JSDoc3插件(不过,这会导致行号混乱):
// jsdoc.json
{
"plugins": ["plugins/commentsOnly"]
}
然后是jsdoc src -d docs -R README.md -c jsdoc.json
您也可以编写自己的插件,做同样的事情,但保留换行符:
// jsdocPlugin.js
var commentPattern = /\/\*\*[\s\S]+?\*\//g,
notNewLinePattern = /[^\n]/g,
extname = require('path').extname,
extension = '.js',
comments;
exports.handlers = {
beforeParse: function (e) {
if (extension === extname(e.filename)) {
comments = e.source.match(commentPattern);
e.source = comments ? e.source.split(commentPattern).reduce(function(result, source, i) {
return result + source.replace(notNewLinePattern, '') + comments[i];
}, '') : e.source.replace(notNewLinePattern, '');
}
}
};
// jsdoc.json
{
"plugins": ["jsdocPlugin.js"]
}
然后是jsdoc src -d docs -R README.md -c jsdoc.json
我为JSDoc编写了一个小包装器,这样就可以在Node.js - 文档中以编程方式使用。
https://stackoverflow.com/questions/17603367
复制