|
@@ -1,25 +1,37 @@
|
|
1
|
+import * as _ from 'lodash';
|
1
|
2
|
import * as Handlebars from 'handlebars';
|
2
|
3
|
import * as fs from 'fs';
|
3
|
4
|
import { ClassContext } from './ClassParser';
|
|
5
|
+import { EnumContext } from './EnumParser';
|
4
|
6
|
|
5
|
7
|
export class MarkdownWriter {
|
6
|
8
|
private classFn;
|
|
9
|
+ private enumFn;
|
7
|
10
|
private menuFn;
|
8
|
11
|
constructor(private templatesDir: string, private outputDir: string) {
|
9
|
12
|
this.classFn = this.setupClassHandlebars();
|
|
13
|
+ this.enumFn = this.setupEnumHandlebars();
|
10
|
14
|
this.menuFn = this.setupMenuHandlebars();
|
11
|
15
|
}
|
12
|
16
|
|
13
|
17
|
public writeClasses(classContexts: ClassContext[]) {
|
14
|
18
|
classContexts.forEach((c) => {
|
15
|
|
- const classMarkdown = this.classFn(c);
|
16
|
|
- fs.writeFileSync(`${this.outputDir}/${c.name}.md`, classMarkdown, { encoding: 'utf8' });
|
|
19
|
+ const markdown = this.classFn(c);
|
|
20
|
+ fs.writeFileSync(`${this.outputDir}/${c.name}.md`, markdown, { encoding: 'utf8' });
|
17
|
21
|
});
|
18
|
22
|
}
|
19
|
23
|
|
20
|
|
- public writeMenu(classContexts: ClassContext[]) {
|
|
24
|
+ public writeEnums(enumContexts: EnumContext[]) {
|
|
25
|
+ enumContexts.forEach((c) => {
|
|
26
|
+ const markdown = this.enumFn(c);
|
|
27
|
+ fs.writeFileSync(`${this.outputDir}/${c.name}.md`, markdown, { encoding: 'utf8' });
|
|
28
|
+ });
|
|
29
|
+ }
|
|
30
|
+
|
|
31
|
+ public writeMenu(classContexts: ClassContext[], enumContexts: EnumContext[]) {
|
21
|
32
|
const files = classContexts.map((c) => ({ name: c.name, path: `/api/${c.name}` }));
|
22
|
|
- const menuMarkdown = this.menuFn({ files });
|
|
33
|
+ const files2 = enumContexts.map((c) => ({ name: c.name, path: `/api/${c.name}` }));
|
|
34
|
+ const menuMarkdown = this.menuFn({ files: _.concat(files, files2) });
|
23
|
35
|
fs.writeFileSync(`${this.outputDir}/_sidebar.md`, menuMarkdown, { encoding: 'utf8' });
|
24
|
36
|
fs.writeFileSync(`${this.outputDir}/README.md`, menuMarkdown, { encoding: 'utf8' });
|
25
|
37
|
}
|
|
@@ -36,6 +48,11 @@ export class MarkdownWriter {
|
36
|
48
|
return Handlebars.compile('{{> class}}', { strict: true, noEscape: true });
|
37
|
49
|
}
|
38
|
50
|
|
|
51
|
+ private setupEnumHandlebars() {
|
|
52
|
+ const enumTemplate = fs.readFileSync(`${this.templatesDir}/enum.hbs`).toString();
|
|
53
|
+ return Handlebars.compile(enumTemplate, { strict: true, noEscape: true });
|
|
54
|
+ }
|
|
55
|
+
|
39
|
56
|
private setupMenuHandlebars() {
|
40
|
57
|
const template = fs.readFileSync(`${this.templatesDir}/menu.hbs`).toString();
|
41
|
58
|
return Handlebars.compile(template, { strict: true, noEscape: true });
|