mozilla / sphinx-js

Autodoc-style extraction into Sphinx for your JS project
https://pypi.python.org/pypi/sphinx-js/
MIT License
282 stars 81 forks source link

automatic module documentation with js:automodule #177

Open xsjad0 opened 3 years ago

xsjad0 commented 3 years ago

js:automodule - directive

Hey Erik! I have another feature that I want to share with you and others. With this pull request, I'm going to address issue #5 .

JSDoc provides the @module tag that marks the current file as being its own JS module (see JSDoc documentation). With the @module tag, we tell JSDoc that all symbols in the path are assumed to be members of that module. Additionally, you can use the @author, @version and @license tags to display some more information in the module comment. Once we've done this, we can use the js:automodule directive to document the JS module with all its members at once.

Here's an example:

JS module containing some constants, classes and functions

/**
 * For test purpose only.
 *
 * @module  TestModule
 * @author  xsjad0
 * @version 0.1.0
 * @license MIT
 */

/**
 * Class doc.
 */
 class SimpleClass {
    /**
     * Constructor doc.
     */
    constructor() {}

    /**
     * simpleMethod.
     */
    simpleMethod() {}

    /**
     * privateMethod
     * @private
     */
    privateMethod() {}

    /**
     * simpleAttribute.
     */
    simpleAttribute = "attr"
}

/**
 * simpleFunction.
 */
function simpleFunction() {}

/**
 * globalConstant.
 */
const globalConstant = null;

Text to trigger the module documentation

TestModule
==========

.. js:automodule:: TestModule
    :members:

HTML output

image

The js:automodule directive accepts the options :members:, :private-members: and :exclude-members to handle what needs to be documented. These options work on module and on class level. That means that you can control class members as well as module members (maybe there's an even better approach?!)

The additional tags @author, @version and @license can be omitted.

Notes:

Notable changes:

We need to document many classes, namespaces, functions, ... This features safes us a lot of time! I also started to implement an automodules directive, which makes it even possible to document multiple modules at once. But first, I want to read your opinion about this feature. Hope you gonna enjoy it!