-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·66 lines (54 loc) · 1.97 KB
/
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
var fs = require('fs'),
path = require('path'),
File = require('vinyl'),
vfs = require('vinyl-fs'),
concat = require('concat-stream'),
Handlebars = require('handlebars'),
autolink = require('./lib/autolink'),
formatMarkdown = require('./lib/format_markdown'),
formatParameters = require('./lib/format_parameters');
module.exports = function (comments, options, callback) {
var pageTemplate = Handlebars.compile(fs.readFileSync(path.join(__dirname, 'index.hbs'), 'utf8'));
Handlebars.registerPartial('section',
Handlebars.compile(fs.readFileSync(path.join(__dirname, 'section.hbs'), 'utf8'), {
preventIndent: true
})
);
var paths = comments.map(function (comment) {
return comment.path.join('.');
}).filter(function (path) {
return path;
});
Handlebars.registerHelper('permalink', function () {
return this.path.join('.');
});
Handlebars.registerHelper('autolink', function (text) {
return new Handlebars.SafeString(autolink(paths, text));
});
Handlebars.registerHelper('format_params', formatParameters);
Handlebars.registerHelper('md', function (string) {
return new Handlebars.SafeString(formatMarkdown(string, paths));
});
Handlebars.registerHelper('format_type', function (type) {
return new Handlebars.SafeString(formatMarkdown.type(type, paths));
});
Handlebars.registerHelper('trunk', function (string) {
return string.substr(0, 100) + ' ...';
});
var highlight = require('./lib/highlight')(options.hljs || {});
Handlebars.registerHelper('highlight', function (string) {
return new Handlebars.SafeString(highlight(string));
});
// push assets into the pipeline as well.
vfs.src([__dirname + '/assets/**'], { base: __dirname })
.pipe(concat(function (files) {
callback(null, files.concat(new File({
path: 'index.html',
contents: new Buffer(pageTemplate({
docs: comments,
options: options
}), 'utf8')
})));
}));
};