Skip to content

Commit

Permalink
feat(theme-demo): first draft implementation of pages plugin support
Browse files Browse the repository at this point in the history
Related to #109
  • Loading branch information
GerkinDev committed Jul 23, 2022
1 parent 25e82d8 commit d6d8930
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/plugin-monorepo-readmes/src/output/theme.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Theme } from 'typedoc';

export interface IReadmePluginTheme extends Theme {
monorepoReadmesPlugin: true;
monorepoReadmesPlugin: boolean;
}

export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin;
export const isMonorepoReadmesPluginTheme = ( theme: Theme ): theme is IReadmePluginTheme => 'monorepoReadmesPlugin' in theme && ( theme as any ).monorepoReadmesPlugin === true;
10 changes: 9 additions & 1 deletion packages/theme-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@
"@knodes/typedoc-pluginutils": "~0.23.1"
},
"peerDependencies": {
"typedoc": "^0.23.0"
"typedoc": "^0.23.0",
"@knodes/typedoc-plugin-pages": "~0.23.1",
"@knodes/typedoc-plugin-code-blocks": "~0.23.1",
"@knodes/typedoc-plugin-monorepo-readmes": "~0.23.1"
},
"peerDependenciesMeta": {
"@knodes/typedoc-plugin-pages": {"optional": true},
"@knodes/typedoc-plugin-code-blocks": {"optional": true},
"@knodes/typedoc-plugin-monorepo-readmes": {"optional": true}
},
"devDependencies": {
"@knodes/eslint-config": "^1.6.5",
Expand Down
8 changes: 7 additions & 1 deletion packages/theme-demo/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
export const STUB = '';
import { Application } from 'typedoc';

import { KnodesPluginsDemoTheme } from './thene/knodes-plugins-demo-theme';

export const load = ( application: Application ) => {
application.renderer.defineTheme( 'knodes-plugins-theme-demo', KnodesPluginsDemoTheme );
};
21 changes: 21 additions & 0 deletions packages/theme-demo/src/thene/knodes-plugins-demo-theme-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DefaultThemeRenderContext, Options } from 'typedoc';

import type { KnodesPluginsDemoTheme } from './knodes-plugins-demo-theme';
import { navigation } from './partials/navigation';
import { renderPageLink } from './partials/plugin-pages/page-link';
import { pagesNavigation } from './partials/plugin-pages/pages-navigation';

export class KnodesPluginsDemoThemeContext extends DefaultThemeRenderContext {
public pagesPlugin = {
pagesNavigation: pagesNavigation( this ),
renderPageLink: renderPageLink( this ),
};

// public codeBlocksPlugin: ICodeBlocksPluginThemeMethods = {};

public constructor( theme: KnodesPluginsDemoTheme, options: Options ) {
super( theme, options );

this.navigation = navigation( this );
}
}
52 changes: 52 additions & 0 deletions packages/theme-demo/src/thene/knodes-plugins-demo-theme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { DefaultTheme, Renderer, RendererEvent } from 'typedoc';

import type { ICodeBlocksPluginTheme, ICodeBlocksPluginThemeMethods } from '@knodes/typedoc-plugin-code-blocks';
import type { IReadmePluginTheme } from '@knodes/typedoc-plugin-monorepo-readmes';
import type { IPagesPluginTheme, IPagesPluginThemeMethods } from '@knodes/typedoc-plugin-pages';

import { KnodesPluginsDemoThemeContext } from './knodes-plugins-demo-theme-context';

export class KnodesPluginsDemoTheme extends DefaultTheme implements IPagesPluginTheme, ICodeBlocksPluginTheme, IReadmePluginTheme {
public readonly monorepoReadmesPlugin = true as const;
private _contextCache?: KnodesPluginsDemoThemeContext;

public constructor( renderer: Renderer ) {
super( renderer );
}

/**
* Return the plugin methods.
* This method is called when `@knodes/typedoc-plugin=pages` will start rendering.
* You might do some initialization here, like copying specific assets, or post-processing the pages tree.
*
* @param _event - The renderer event.
* @returns the plugin rendering methods for this theme.
*/
public pagesPlugin( _event: RendererEvent ): IPagesPluginThemeMethods {
return this.getRenderContext().pagesPlugin;
}

/**
* Return the plugin methods.
*
* @param _event - The renderer event.
* @returns the plugin rendering methods for this theme.
*/
public codeBlocksPlugin( _event: RendererEvent ): ICodeBlocksPluginThemeMethods {
throw new Error( 'Method not implemented.' );
return {} as any;
}

/**
* Obtain the stored instance of context.
*
* @returns the theme context.
*/
public override getRenderContext(): KnodesPluginsDemoThemeContext {
this._contextCache = this._contextCache ??
new KnodesPluginsDemoThemeContext( this, this.application.options ) ;

return this._contextCache;
}
}

11 changes: 11 additions & 0 deletions packages/theme-demo/src/thene/partials/navigation.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { JSX, PageEvent, Reflection } from 'typedoc';

import type { KnodesPluginsDemoThemeContext } from '../knodes-plugins-demo-theme-context';

export const navigation = ( context: KnodesPluginsDemoThemeContext ) => ( props: PageEvent<Reflection> ): JSX.Element =>
<>
{context.settings()}
{context.pagesPlugin.pagesNavigation( props )}
{context.primaryNavigation( props )}
{context.secondaryNavigation( props )}
</>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { JSX } from 'typedoc';

import type { RenderPageLinkProps } from '@knodes/typedoc-plugin-pages';

import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context';

export const renderPageLink = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: RenderPageLinkProps ): JSX.Element => <>
TODO
</>;
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { JSX, PageEvent, Reflection } from 'typedoc';

import type { KnodesPluginsDemoThemeContext } from '../../knodes-plugins-demo-theme-context';

export const pagesNavigation = ( _ctx: KnodesPluginsDemoThemeContext ) => ( _props: PageEvent<Reflection> ): JSX.Element => <>
TODO
</>;

0 comments on commit d6d8930

Please sign in to comment.