__express = function (path, options, fn) {
if(options.compileDebug == undefined && process.env.NODE_ENV === 'production') {
options.compileDebug = false;
}
exports.renderFile(path, options, fn);
}n/a
compile = function (str, options){
var options = options || {}
str = String(str);
var parsed = compileBody(str, {
compileDebug: options.compileDebug !== false,
filename: options.filename,
basedir: options.basedir,
pretty: options.pretty,
doctype: options.doctype,
inlineRuntimeFunctions: options.inlineRuntimeFunctions,
globals: options.globals,
self: options.self,
includeSources: options.compileDebug === true,
debug: options.debug,
templateName: 'template'
});
var res = options.inlineRuntimeFunctions
? new Function('', parsed.body + ';return template;')()
: runtimeWrap(parsed.body);
res.dependencies = parsed.dependencies;
return res;
}...
For full API, see [jade-lang.com/api](http://jade-lang.com/api/)
```js
var jade = require('jade');
// compile
var fn = jade.compile('string of jade', options);
var html = fn(locals);
// render
var html = jade.render('string of jade', merge(options, locals));
// renderFile
var html = jade.renderFile('filename.jade', merge(options, locals));
...compileClient = function (str, options) {
return exports.compileClientWithDependenciesTracked(str, options).body;
}n/a
compileClientWithDependenciesTracked = function (str, options){
var options = options || {};
str = String(str);
var parsed = compileBody(str, {
compileDebug: options.compileDebug,
filename: options.filename,
basedir: options.basedir,
pretty: options.pretty,
doctype: options.doctype,
inlineRuntimeFunctions: options.inlineRuntimeFunctions !== false,
globals: options.globals,
self: options.self,
includeSources: options.compileDebug,
debug: options.debug,
templateName: options.name || 'template'
});
return {body: parsed.body, dependencies: parsed.dependencies};
}n/a
compileFile = function (path, options) {
options = options || {};
options.filename = path;
return handleTemplateCache(options);
}n/a
compileFileClient = function (path, options){
var key = path + ':client';
options = options || {};
options.filename = path;
if (options.cache && exports.cache[key]) {
return exports.cache[key];
}
var str = fs.readFileSync(options.filename, 'utf8');
var out = exports.compileClient(str, options);
if (options.cache) exports.cache[key] = out;
return out;
}n/a
render = function (str, options, fn){
// support callback API
if ('function' == typeof options) {
fn = options, options = undefined;
}
if (typeof fn === 'function') {
var res
try {
res = exports.render(str, options);
} catch (ex) {
return fn(ex);
}
return fn(null, res);
}
options = options || {};
// cache requires .filename
if (options.cache && !options.filename) {
throw new Error('the "filename" option is required for caching');
}
return handleTemplateCache(options, str)(options);
}...
var jade = require('jade');
// compile
var fn = jade.compile('string of jade', options);
var html = fn(locals);
// render
var html = jade.render('string of jade', merge(options, locals));
// renderFile
var html = jade.renderFile('filename.jade', merge(options, locals));
```
### Options
...renderFile = function (path, options, fn){
// support callback API
if ('function' == typeof options) {
fn = options, options = undefined;
}
if (typeof fn === 'function') {
var res
try {
res = exports.renderFile(path, options);
} catch (ex) {
return fn(ex);
}
return fn(null, res);
}
options = options || {};
options.filename = path;
return handleTemplateCache(options)(options);
}...
var fn = jade.compile('string of jade', options);
var html = fn(locals);
// render
var html = jade.render('string of jade', merge(options, locals));
// renderFile
var html = jade.renderFile('filename.jade', merge(options, locals));
```
### Options
- `filename` Used in exceptions, and required when using includes
- `compileDebug` When `false` no debug instrumentation is compiled
- `pretty` Add pretty-indentation whitespace to output _(false by default)_
...function jade_attr(key, val, escaped, terse) {
if (val === false || val == null || !val && (key === 'class' || key === 'style')) {
return '';
}
if (val === true) {
return ' ' + (terse ? key : key + '="' + key + '"');
}
if (typeof val.toISOString === 'function') {
val = val.toISOString();
} else if (typeof val !== 'string') {
val = JSON.stringify(val);
if (!escaped && val.indexOf('"') !== -1) {
return ' ' + key + '=\'' + val.replace(/'/g, ''') + '\'';
}
}
if (escaped) val = jade_escape(val);
return ' ' + key + '="' + val + '"';
}n/a
function jade_attrs(obj, terse){
var attrs = '';
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; ++i) {
var key = keys[i]
, val = obj[key];
if ('class' === key) {
val = jade_classes(val);
attrs = jade_attr(key, val, false, terse) + attrs;
continue;
}
if ('style' === key) {
val = jade_style(val);
}
attrs += jade_attr(key, val, false, terse);
}
return attrs;
}n/a
function jade_classes(val, escaping) {
if (Array.isArray(val)) {
return jade_classes_array(val, escaping);
} else if (val && typeof val === 'object') {
return jade_classes_object(val);
} else {
return val || '';
}
}n/a
function jade_escape(_html){
var html = '' + _html;
var regexResult = jade_match_html.exec(html);
if (!regexResult) return _html;
var result = '';
var i, lastIndex, escape;
for (i = regexResult.index, lastIndex = 0; i < html.length; i++) {
switch (html.charCodeAt(i)) {
case 34: escape = '"'; break;
case 38: escape = '&'; break;
case 60: escape = '<'; break;
case 62: escape = '>'; break;
default: continue;
}
if (lastIndex !== i) result += html.substring(lastIndex, i);
lastIndex = i + 1;
result += escape;
}
if (lastIndex !== i) return result + html.substring(lastIndex, i);
else return result;
}n/a
function jade_merge(a, b) {
if (arguments.length === 1) {
var attrs = a[0];
for (var i = 1; i < a.length; i++) {
attrs = jade_merge(attrs, a[i]);
}
return attrs;
}
for (var key in b) {
if (key === 'class') {
var valA = a[key] || [];
a[key] = (Array.isArray(valA) ? valA : [valA]).concat(b[key] || []);
} else if (key === 'style') {
var valA = jade_style(a[key]);
var valB = jade_style(b[key]);
a[key] = valA + (valA && valB && ';') + valB;
} else {
a[key] = b[key];
}
}
return a;
}n/a
function jade_rethrow(err, filename, lineno, str){
if (!(err instanceof Error)) throw err;
if ((typeof window != 'undefined' || !filename) && !str) {
err.message += ' on line ' + lineno;
throw err;
}
try {
str = str || require('fs').readFileSync(filename, 'utf8')
} catch (ex) {
jade_rethrow(err, null, lineno)
}
var context = 3
, lines = str.split('\n')
, start = Math.max(lineno - context, 0)
, end = Math.min(lines.length, lineno + context);
// Error context
var context = lines.slice(start, end).map(function(line, i){
var curr = i + start + 1;
return (curr == lineno ? ' > ' : ' ')
+ curr
+ '| '
+ line;
}).join('\n');
// Alter exception message
err.path = filename;
err.message = (filename || 'Jade') + ':' + lineno
+ '\n' + context + '\n\n' + err.message;
throw err;
}n/a
function jade_style(val) {
if (!val) return '';
if (typeof val === 'object') {
var out = '', delim = '';
for (var style in val) {
/* istanbul ignore else */
if (jade_has_own_property.call(val, style)) {
out = out + delim + style + ':' + val[style];
delim = ';';
}
}
return out;
} else {
val = '' + val;
if (val[val.length - 1] === ';') return val.slice(0, -1);
return val;
}
}n/a