forked from electrode-io/electrode-docgen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-markdown.js
36 lines (30 loc) · 1.11 KB
/
generate-markdown.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
var fs = require('fs');
var handlebars = require('handlebars');
handlebars.registerPartial('component', fs.readFileSync(__dirname + '/templates/component-partial.hbs').toString());
handlebars.registerHelper('defaultProp', function(options) {
var str = options.fn(this);
str = str.replace(/\s+/g,' ');
if (str.length > 50) {
str = str.substring(0, 50) + '...';
}
return str.length > 0 ? '`' + str + '`' : "";
});
handlebars.registerHelper('ternary', function(test, yes, no) {
return test ? yes : no;
});
function _generateDevPortal(comp) {
var templateSource = fs.readFileSync(__dirname + '/templates/dev-portal.hbs');
var template = handlebars.compile(templateSource.toString(), {noEscape: true});
var result = template(comp);
return result;
}
function _generateLibraryDocs(metadata) {
var templateSource = fs.readFileSync(__dirname + '/templates/library-docs.hbs');
var template = handlebars.compile(templateSource.toString(), {noEscape: true});
var result = template(metadata);
return result;
}
module.exports = {
generateLibraryDocs: _generateLibraryDocs,
generateDevPortal: _generateDevPortal
}