Javascript 如何向JSDoc添加标记?
我使用的Meteor与普通JavaScript相比有一些奇怪的警告。我想添加一些标记,以便使文档更加明确Javascript 如何向JSDoc添加标记?,javascript,documentation,documentation-generation,jsdoc3,Javascript,Documentation,Documentation Generation,Jsdoc3,我使用的Meteor与普通JavaScript相比有一些奇怪的警告。我想添加一些标记,以便使文档更加明确 Meteor.methods({ /** * Upgrade a user's role * * @where Anywhere * @rolerequired 'admin' * * @module Meteor.methods * @method Roles.upgrade * @param {String|Object} user the userI
Meteor.methods({
/**
* Upgrade a user's role
*
* @where Anywhere
* @rolerequired 'admin'
*
* @module Meteor.methods
* @method Roles.upgrade
* @param {String|Object} user the userId or the user document to update
* @param {String} role the role to add the user to
* @throws Meteor.Error 401 if the user trying to upgrade was not authorized to do so
*
* @example
* Meteor.call('Roles.upgrade', Meteor.users.findOne(), function (err) {
if (!err) {
console.log('User successfully added to role');
} else {
Router.error(401);
}
})
*/
'Roles.upgrade': function (user, role) {
if (Roles.userIsInRole(this.userId, 'admin')) {
return Roles.addUserToRoles(user, role);
} else {
throw new Meteor.Error(401, "Not authorized to upgrade roles")
}
}
});
所需的@where
和@rolererequired
更特定于此基于Meteor的应用程序。@其中
可以在类似devdocs.io的内容中看到
如何向JSDoc添加标记?是的,可以向JSDoc添加自定义标记。您需要创建一个javascript文件来定义要添加的标记:
自定义标签.js
:
exports.defineTags = function(dictionary) {
dictionary.defineTag('where', {
mustHaveValue: true,
onTagged : function(doclet, tag) {
doclet.where = doclet.where || [];
doclet.where.push(tag.value);
}
});
};
然后,您需要将该javascript文件的位置添加到conf.json中,该conf.json将您的插件作为路径的一部分列出
conf.json
:
{
"plugins": [
"plugins/test"
],
}
最后,您需要为默认模板更新一个.tmpl文件,以便在生成的文档中呈现您的信息。或者,您可以创建自己的模板并定义自己的解析,以将标记添加到生成的文档中