Skip to content

feat: add description section classes-mixins #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/to-markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fs.writeFileSync('./custom-elements.md', markdown);
| Option | Type | Default | Description |
| ------------- | ---------------------------- | ------- | ----------- |
| headingOffset | Integer | 0 | Offset the heading level by this number |
| mainDescription | Boolean | true | Show description field for Class and Mixins |
| private | `'all'\|'details'\|'hidden'` | `'all'` | See [Private Members](#private-members) |
| omitDeclarations | `OptionalDeclarations[]` | [] | See [Omit Declarations](#omit-declarations) |
| omitSections | `OptionalSections[]` | [] | See [Omit Sections](#omit-sections) |
Expand Down Expand Up @@ -62,6 +63,7 @@ customElementsManifestToMarkdown(manifest, {
The `omitSections` option is a `string[]` that controls which sections of a declaration's full entry in the manifest.json should be rendered in the final markdown output. The section names are:

- mainHeading : "main-heading"
- mainDescription : "main-description"
- superClass : "super-class"
- fields : "fields"
- methods : "methods"
Expand Down Expand Up @@ -117,6 +119,7 @@ customElementsManifestToMarkdown(manifest, {
"declarations": [
{
"kind": "class",
"description": "My description",
"name": "SuperClass",
"events": [
{
Expand Down Expand Up @@ -420,6 +423,8 @@ customElementsManifestToMarkdown(manifest, {

<details><summary>Result</summary>

My description

## `./fixtures/-TEST/package/my-element.js`:

### class: `SuperClass`
Expand Down
2 changes: 2 additions & 0 deletions packages/to-markdown/fixtures/heading-offset-2/EXPECTED.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Large description of ...

### `my-element.js`:

#### class: `MyElement`, `my-element`
Expand Down
3 changes: 3 additions & 0 deletions packages/to-markdown/fixtures/heading-offset-2/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Large description of ...


### `my-element.js`:

#### class: `MyElement`, `my-element`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{
"kind": "class",
"name": "MyElement",
"description": "Large description of ...",
"cssProperties": [
{
"name": "--background-color",
Expand Down
14 changes: 14 additions & 0 deletions packages/to-markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DECLARATIONS = {
};

const SECTIONS = {
mainDescription : 'main-description',
mainHeading: 'main-heading',
superClass: 'super-class',
fields: 'fields',
Expand Down Expand Up @@ -180,7 +181,20 @@ function makeModuleDoc(mod, options) {
const variablesDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('variable'));
const functionsDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('function'));

const mainDescription =
optionEnabled(omittedSections.mainDescription)
? declarations.map((decl) =>{
if (['mixin', 'class'].includes(decl.kind) && decl.description) {
return html(`${decl.description}\n`);
} else {
return '';
}
})
: [];

return [
...mainDescription,

optionEnabled(omittedSections.mainHeading) ? heading(1 + headingOffset, [inlineCode(mod.path), text(':')]) : null,

...(filteredDeclarations(declarations, omittedDeclarations, classNameFilter).flatMap(decl => {
Expand Down
5 changes: 4 additions & 1 deletion packages/to-markdown/lib/cells.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ function getExportKind(x, options) {
return x.kind ? inlineCode(x.kind) : text('');
}

const formatInline = x =>
x?.replace(/\n/g, '');

export const DECLARATION = { heading: 'Declaration', get: x => x.declaration?.name ?? '' };
export const DEFAULT = { heading: 'Default', get: x => x.default, cellType: inlineCode };
export const DEFAULT = { heading: 'Default', get: x => formatInline(x.default), cellType: inlineCode };
export const NAME = { heading: 'Name', get: x => x.name, cellType: inlineCode };
export const ATTR_FIELD = { heading: 'Field', get: x => x.fieldName };
export const INHERITANCE = { heading: 'Inherited From', get: x => x.inheritedFrom?.name ?? '' };
Expand Down
4 changes: 4 additions & 0 deletions packages/to-markdown/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
"remark-gfm": "^1.0.0",
"remark-stringify": "^9.0.1",
"unified": "^9.2.1"
},
"devDependencies": {
"@asdgf/cli": "https://gitpkg.now.sh/thepassle/asdgf/packages/cli?master",
"esbuild": "^0.19.2"
}
}
2 changes: 1 addition & 1 deletion packages/to-markdown/test/to-markdown.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const MAIN_TEST_CASE_OPTIONS = {
};

const OUTPUT_OPTIONS_TESTS_OPTIONS = {
'no-heading': { omitSections: ['main-heading'] },
'no-heading': { omitSections: ['main-heading','main-description'] },
'class-name-filter': { classNameFilter: 'My*' },
'no-attributes': { omitSections: ['attributes'] },
'no-cssparts': { omitSections: ['css-parts'] },
Expand Down
2 changes: 2 additions & 0 deletions packages/to-markdown/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ enum Declarations {
}

enum Sections {
mainDescription = 'main-description',
mainHeading = 'main-heading',
superClass = 'super-class',
fields = 'fields',
Expand All @@ -29,6 +30,7 @@ type OptionalSections = `${Sections}`;
export interface Options {
private?: 'details'|'hidden'|'all';
headingOffset?: number;
mainDescription?: boolean;
omitSections: OptionalSections[];
omitDeclarations: OptionalDeclarations[];
classNameFilter: string | (() => string);
Expand Down