-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
30 lines (27 loc) · 803 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const fs = require('fs');
const jade = require('jade')
/*
* Usage:
* var jade = require('diet-jade')({ path: app.path+'/static/jade' })
*
* app.header(jade)
*
* $.render('index') => $.render('index.jade')
*
*/
module.exports = function(options) {
var options = options || {}
return function($) {
$.render = function(filename) {
$.header('Content-Type', 'text/html; charset=UTF-8')
filename ? (filename.indexOf('.jade')>-1 ? (options.file = filename) : (options.file = filename + '.jade')) : ($.error('No jade file specified'))
var path = (options.path.slice(-1) === '/') ? options.path : options.path + '/'
var fn = jade.compileFile(path + options.file, {
pretty: true,
})
var html = fn($.data)
$.end(html)
}
$.return()
}
}