customizing
DocumentJS.guides.customizing
Learn how to change the appearance and JavaScript behavior of your generated html documentation.
Learn how to change the appearance and JavaScript behavior of your generated html documentation.
The html generator allows you to completely customize the look and behavior of the site. You can also supply your own generators to build other forms of documentation.
Customizing the default HTML generator
You can customize the templates and helpers used to render a docObject and customize the JavaScript and CSS used by the HTML pages. This behavior is controlled mostly by the siteConfig's
templatesandstaticoptions. However, some tags like @hide allow you to alter the behavior slightly.Changing the HTML
The html generator uses Handlebars templates and helpers to render docObjects. Overwrite the default templates with the siteConfig
templatesoption. If you are producing a multi-versioned site, and you want all versions to have the same template, your website's documentjs.json might look like:The
templatespath should be specified relative to thedocumentjs.jsonfolder.This will use the templates (and helpers) in "theme/templates" to overwrite the default helpers and templates. The default templates can be found in
documentjs/site/default/templates.documentjs/site/default/templateshas the following templates:For example, to make a change to the layout, copy documentjs/site/default/templates/layout.mustache to theme/templates and make changes in your copy.
Adding Helpers
You can add and use your own Handlebars helpers by creating a
.jsfile in your templates directory. For example, you can create theme/templates/helpers.js. Any.jsfile will be required as a module with CommonJS. The module is expect to export a makeHelpers function like:This allows you to write
{{hello-world}}and get back:This behavior is provided by generators.html.build.helpers.
Changing static resources: Styles, Images, and JavaScript
The html generator builds a static distributable that includes the CSS, Images, and JavaScript used by the site. The default content used to build the site can be found within documentjs/site/default/static.
You can overwrite the default static content with the siteConfig
staticoption. If you are producing a multi-versioned site, and you want all versions to have the same static content, your website's documentjs.json might look like:After the default and static content have been combined, the
static/build.jsfile is required with CommonJS and run.static/build.jsis expected to export a builder function that builds the final static content and copies it to a distributable location.The default builder uses StealJS to build a CanJS and LESS application. It copies the minfied
cssandjsbundles as well as all files in the static/fonts, static/img, and static/templates folder to the distributable location.It's likely you don't have to write a custom builder and can instead overwrite the default CSS, Image, and JS files used by the builder.
Changing Styles
documentjs/site/default/static/styles contains the default styles. The styles are broken down functionally:
.brandclass.To change the default styles, copy one of the
lessfiles above to yoursiteConfig.static's styles folder and make changes.Changing Colors
To change colors, copy variables.less and change the color palette options:
Below the color palette definitions, you can see how they are mapped to parts of the application.
Adding other styles
To add another style, create the less or css file in your
siteConfig.static's styles folder. Then, copy styles.less and import your stylesheet:Changing Images
To change the default images, add your replacement images to
siteConfig.static's img folder. You probably want to create a:Changing JavaScript
The default builder loads and builds the documentjs/site/default/static/static.js file using StealJS. This imports various modules and initializes their behavior. StealJS supports importing ES6, AMD, and CJS modules. To add your own behavior:
Add your JavaScript files to the
siteConfig.staticfolder.Copy documentjs/site/default/static/static.js to
siteConfig.staticfolder.Edit your copy of
static.jsto import and initialize your JavaScript code:Writing your own generator
You can create your own generator module which gives you complete control over how a docMap is converted to some output.
If you do decide to create your own generator, the best place to do that is within its own project that is registered on npm. To do that, create a github project with a
main.jsthat exports a generator function like:Publish this to npm. For this example, we'll assume it's published as "doc-map-json".
In a project that wants to use this generator, make sure it's listed as a devDependency in package.json:
In documentjs.json, make sure to list that generator and any options it needs in your siteConfigs.