Fork me on GitHub

API Documentation

This page details how to render jade using the JavaScript API in node.js

Installation

via npm:

$ npm install jade

Usage

options

All API methods take the following set of options:

{
filename:
string
Used in exceptions, and required for relative includes and extends
pretty:
boolean
Adds whitespace to the resulting html to make it easier for a human to read
self:
boolean
Use a `self` namespace to hold the locals _(false by default)_
debug:
boolean
If set to true, the tokens and function body is logged to stdout
compileDebug:
boolean
Set this to false to disable debugging instrumentation (recommended in production). Set it to true to include the function source in the compiled template for better error messages (sometimes useful in development).
compiler:
class
Override the default compiler
globals:
array
Add a list of globals (as string names) to make accessible in templates
}

jade.compile(source, options)

Compile some jade source to a function which can be rendered multiple times with different locals.

source
string
The source jade to compile
options
options
An options object (see above)
returns
function
A function to generate the html from an object containing locals
var jade = require('jade');

// Compile a function
var fn = jade.compile('string of jade', options);

// Render the function
var html = fn(locals);
// => '<string>of jade</string>'

jade.render(source, options, callback)

Render some jade source to HTML with given options and locals.

source
string
The source jade to render
options
options
An options object (see above), also used as the locals object
callback
function
Node style callback function which is passed error and result as its arguments
var jade = require('jade');

jade.render('string of jade', options, function (err, html) {
  if (err) throw err;
  // html => '<string>of jade</string>'
});

or

source
string
The source jade to render
options
options
An options object (see above), also used as the locals object
returns
string
The resulting html string
var jade = require('jade');

var html = jade.render('string of jade', options);
// => '<string>of jade</string>'

jade.renderFile(filename, options, callback)

Render a jade file to HTML with given options and locals.

filename
string
The path to the jade file to render
options
options
An options object (see above), also used as the locals object
callback
function
Node style callback function which is passed error and result as its arguments
var jade = require('jade');

jade.renderFile('path/to/file.jade', options, function (err, html) {
  if (err) throw err;
  // ...
});

or

filename
string
The path to the jade file to render
options
options
An options object (see above), also used as the locals object
returns
string
The resulting html string
var jade = require('jade');

var html = jade.renderFile('path/to/file.jade', options);
// ...