API

This page will go over using DocPad as a module, and the API available to you.

Technical API

DocPad has auto-generated Technical API from its source code, check it out!

Install DocPad

Besides having Node.js installed, you'll want to install DocPad locally to your project, you can do this by running npm install --save docpad in your command line. This will install DocPad into ./node_modules/docpad and make it accessible via Node.js's require function (e.g., require('docpad'))

If you are wanting to utilise DocPad for rendering, you'll also want to install some rendering Plugins.

Create your DocPad Instance

Firstly, you need to create your DocPad instance, you can do this like so:

var docpadInstanceConfiguration = {};
require('docpad').createInstance(docpadInstanceConfiguration, function(err,docpadInstance){
    if (err)  return console.log(err.stack);
    // ...
});

Rendering individual files

You can use DocPad as a module to render individual files very easily. This allows you to utilise DocPad for all the rendering inside your application, instead of having to write and maintain specific wrappers for each rendering engine yourself.

Render some text with DocPad

Render a file path with DocPad

DocPad CLI Actions

Here is how you would normalise common tasks you would typically achieve with the DocPad command line interface.

Performing a generation

Start the DocPad server

Generate and Start the DocPad Server

You can combine actions by separating them with a space, like so:

Perform an initial generation, then watch files and regenerate when a change occurs

Using the Database

DocPad using Backbone.js for its Models, and QueryEngine for its Collections. Providing a powerful database that you can query in a noSQL type fashion.

Get the database

Create a Document and File

Create a Document and File, then add it to the Database

Parse a Document and File Directory

Querying

For more information about Querying, check out this FAQ Entry.

Using with Express

If you already have an Express.js application, you can do the following to just stick DocPad straight ontop of it:

Here is some code for manually rendering a document (inside src/render) with a custom route:

Last updated

Was this helpful?