Skip to content

Commit 1d742ba

Browse files
Add entry point options, resolves #90
1 parent 350e725 commit 1d742ba

File tree

3 files changed

+110
-22
lines changed

3 files changed

+110
-22
lines changed

bin/typedoc.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3761,6 +3761,10 @@ declare module td {
37613761
* Should we hide the TypeDoc link at the end of the page?
37623762
*/
37633763
hideGenerator?: boolean;
3764+
/**
3765+
* Specifies the fully qualified name of the root symbol. Defaults to global namespace.
3766+
*/
3767+
entryPoint?: string;
37643768
}
37653769
}
37663770
declare module td.output {
@@ -3821,6 +3825,13 @@ declare module td.output {
38213825
* should be rendered to which files.
38223826
*/
38233827
getUrls(project: models.ProjectReflection): UrlMapping[];
3828+
/**
3829+
* Return the entry point of the documentation.
3830+
*
3831+
* @param project The current project.
3832+
* @returns The reflection that should be used as the entry point.
3833+
*/
3834+
getEntryPoint(project: models.ProjectReflection): models.ContainerReflection;
38243835
/**
38253836
* Create a navigation structure for the given project.
38263837
*

bin/typedoc.js

Lines changed: 48 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5208,17 +5208,18 @@ var td;
52085208
Reflection.prototype.getChildByName = function (arg) {
52095209
var names = Array.isArray(arg) ? arg : arg.split('.');
52105210
var name = names[0];
5211+
var result = null;
52115212
this.traverse(function (child) {
52125213
if (child.name == name) {
52135214
if (names.length <= 1) {
5214-
return child;
5215+
result = child;
52155216
}
52165217
else if (child) {
5217-
return child.getChildByName(names.slice(1));
5218+
result = child.getChildByName(names.slice(1));
52185219
}
52195220
}
52205221
});
5221-
return null;
5222+
return result;
52225223
};
52235224
/**
52245225
* Try to find a reflection by its name.
@@ -7982,6 +7983,10 @@ var td;
79827983
name: 'hideGenerator',
79837984
help: 'Do not print the TypeDoc link at the end of the page.',
79847985
type: 2 /* Boolean */
7986+
}, {
7987+
name: 'entryPoint',
7988+
help: 'Specifies the fully qualified name of the root symbol. Defaults to global namespace.',
7989+
type: 0 /* String */
79857990
}];
79867991
};
79877992
/**
@@ -7993,22 +7998,47 @@ var td;
79937998
*/
79947999
DefaultTheme.prototype.getUrls = function (project) {
79958000
var urls = [];
8001+
var entryPoint = this.getEntryPoint(project);
79968002
if (this.renderer.application.options.readme == 'none') {
7997-
project.url = 'index.html';
7998-
urls.push(new output.UrlMapping('index.html', project, 'reflection.hbs'));
8003+
entryPoint.url = 'index.html';
8004+
urls.push(new output.UrlMapping('index.html', entryPoint, 'reflection.hbs'));
79998005
}
80008006
else {
8001-
project.url = 'globals.html';
8002-
urls.push(new output.UrlMapping('globals.html', project, 'reflection.hbs'));
8003-
urls.push(new output.UrlMapping('index.html', project, 'index.hbs'));
8007+
entryPoint.url = 'globals.html';
8008+
urls.push(new output.UrlMapping('globals.html', entryPoint, 'reflection.hbs'));
8009+
urls.push(new output.UrlMapping('index.html', entryPoint, 'index.hbs'));
80048010
}
8005-
if (project.children) {
8006-
project.children.forEach(function (child) {
8011+
if (entryPoint.children) {
8012+
entryPoint.children.forEach(function (child) {
80078013
DefaultTheme.buildUrls(child, urls);
80088014
});
80098015
}
80108016
return urls;
80118017
};
8018+
/**
8019+
* Return the entry point of the documentation.
8020+
*
8021+
* @param project The current project.
8022+
* @returns The reflection that should be used as the entry point.
8023+
*/
8024+
DefaultTheme.prototype.getEntryPoint = function (project) {
8025+
var entryPoint = this.renderer.application.options.entryPoint;
8026+
if (entryPoint) {
8027+
var reflection = project.getChildByName(entryPoint);
8028+
if (reflection) {
8029+
if (reflection instanceof td.models.ContainerReflection) {
8030+
return reflection;
8031+
}
8032+
else {
8033+
this.renderer.application.logger.warn('The given entry point `%s` is not a container.', entryPoint);
8034+
}
8035+
}
8036+
else {
8037+
this.renderer.application.logger.warn('The entry point `%s` could not be found.', entryPoint);
8038+
}
8039+
}
8040+
return project;
8041+
};
80128042
/**
80138043
* Create a navigation structure for the given project.
80148044
*
@@ -8120,21 +8150,27 @@ var td;
81208150
var modules = [];
81218151
project.getReflectionsByKind(td.models.ReflectionKind.SomeModule).forEach(function (someModule) {
81228152
var target = someModule.parent;
8153+
var inScope = (someModule == entryPoint);
81238154
while (target) {
81248155
if (target.kindOf(1 /* ExternalModule */))
81258156
return;
8157+
if (entryPoint == target)
8158+
inScope = true;
81268159
target = target.parent;
81278160
}
8128-
modules.push(someModule);
8161+
if (inScope) {
8162+
modules.push(someModule);
8163+
}
81298164
});
81308165
if (modules.length < 10) {
81318166
buildGroups(modules, root, buildChildren);
81328167
}
81338168
else {
8134-
buildGroups(project.getChildrenByKind(td.models.ReflectionKind.SomeModule), root, buildChildren);
8169+
buildGroups(entryPoint.getChildrenByKind(td.models.ReflectionKind.SomeModule), root, buildChildren);
81358170
}
81368171
return root;
81378172
}
8173+
var entryPoint = this.getEntryPoint(project);
81388174
return build(this.renderer.application.options.readme != 'none');
81398175
};
81408176
/**

src/td/output/themes/DefaultTheme.ts

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,15 @@ declare module td
1717
* Should we hide the TypeDoc link at the end of the page?
1818
*/
1919
hideGenerator?:boolean;
20+
21+
/**
22+
* Specifies the fully qualified name of the root symbol. Defaults to global namespace.
23+
*/
24+
entryPoint?:string;
2025
}
2126
}
2227

28+
2329
module td.output
2430
{
2531
/**
@@ -126,6 +132,10 @@ module td.output
126132
name: 'hideGenerator',
127133
help: 'Do not print the TypeDoc link at the end of the page.',
128134
type: ParameterType.Boolean
135+
},{
136+
name: 'entryPoint',
137+
help: 'Specifies the fully qualified name of the root symbol. Defaults to global namespace.',
138+
type: ParameterType.String
129139
}];
130140
}
131141

@@ -139,18 +149,19 @@ module td.output
139149
*/
140150
getUrls(project:models.ProjectReflection):UrlMapping[] {
141151
var urls = [];
152+
var entryPoint = this.getEntryPoint(project);
142153

143154
if (this.renderer.application.options.readme == 'none') {
144-
project.url = 'index.html';
145-
urls.push(new UrlMapping('index.html', project, 'reflection.hbs'));
155+
entryPoint.url = 'index.html';
156+
urls.push(new UrlMapping('index.html', entryPoint, 'reflection.hbs'));
146157
} else {
147-
project.url = 'globals.html';
148-
urls.push(new UrlMapping('globals.html', project, 'reflection.hbs'));
149-
urls.push(new UrlMapping('index.html', project, 'index.hbs'));
158+
entryPoint.url = 'globals.html';
159+
urls.push(new UrlMapping('globals.html', entryPoint, 'reflection.hbs'));
160+
urls.push(new UrlMapping('index.html', entryPoint, 'index.hbs'));
150161
}
151162

152-
if (project.children) {
153-
project.children.forEach((child) => {
163+
if (entryPoint.children) {
164+
entryPoint.children.forEach((child) => {
154165
DefaultTheme.buildUrls(child, urls);
155166
});
156167
}
@@ -159,6 +170,31 @@ module td.output
159170
}
160171

161172

173+
/**
174+
* Return the entry point of the documentation.
175+
*
176+
* @param project The current project.
177+
* @returns The reflection that should be used as the entry point.
178+
*/
179+
getEntryPoint(project:models.ProjectReflection):models.ContainerReflection {
180+
var entryPoint = this.renderer.application.options.entryPoint;
181+
if (entryPoint) {
182+
var reflection = project.getChildByName(entryPoint);
183+
if (reflection) {
184+
if (reflection instanceof models.ContainerReflection) {
185+
return reflection;
186+
} else {
187+
this.renderer.application.logger.warn('The given entry point `%s` is not a container.', entryPoint);
188+
}
189+
} else {
190+
this.renderer.application.logger.warn('The entry point `%s` could not be found.', entryPoint);
191+
}
192+
}
193+
194+
return project;
195+
}
196+
197+
162198
/**
163199
* Create a navigation structure for the given project.
164200
*
@@ -278,23 +314,28 @@ module td.output
278314
var modules = [];
279315
project.getReflectionsByKind(models.ReflectionKind.SomeModule).forEach((someModule) => {
280316
var target = someModule.parent;
317+
var inScope = (someModule == entryPoint);
281318
while (target) {
282319
if (target.kindOf(models.ReflectionKind.ExternalModule)) return;
320+
if (entryPoint == target) inScope = true;
283321
target = target.parent;
284322
}
285-
modules.push(someModule);
323+
324+
if (inScope) {
325+
modules.push(someModule);
326+
}
286327
});
287328

288329
if (modules.length < 10) {
289330
buildGroups(modules, root, buildChildren);
290331
} else {
291-
buildGroups(project.getChildrenByKind(models.ReflectionKind.SomeModule), root, buildChildren);
332+
buildGroups(entryPoint.getChildrenByKind(models.ReflectionKind.SomeModule), root, buildChildren);
292333
}
293334

294335
return root;
295336
}
296337

297-
338+
var entryPoint = this.getEntryPoint(project);
298339
return build(this.renderer.application.options.readme != 'none');
299340
}
300341

0 commit comments

Comments
 (0)