Home

Awesome

License: MIT npm package Build Status

kis-jsdoc-plugin

A JSDoc plugin associated with a custom template that generates markdown documentation in a 'Keep It Simple' way.

Description

Requirements

This plugin is written in EcmaScript 2015 so a version of node.js > to 6.4 is required. It has been developed and tested with the 3.5.5 release of JSDoc.

Installation

Install kis-jsdoc-plugin within you project:

npm install --save-dev kis-jsdoc-plugin

Create or modify your .jsdoc.json config file to reference the kis-jsdoc-plugin plugin and the markdown custom template:

{
  "tags": {
    "allowUnknownTags": true
  },
  "source": {
    "include": ["./src"] /* the path to your documented source code */
  },
  "opts": {
    "template": "node_modules/kis-jsdoc-plugin/templates/markdown",
    "encoding": "utf8",
    "destination": "./doc/", /* the path to the generated documentation */
    "recurse": true
  },
  "plugins": ["node_modules/kis-jsdoc-plugin"],
  "templates": {
    "markdown": {
      "tocfilename": "toc.md" /* the name of the table of contents file */
    }
  }
}

Running

Run JSDoc:

jsdoc -c ./.jsdoc.json

Coding coventions

/**
 * Defines my EcmaScript2015 class.
 */
export class MyClass {

  /** @member {string} - The private member. */
  _bar;
  /** @member {string} - The public member. */
  foo;

  /**
   * The public method.
   */
  foobar() {
  }
}
/**
 * Defines a JavaScript module.
 * @module
 */

/**
 * Defines a private function.
 */
function bar() {
}

/**
 * Defines a public function.
 * @param {number} x - The x parameter.
 */
exports.foo = x => ...;

Automatic links to class documentation

If all you EcmaScript classes have unique names and if you use the class name as parameters of your @param, @return, @see tags or {@link} inline tag, a markdown link to the corresponding class documentation will be created.

/**
 * Defines a new class using {@link MyClass}.
 * @see MyClass
 */
export class AnotherClass {

/**
 * Defines a public method.
 * @param {MyClass} myClass - The instance of the class.
 */
bar(myClass) {

You can also add external links to classes in the configuration file like this:

{
  "templates": {
      "externallinks": {
        "HttpClient": "https://aurelia.io/docs/api/fetch-client/class/HttpClient",
        "Router": "https://aurelia.io/docs/api/router/class/AppRouter",
        "Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise"
      }
   }
 }

The following comment in your code:

  /**
   * Creates an instance of the SettingsService with the specified parameters.
   * @param {HttpClient} client - the fetch http client
   */
  constructor(client) {

will generate this:

Creates an instance of the SettingsService with the specified parameters.

ParametersTypeDescription
clientHttpClientthe fetch http client

Exclude private code

You can opt out the generation of private members or functions with the following configuration:

{
  "opts": {
    "includes": "public"  /* default is "public,protected,private" */
  },

Modifiers badges

The modifiers like public, private, protected, static, abstract are represented by an svg badge. You can opt out for a png file in case svg does not fit your need. Use this configuration:

{
  "templates": {
    "markdown": {
      "imageext": "png"  /* default is "svg" */

Category

This plugin register a new @category JSDoc tag. It will be used to generate the table of contents. You can add whatever category you want.

/**
 * Implements the user settings.
 * @category Model
 */
export class UserSettings {

You can modify the order of the categories in the table of contents with the following configuration:

{
  "templates": {
    "markdown": {
      "tocOrder": {
        "model": 1,
        "viewmodel": 2
      }

A badge will be generated for the category and you can define the color with the following configuration:

{
  "templates": {
    "markdown": {
      "badgecolors": {
        "model": "009663",
        "viewmodel": "00A800"
      }

Table of contents

A table of contents documentation is generated in a separated file. You can change the name in the configuration file:

{
  "templates": {
    "markdown": {
      "tocfilename": "toc.md"
    }

Screenshots

For a module or class, you can add a png image to the {your_doc_folder}/images/screenshots folder with the same name as the original source file and the image will be added to the corresponding documentation markdown file.

Customization

You can provide your own handlebars templates for the markdown generation by specifying the folder in the configuration file:

{
  "opts": {
    "template": "{your_template_folder}",  /* the default is node_modules/kis-jsdoc-plugin/templates/markdown */

You need to provide two handlebars files :

You can also provide handlebars partials in the partials subfolder and they will be precompiled and registered by their filenames.

Note that the doclet object model for each documented javascript has the following hierarchy:

Project documentation

The project documentantion has been self generated by this plugin and the table of contents is available here: Table of contents

Known issues & limitations

Only the following JSDoc tags are currently used in markdown templates: @augments, @class, @constant, @example, @member, @module, @param, @private, @public, @return, @see, @static, @type.