/
DefaultThemeRenderContext.ts
87 lines (77 loc) · 3.51 KB
/
DefaultThemeRenderContext.ts
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import type * as ts from "typescript";
import type { RendererHooks } from "../..";
import type { Reflection } from "../../../models";
import type { Options } from "../../../utils";
import type { DefaultTheme } from "./DefaultTheme";
import { defaultLayout } from "./layouts/default";
import { index } from "./partials";
import { analytics } from "./partials/analytics";
import { breadcrumb } from "./partials/breadcrumb";
import { comment } from "./partials/comment";
import { footer } from "./partials/footer";
import { header } from "./partials/header";
import { hierarchy } from "./partials/hierarchy";
import { member } from "./partials/member";
import { memberDeclaration } from "./partials/member.declaration";
import { memberGetterSetter } from "./partials/member.getterSetter";
import { memberReference } from "./partials/member.reference";
import { memberSignatureBody } from "./partials/member.signature.body";
import { memberSignatureTitle } from "./partials/member.signature.title";
import { memberSignatures } from "./partials/member.signatures";
import { memberSources } from "./partials/member.sources";
import { members } from "./partials/members";
import { membersGroup } from "./partials/members.group";
import { navigation } from "./partials/navigation";
import { parameter } from "./partials/parameter";
import { type } from "./partials/type";
import { typeAndParent } from "./partials/typeAndParent";
import { typeParameters } from "./partials/typeParameters";
import { indexTemplate } from "./templates";
import { reflectionTemplate } from "./templates/reflection";
function bind<F, L extends any[], R>(fn: (f: F, ...a: L) => R, first: F) {
return (...r: L) => fn(first, ...r);
}
export class DefaultThemeRenderContext {
options: Options;
constructor(private theme: DefaultTheme, options: Options) {
this.options = options;
}
hook = (name: keyof RendererHooks) =>
this.theme.owner.hooks.emit(name, this);
/** Avoid this in favor of urlTo if possible */
relativeURL = (url: string | undefined) => {
return url ? this.theme.markedPlugin.getRelativeUrl(url) : url;
};
urlTo = (reflection: Reflection) => this.relativeURL(reflection.url);
markdown = (md: string | undefined) => {
return md ? this.theme.markedPlugin.parseMarkdown(md) : "";
};
attemptExternalResolution = (symbol: ts.Symbol | undefined) => {
return this.theme.owner.attemptExternalResolution(symbol);
};
reflectionTemplate = bind(reflectionTemplate, this);
indexTemplate = bind(indexTemplate, this);
defaultLayout = bind(defaultLayout, this);
analytics = bind(analytics, this);
breadcrumb = bind(breadcrumb, this);
comment = bind(comment, this);
footer = bind(footer, this);
header = bind(header, this);
hierarchy = bind(hierarchy, this);
index = bind(index, this);
member = bind(member, this);
memberDeclaration = bind(memberDeclaration, this);
memberGetterSetter = bind(memberGetterSetter, this);
memberReference = bind(memberReference, this);
memberSignatureBody = bind(memberSignatureBody, this);
memberSignatureTitle = bind(memberSignatureTitle, this);
memberSignatures = bind(memberSignatures, this);
memberSources = bind(memberSources, this);
members = bind(members, this);
membersGroup = bind(membersGroup, this);
navigation = bind(navigation, this);
parameter = bind(parameter, this);
type = bind(type, this);
typeAndParent = bind(typeAndParent, this);
typeParameters = bind(typeParameters, this);
}