javascript - 如何给JSDoc添加标签?

标签 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 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@rolerequired 更具体地针对这个基于 Meteor 的应用程序。 @where 可以在 devdocs.io 之类的地方看到。

如何给JSDoc添加标签?

最佳答案

是的,可以向 JSDoc 添加自定义标签。您需要创建一个 javascript 文件来定义要添加的标签:

custom_tags.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:

{
  "plugins": [
    "plugins/test"
  ],
}

最后,您需要更新默认模板的 .tmpl 文件,以便在生成的文档中呈现您的信息。或者,您可以创建自己的模板并定义自己的解析,以将标签添加到生成的文档中。

关于javascript - 如何给JSDoc添加标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31653799/

相关文章:

configuration - 我可以使用 DoxyGen 来记录 ActionScript 代码吗?

matlab - 如何记录面向对象的 MATLAB 代码?

c# - SandcaSTLe 没有记录属性摘要

documentation-generation - 使用RestructuredText和Sphinx包含预格式化的文件

java - 如何维护基于 JSON 的领域特定语言的文档?

javascript - 带参数的jQuery淡入淡出函数

javascript - 如何在向下滚动时向顶部添加 20px

javascript - 表单提交后关闭 Bootstrap Modal - Rails

javascript - Nodejs 和 javascript 用户代理行为

mysql - Excel 文件架构