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
doctype:
string
If the doctype is not specified as part of the template, you can specify it here. It is sometimes useful to get self-closing tags and remove mirroring of boolean attributes.
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
}

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.compileFile(path, options)

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

source
path
The path to a jade file
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.compileFile('path to jade file', options);

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

jade.compileClient(source, options)

Compile some jade source to a string of JavaScript that can be used client side along with the jade runtime.

source
string
The source jade to compile
options
options
An options object (see above)
returns
string
A string of JavaScript representing a function
var jade = require('jade');

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

// Render the function
var html = fn(locals);
// => 'function template(locals) { return "<string>of jade</string>"; }'

jade.render(source, options)

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)

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);
// ...