Skip to content

Commit 14c9bf3

Browse files
author
Sebastian Schürmann
committed
refactor(vanillin): doc gen config available as static
1 parent dd50aca commit 14c9bf3

File tree

1 file changed

+37
-8
lines changed

1 file changed

+37
-8
lines changed

packages/vanillin/src/doc-gen.ts

+37-8
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,63 @@ import { TSDocParser, type ParserContext, type DocComment, TSDocConfiguration, T
22
import * as path from 'path';
33
import * as fs from 'fs';
44
import { Formatter } from './formatter';
5+
6+
/**
7+
* A class for parsing and rendering TSDoc documentation comments.
8+
* Provides functionality to parse TypeScript source files and extract their documentation,
9+
* as well as render the documentation in a formatted way.
10+
*/
511
export class DocGen {
612

13+
/**
14+
* TSDoc tag definition for demo blocks.
15+
* This custom block tag allows marking code sections as demos in the documentation.
16+
*/
17+
public static CUSTOM_BLOCK_DEFINITION_DEMO = new TSDocTagDefinition({
18+
tagName: '@demo',
19+
syntaxKind: TSDocTagSyntaxKind.BlockTag
20+
});
21+
22+
/**
23+
* Parses a TypeScript source file to extract its documentation.
24+
*
25+
* @param doc - The path to the TypeScript source file to parse
26+
* @returns A ParserContext containing the parsed documentation
27+
*/
728
parseDoc(doc: string): ParserContext {
829
const inputFilename: string = path.resolve(doc);
930
const inputBuffer: string = fs.readFileSync(inputFilename).toString();
1031

1132
const customConfiguration: TSDocConfiguration = new TSDocConfiguration();
1233

13-
const customBlockDefinition: TSDocTagDefinition = new TSDocTagDefinition({
14-
tagName: '@demo',
15-
syntaxKind: TSDocTagSyntaxKind.BlockTag
16-
});
17-
1834
customConfiguration.addTagDefinitions([
19-
customBlockDefinition
35+
DocGen.CUSTOM_BLOCK_DEFINITION_DEMO
2036
]);
21-
37+
2238
const tsdocParser: TSDocParser = new TSDocParser(customConfiguration);
2339
const parserContext: ParserContext = tsdocParser.parseString(inputBuffer);
2440
return parserContext;
2541
}
2642

27-
render (context: ParserContext): string {
43+
/**
44+
* Renders all documentation nodes from a parsed documentation context.
45+
*
46+
* @param context - The parsed documentation context to render
47+
* @returns A formatted string containing the rendered documentation
48+
*/
49+
render(context: ParserContext): string {
2850
const docComment: DocComment = context.docComment;
2951
const result = Formatter.renderDocNodes(docComment.getChildNodes());
3052
return result;
3153
}
3254

55+
/**
56+
* Renders only the custom documentation blocks from a parsed documentation context.
57+
* This specifically focuses on rendering blocks marked with custom tags like @demo.
58+
*
59+
* @param context - The parsed documentation context to render
60+
* @returns A formatted string containing only the custom documentation blocks
61+
*/
3362
renderDocs(context: ParserContext) {
3463
const docComment: DocComment = context.docComment;
3564
const result = Formatter.renderDocNodes(docComment.customBlocks);

0 commit comments

Comments
 (0)