Skip to content

Commit

Permalink
Add Typedoc setup for integrating generated api docs
Browse files Browse the repository at this point in the history
  • Loading branch information
craigbeck committed Jun 27, 2024
1 parent de9102b commit 7b60374
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ defaults:
values:
render_with_liquid: true

nav_external_links:
- title: Derby API
url: /api
hide_icon: true
opens_in_new_tab: true
- title: Racer API
url: https://derbyjs.github.io/racer
hide_icon: true
opens_in_new_tab: true

# Exclude from processing.
# The following items will not be processed, by default.
# Any item listed under the `exclude:` key here will be automatically added to
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"scripts": {
"build": "node_modules/.bin/tsc",
"checks": "npm run lint && npm test",
"docs": "npx typedoc",
"lint": "npx eslint src/**/*.ts test/**/*.js",
"lint:ts": "npx eslint src/**/*.ts",
"lint:fix": "npm run lint:ts -- --fix",
Expand Down Expand Up @@ -78,6 +79,9 @@
"prettier": "^3.0.1",
"racer": "^v2.0.0-beta.11",
"ts-node": "^10.9.2",
"typedoc": "^0.25.13",
"typedoc-plugin-mdn-links": "^3.1.28",
"typedoc-plugin-missing-exports": "^2.2.0",
"typescript": "~5.1.3"
},
"peerDependencies": {
Expand Down
21 changes: 20 additions & 1 deletion src/templates/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { Controller } from '../Controller';

function noop() { }

/**
* Properties and methods which are globally inherited for the entire page
*/
export class ContextMeta {
addBinding: (binding: any) => void = noop;

Check warning on line 15 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 16

Unexpected any. Specify a different type

Check warning on line 15 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 18

Unexpected any. Specify a different type

Check warning on line 15 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 20

Unexpected any. Specify a different type
removeBinding: (binding: any) => void = noop;

Check warning on line 16 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 16

Unexpected any. Specify a different type

Check warning on line 16 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 18

Unexpected any. Specify a different type

Check warning on line 16 in src/templates/contexts.ts

View workflow job for this annotation

GitHub Actions / Node 20

Unexpected any. Specify a different type
Expand Down Expand Up @@ -82,6 +85,11 @@ export class Context {
this._eventModels = null;
}

/**
* Generate unique Id
*
* @returns namespaced Id
*/
id() {
const count = ++this.meta.idCount;
return this.meta.idNamespace + '_' + count.toString(36);
Expand Down Expand Up @@ -136,7 +144,13 @@ export class Context {
return new Context(this.meta, component, this, this.unbound);
}

// Make a context for an item in an each block
/**
* Make a context for an item in an each block
*
* @param expression
* @param item
* @returns new Context
*/
eachChild(expression, item) {
const context = new Context(this.meta, this.controller, this, this.unbound, expression);
context.item = item;
Expand Down Expand Up @@ -210,6 +224,11 @@ export class Context {
}
}

/**
* Gets the current `context` view or closest `context.parent` view
*
* @returns view
*/
getView() {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let context: Context = this;
Expand Down
25 changes: 15 additions & 10 deletions src/test-utils/ComponentHarness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export class ComponentHarness extends EventEmitter {
document: Document;
model: RootModel;
page: PageForHarness;


/**
* Creates a `ComponentHarness`.
*
* If arguments are provided, then `#setup` is called with the arguments.
*/
constructor() {
super();
this.app = new AppForHarness(this);
Expand All @@ -94,15 +99,15 @@ export class ComponentHarness extends EventEmitter {

/** @typedef { {view: {is: string, source?: string}} } InlineComponent */
/**
* Sets up the harness with a HTML template, which should contain a `<view is="..."/>` for the
* component under test, and the components to register for the test.
*
* @param {string} source - HTML template for the harness page
* @param {...(Component | InlineComponent} components - components to register for the test
*
* @example
* var harness = new ComponentHarness().setup('<view is="dialog"/>', Dialog);
*/
* Sets up the harness with a HTML template, which should contain a `<view is="..."/>` for the
* component under test, and the components to register for the test.
*
* @param {string} source - HTML template for the harness page
* @param {...(Component | InlineComponent} components - components to register for the test
*
* @example
* var harness = new ComponentHarness().setup('<view is="dialog"/>', Dialog);
*/
setup(source: string, ...components: ComponentConstructor[]) {
this.app.views.register('$harness', source);
// Remaining variable arguments are components
Expand Down
17 changes: 17 additions & 0 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"entryPoints": ["src/index.ts"],
"excludeNotDocumented": false,
"plugin":[
"typedoc-plugin-mdn-links",
"typedoc-plugin-missing-exports",
"./typedocExcludeUnderscore.mjs"
],
"out": "docs/api",
"visibilityFilters": {
"protected": false,
"private": false,
"inherited": true,
"external": false
},
"excludePrivate": true
}
30 changes: 30 additions & 0 deletions typedocExcludeUnderscore.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Converter, ReflectionFlag, ReflectionKind } from "typedoc";
import camelCase from "camelcase";

/**
* @param {Readonly<import('typedoc').Application>} app
*/
export function load(app) {
/**
* Create declaration event handler that sets symbols with underscore-prefixed names
* to private to exclude from generated documentation.
*
* Due to "partial class" style of code in use, otherwise private properties and methods -
* prefixed with underscore - are effectively declared public so they can be accessed in other
* files used to build class - e.g. Model. This marks anything prefixed with an underscore and
* no doc comment as private.
*
* @param {import('typedoc').Context} context
* @param {import('typedoc').DeclarationReflection} reflection
*/
function handleCreateDeclaration(context, reflection) {
if (!reflection.name.startsWith('_')) {
return;
}
if (!reflection.comment) {
reflection.setFlag(ReflectionFlag.Private);
}
}

app.converter.on(Converter.EVENT_CREATE_DECLARATION, handleCreateDeclaration);
}

0 comments on commit 7b60374

Please sign in to comment.