87 lines
2.9 KiB
TypeScript
87 lines
2.9 KiB
TypeScript
/// <reference path="../../bin/typedoc.d.ts" />
|
|
|
|
export class Theme extends TypeDoc.Output.DefaultTheme
|
|
{
|
|
/**
|
|
* Create a new DefaultTheme instance.
|
|
*
|
|
* @param renderer The renderer this theme is attached to.
|
|
* @param basePath The base path of this theme.
|
|
*/
|
|
constructor(renderer:TypeDoc.Output.Renderer, basePath:string) {
|
|
super(renderer, basePath);
|
|
|
|
renderer.removePlugin(TypeDoc.Output.AssetsPlugin);
|
|
renderer.removePlugin(TypeDoc.Output.JavascriptIndexPlugin);
|
|
renderer.removePlugin(TypeDoc.Output.NavigationPlugin);
|
|
renderer.removePlugin(TypeDoc.Output.TocPlugin);
|
|
|
|
renderer.on(TypeDoc.Output.Renderer.EVENT_BEGIN_PAGE, this.onRendererBeginPage, this);
|
|
}
|
|
|
|
|
|
/**
|
|
* Test whether the given path contains a documentation generated by this theme.
|
|
*
|
|
* @param path The path of the directory that should be tested.
|
|
* @returns TRUE if the given path seems to be a previous output directory,
|
|
* otherwise FALSE.
|
|
*/
|
|
isOutputDirectory(path:string):boolean {
|
|
if (!FS.existsSync(Path.join(path, 'index.html'))) return false;
|
|
return true;
|
|
}
|
|
|
|
|
|
/**
|
|
* Map the models of the given project to the desired output files.
|
|
*
|
|
* @param project The project whose urls should be generated.
|
|
* @returns A list of [[UrlMapping]] instances defining which models
|
|
* should be rendered to which files.
|
|
*/
|
|
getUrls(project:TypeDoc.Models.ProjectReflection):TypeDoc.Models.UrlMapping[] {
|
|
var urls = [];
|
|
urls.push(new TypeDoc.Models.UrlMapping('index.html', project, 'index.hbs'));
|
|
|
|
project.url = 'index.html';
|
|
project.anchor = null;
|
|
project.hasOwnDocument = true;
|
|
|
|
project.children.forEach((child) => {
|
|
TypeDoc.Output.DefaultTheme.applyAnchorUrl(child, project);
|
|
});
|
|
|
|
return urls;
|
|
}
|
|
|
|
|
|
/**
|
|
* Triggered before a document will be rendered.
|
|
*
|
|
* @param page An event object describing the current render operation.
|
|
*/
|
|
private onRendererBeginPage(page:TypeDoc.Output.OutputPageEvent) {
|
|
var model = page.model;
|
|
if (!(model instanceof TypeDoc.Models.BaseReflection)) {
|
|
return;
|
|
}
|
|
|
|
page.toc = new TypeDoc.Models.NavigationItem();
|
|
Theme.buildToc(page.model, page.toc);
|
|
}
|
|
|
|
|
|
/**
|
|
* Create a toc navigation item structure.
|
|
*
|
|
* @param model The models whose children should be written to the toc.
|
|
* @param parent The parent [[Models.NavigationItem]] the toc should be appended to.
|
|
*/
|
|
static buildToc(model:TypeDoc.Models.DeclarationReflection, parent:TypeDoc.Models.NavigationItem) {
|
|
model.children.forEach((child:TypeDoc.Models.DeclarationReflection) => {
|
|
var item = TypeDoc.Models.NavigationItem.create(child, parent, true);
|
|
Theme.buildToc(child, item);
|
|
});
|
|
}
|
|
} |