import { Contracts } from "ts-extractor" ; import { MarkdownGenerator , MarkdownBuilder } from "@simplrjs/markdown" ; import { GeneratorHelpers } from "../generator-helpers" ; import { SupportedApiItemKindType , PluginResult , PluginOptions } from "../contracts/plugin" ; import { BasePlugin } from "../abstractions/base-plugin" ; import { ApiEnum } from "../api-items/definitions/api-enum" ; import { ApiEnumMember } from "../api-items/definitions/api-enum-member" ; export class ApiEnumPlugin extends BasePlugin < Contracts . ApiEnumDto > { public SupportedApiDefinitionKind ( ) { return [ GeneratorHelpers . ApiDefinitionKind . Enum ] ; } public CheckApiItem ( item ) { return true ; } private renderEnumTable ( members ) { const header = [ "Name" , "Value" , "Description" ] ; const content = members . map ( x => [ x . ApiItem . Name , x . ApiItem . Value , x . ApiItem . Metadata . DocumentationComment ] ) ; return MarkdownGenerator . Table ( header , content , { removeColumnIfEmpty : true } ) ; } public Render ( options , apiItem ) { const serializedApiItem = new ApiEnum ( options . ExtractedData , apiItem , options . Reference ) ; const heading = serializedApiItem . ToHeadingText ( ) ; const pluginResult = { ... GeneratorHelpers . GetDefaultPluginResultData ( ) , ApiItem : apiItem , Reference : options . Reference , Headings : [ { Heading : heading , ApiItemId : options . Reference . Id } ] , UsedReferences : [ options . Reference . Id ] } ; pluginResult . Result = new MarkdownBuilder ( ) . Header ( heading , 3 ) . EmptyLine ( ) . Text ( this . RenderApiItemMetadata ( apiItem ) ) . EmptyLine ( ) . Code ( serializedApiItem . ToText ( ) , GeneratorHelpers . DEFAULT_CODE_OPTIONS ) . EmptyLine ( ) . Bold ( "Members" ) . EmptyLine ( ) . Text ( this . renderEnumTable ( serializedApiItem . EnumMembers ) ) . GetOutput ( ) ; return pluginResult ; } }