Skip to content
Lloyd Brookes edited this page Oct 9, 2016 · 2 revisions

You can customise the generated documentation to taste by overriding or adding partials and/or helpers.

For example, let's say you wanted this datestamp at the bottom of your generated docs:

**documentation generated on Sun, 01 Mar 2015 09:30:17 GMT**

You need to do two things:

  1. Write a helper method to return the date in your preferred format
  2. Override the appropriate partial, inserting a mustache tag (e.g. {{datestamp}}) where you would like it to appear. We'll override the main partial.

Write a new helper

A helper file is just a plain commonJS module. Each method exposed on the module will be available as a helper in your templates. So, our new helper module:

exports.generatedDate = function(){
    return new Date().toUTCString();
}

Read more about helpers in the handlebars documentation.

Write a new main partial

Create a duplicate of the main partial (typically in the project you are documenting) containing your new footer:

\{{>main-index~}}
\{{>all-docs~}}

**documentation generated on \{{generatedDate}}**

the file basename of a partial is significant - if you wish to override main (invoked by \{{>main}}) then the filename of your partial must be main.hbs.

Employ

To use the overrides, pass their file names as options to dmd (or jsdoc-to-markdown if you're using that):

$ cat your-parsed-docs.json | dmd --partial custom/main.hbs --helper custom/generatedDate.js

If you have multiple overrides, the syntax is

$ cat your-parsed-docs.json | dmd --partial override1.hbs override2.hbs

Globbing also works:

$ cat your-parsed-docs.json | dmd --partial overrides/*.hbs

Create a plugin

If you wish to version-control and/or share your customisations you can create a plugin for distribution via npm. See dmd-plugin-example as an example and boilerplate to get you started.

Once you have your plugin, install it where required as a dev-dependency. Then supply the plugin package name(s) to the --plugin option, for example:

$ cd my-project
$ npm install dmd-plugin-example --save-dev
$ jsdoc2md lib/my-module.js --plugin dmd-plugin-example
Clone this wiki locally