Skip to content

Commit

Permalink
chore(refactor): moved comment parts to helper file
Browse files Browse the repository at this point in the history
  • Loading branch information
tgreyuk committed Jun 25, 2024
1 parent fc7ce3d commit bf0dab1
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export function getDescriptionForReflection(
? model.signatures[0].comment
: model.comment;
if (comment?.summary?.length) {
return this.partials
.commentParts(comment.summary)
return this.helpers
.getCommentParts(comment.summary)
?.split('\n\n')[0]
.replace(/\n/g, ' ');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './comments.comment';
export * from './comments.commentParts';
export * from './container.body';
export * from './container.categories';
export * from './container.groups';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function comment(
? heading(opts.headingLevel, tagText) + '\n'
: bold(tagText) + '\n',
];
tagMd.push(this.partials.commentParts(tag.content));
tagMd.push(this.helpers.getCommentParts(tag.content));
return tagMd.join('\n');
});
md.push(tags.join('\n\n'));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function categories(
.forEach((category) => {
md.push(heading(options.headingLevel, category.title));
if (category.description) {
md.push(this.partials.commentParts(category.description));
md.push(this.helpers.getCommentParts(category.description));
}
if (category.children) {
md.push(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function groups(
if (group.categories) {
md.push(heading(options.headingLevel, getGroupTitle(group.title)));
if (group.description) {
md.push(this.partials.commentParts(group.description));
md.push(this.helpers.getCommentParts(group.description));
}
md.push(
this.partials.categories(group.categories, {
Expand All @@ -44,7 +44,7 @@ export function groups(

md.push(heading(options.headingLevel, getGroupTitle(group.title)));
if (group.description) {
md.push(this.partials.commentParts(group.description));
md.push(this.helpers.getCommentParts(group.description));
}
if (
isPropertiesGroup &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function reflectionIndex(
model.categories.forEach((categoryGroup) => {
md.push(heading(options.headingLevel, categoryGroup.title) + '\n');
if (categoryGroup.description) {
md.push(this.partials.commentParts(categoryGroup.description) + '\n');
md.push(this.helpers.getCommentParts(categoryGroup.description) + '\n');
}
md.push(this.helpers.getGroupIndex(categoryGroup) + '\n');
});
Expand All @@ -36,7 +36,7 @@ export function reflectionIndex(
);
if (categoryGroup.description) {
md.push(
this.partials.commentParts(categoryGroup.description) + '\n',
this.helpers.getCommentParts(categoryGroup.description) + '\n',
);
}
md.push(this.helpers.getGroupIndex(categoryGroup) + '\n');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ export function signature(
this.partials.inheritance(model, { headingLevel: options.headingLevel }),
);

if (model.comment) {
if (modelComments) {
md.push(
this.partials.comment(model.comment, {
this.partials.comment(modelComments, {
headingLevel: options.headingLevel,
showSummary: false,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function signatureReturns(
if (model.comment?.blockTags.length) {
const tags = model.comment.blockTags
.filter((tag) => tag.tag === '@returns')
.map((tag) => this.partials.commentParts(tag.content));
.map((tag) => this.helpers.getCommentParts(tag.content));
md.push(tags.join('\n\n'));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ export const resourcePartials = (context: MarkdownThemeContext) => {
isTableColumn?: boolean | undefined;
} = {},
) => partials.comment.apply(context, [model, options]) as string,
commentParts: (model: CommentDisplayPart[]) =>
partials.commentParts.apply(context, [model]) as string,
body: (model: ContainerReflection, options: { headingLevel: number }) =>
partials.body.apply(context, [model, options]) as string,
categories: (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function document(
md.push(this.partials.breadcrumbs());
}

md.push(this.partials.commentParts(page.model.content));
md.push(this.helpers.getCommentParts(page.model.content));

md.push(this.partials.footer());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function project(
this.page.project.url === this.page.url &&
this.options.getValue('entryPointStrategy') === EntryPointStrategy.Packages;

md.push(this.hook('index.page.begin').join('\n'));
md.push(this.hook('index.page.begin', this).join('\n'));

if (!this.options.getValue('hidePageHeader')) {
md.push(this.partials.header());
Expand All @@ -35,14 +35,14 @@ export function project(
this.options.getValue('mergeReadme') && Boolean(page.model.readme);

if (includeReadme && page.model.readme) {
md.push(this.partials.commentParts(page.model.readme));
md.push(this.helpers.getCommentParts(page.model.readme));
}

if (!this.options.getValue('hidePageTitle') && !includeReadme) {
md.push(heading(1, this.partials.pageTitle()));
}

md.push(this.hook('content.begin').join('\n'));
md.push(this.hook('content.begin', this).join('\n'));

if (page.model.comment) {
md.push(this.partials.comment(page.model.comment, { headingLevel: 2 }));
Expand Down Expand Up @@ -72,7 +72,7 @@ export function project(

md.push(this.partials.footer());

md.push(this.hook('index.page.end').join('\n'));
md.push(this.hook('index.page.end', this).join('\n'));

return md.join('\n\n');
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function readme(

if (Boolean(page.model.readme)) {
md.push(
this.partials.commentParts(page.model.readme as CommentDisplayPart[]),
this.helpers.getCommentParts(page.model.readme as CommentDisplayPart[]),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function reflection(
) {
const md: string[] = [];

md.push(this.hook('page.begin').join('\n'));
md.push(this.hook('page.begin', this).join('\n'));

if (!this.options.getValue('hidePageHeader')) {
md.push(this.partials.header());
Expand All @@ -26,7 +26,7 @@ export function reflection(
md.push(heading(1, this.partials.pageTitle()));
}

md.push(this.hook('content.begin').join('\n'));
md.push(this.hook('content.begin', this).join('\n'));

if (
[
Expand All @@ -44,7 +44,7 @@ export function reflection(

md.push(this.partials.footer());

md.push(this.hook('page.end').join('\n'));
md.push(this.hook('page.end', this).join('\n'));

return md.join('\n\n');
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ import {
resourcePartials,
resourceTemplates,
} from '@plugin/theme/context/resources';
import {
MarkdownRenderer,
MarkdownRendererHooks,
PackageMetaData,
} from '@plugin/types';
import { MarkdownRenderer, PackageMetaData } from '@plugin/types';
import * as path from 'path';
import { Internationalization, Options, Reflection } from 'typedoc';

Expand Down Expand Up @@ -161,6 +157,7 @@ export class MarkdownThemeContext {
*
* @internal
*/
hook = (name: keyof MarkdownRendererHooks) =>
(this.theme.owner as MarkdownRenderer).markdownHooks.emit(name, this);
hook: MarkdownRenderer['markdownHooks']['emit'] = (...params) => {
return (this.theme.owner as MarkdownRenderer).markdownHooks.emit(...params);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
* This is a function that is assigned to a variable.
*
* @param someParam This is some numeric parameter.
*
* @see http://abc.com
*/
export const basicFunction = (someParam: number) => {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ This is some numeric parameter.
\`number\`
## See
http://abc.com
## Source
[functions.ts:1](http://source-url)
Expand All @@ -287,6 +291,10 @@ This is a function that is assigned to a variable.
\`number\`
## See
http://abc.com
## Source
[functions.ts:1](http://source-url)
Expand Down

0 comments on commit bf0dab1

Please sign in to comment.