Skip to content

Commit 8cd73b2

Browse files
authored
Merge pull request #43 from cesarParra/grouping
Grouping support
2 parents 08350ca + da07b79 commit 8cd73b2

File tree

10 files changed

+190
-57
lines changed

10 files changed

+190
-57
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ apexdocs-generate
109109

110110
The CLI supports the following parameters:
111111

112-
| Parameter | Alias | Description | Default | Required |
113-
| ----------------- | ----- | ---------------------------------------------------------------------------------------------------------------- | ----------------------------------- | -------- |
114-
| --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
115-
| --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
116-
| --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
117-
| --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private | `global namespaceaccessible public` | No |
118-
| --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports jekyll and docsify. | `jekyll` | No |
119-
| --configPath | -c | The path to the JSON configuration file that defines the structure of the documents to docGenerator. | N/A | No |
120-
| --group | -o | Define whether the generated files should be grouped by the @group tag on the top level classes. | `true` | No |
112+
| Parameter | Alias | Description | Default | Required |
113+
| ----------------- | ----- |--------------------------------------------------------------------------------------------------------------------------| ----------------------------------- | -------- |
114+
| --sourceDir | -s | The directory location which contains your apex .cls classes. | N/A | Yes |
115+
| --targetDir | -t | The directory location where documentation will be generated to. | `docs` | No |
116+
| --recursive | -r | Whether .cls classes will be searched for recursively in the directory provided. | `true` | No |
117+
| --scope | -p | A list of scopes to document. Values should be separated by a space, e.g --scope public private | `global namespaceaccessible public` | No |
118+
| --targetGenerator | -g | Define the static file generator for which the documents will be created. Currently supports jekyll and docsify. | `jekyll` | No |
119+
| --configPath | -c | (Only versions 1.X) The path to the JSON configuration file that defines the structure of the documents to docGenerator. | N/A | No |
120+
| --group | -o | (Only versions 1.X) Define whether the generated files should be grouped by the @group tag on the top level classes. | `true` | No |
121121

122122
#### Configuration File
123123

@@ -314,6 +314,34 @@ The following tags are supported on the method level:
314314
public static Object call(String action) {
315315
```
316316

317+
### Grouping Declarations Within A Class
318+
319+
A class might have members that should be grouped together. For example, you can have a class for constants with
320+
groups of constants that should be grouped together because they share a common behavior (e.g. different groups
321+
of constants representing the possible values for different picklists.)
322+
323+
You can group things together within a class by using the following syntax:
324+
```apex
325+
// @start-group Group Name or Description
326+
public static final String CONSTANT_FOO = 'Foo';
327+
public static final String CONSTANT_BAR = 'Bar';
328+
// @end-group
329+
```
330+
331+
Groups of members are displayed together under their own subsection after its name or description.
332+
333+
Some notes about grouping:
334+
* This is only supported on classes, NOT enums and interfaces
335+
* Supports
336+
* Properties
337+
* Fields (variables and constants)
338+
* Constructors
339+
* Methods
340+
* BUT only members of the same type are grouped together. For example,
341+
if you have a group that contains properties and methods the properties will be grouped together under Properties -> Group Name, and the methods will be grouped together under Methods -> Group Name
342+
* Does not support inner types (inner classes, interfaces, and enums)
343+
* It is necessary to use `// @end-group` whenever a group has been started, otherwise a parsing error will be raised for that file.
344+
317345
### Inline linking
318346

319347
Apexdocs allows you to reference other classes from anywhere in your docs, and automatically creates a link to that

docs/Sample-Classes/SampleClass.md

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ This is a class description. This class relates to [SampleInterface](/Sample-Int
1717
**See** [SampleInterface](/Sample-Interfaces/SampleInterface.md)
1818

1919
## Constructors
20-
### `SampleClass()`
20+
### My Super Group
21+
##### `SampleClass()`
2122

2223
`NAMESPACEACCESSIBLE`
2324

2425
Constructs a SampleClass without any arguments. This relates to [SampleInterface](/Sample-Interfaces/SampleInterface.md)
2526

26-
#### Throws
27+
###### Throws
2728
|Exception|Description|
2829
|---|---|
2930
|`ExcName`|some exception|
@@ -33,41 +34,45 @@ Constructs a SampleClass without any arguments. This relates to [SampleInterface
3334

3435
**See** [SampleInterface](/Sample-Interfaces/SampleInterface.md)
3536

36-
#### Example
37+
###### Example
3738
```apex
3839
// Example
3940
SampleClass sampleInstance = new SampleClass();
4041
```
4142

42-
### `SampleClass(String argument)`
43+
---
44+
### Other
45+
##### `SampleClass(String argument)`
4346

4447
Constructs a SampleClass with an argument.
4548

46-
#### Parameters
49+
###### Parameters
4750
|Param|Description|
4851
|---|---|
4952
|`argument`|Argument definition|
5053
---
5154
## Fields
55+
### Common Constants
5256

53-
### `A_CONSTANT``String`
54-
55-
This is a constant.
56-
57-
### `someVariable``String`
57+
* `ANOTHER_CONSTANT``String`
58+
* `A_CONSTANT``String` [`NAMESPACEACCESSIBLE` ] - This is a constant.
59+
---
60+
### Other variables
5861

62+
* `someVariable``String`
5963
---
6064
## Properties
6165

6266
### `AnotherProp``Decimal`
6367

64-
`AURAENABLED`
68+
`AURAENABLED`
6569

6670
This is a Decimal property.
6771

6872
### `MyProp``String`
6973

70-
`AURAENABLED`
74+
`AURAENABLED`
75+
`DEPRECATED`
7176

7277
This is a String property.
7378

@@ -122,6 +127,7 @@ Inner class belonging to SampleClass.
122127

123128
##### `InnerProp``String`
124129

130+
125131
Description of the inner property.
126132

127133
---
@@ -140,6 +146,7 @@ Inner class belonging to SampleClass.
140146

141147
##### `InnerProp``String`
142148

149+
143150
Description of the inner property.
144151

145152
---

examples/force-app/main/default/classes/SampleClass.cls

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,20 @@ public with sharing class SampleClass {
1919
C
2020
}
2121

22+
// @start-group Common Constants
2223
/**
2324
* @description This is a constant.
2425
*/
26+
@NamespaceAccessible
2527
public static final String A_CONSTANT = 'My Constant Value';
28+
public static final String ANOTHER_CONSTANT = 'My Constant Value';
29+
// @end-group
30+
31+
// @start-group Other variables
2632
public String someVariable = 'test';
33+
// @end-group
2734

35+
// @start-group My Super Group
2836
/**
2937
* @description Constructs a SampleClass without any arguments. This relates to {@link SampleInterface}
3038
* @throws ExcName some exception
@@ -38,6 +46,7 @@ public with sharing class SampleClass {
3846
public SampleClass() {
3947
System.debug('Constructor');
4048
}
49+
// @end-group
4150

4251
/**
4352
* @description Constructs a SampleClass with an argument.
@@ -73,6 +82,7 @@ public with sharing class SampleClass {
7382
* @description This is a String property.
7483
*/
7584
@AuraEnabled
85+
@Deprecated
7686
public String MyProp { get; set; }
7787

7888
/**

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cparra/apexdocs",
3-
"version": "2.0.2",
3+
"version": "2.1.0",
44
"description": "Library with CLI capabilities to generate documentation for Salesforce Apex classes.",
55
"keywords": [
66
"apex",
@@ -63,7 +63,7 @@
6363
]
6464
},
6565
"dependencies": {
66-
"@cparra/apex-reflection": "^1.0.0",
66+
"@cparra/apex-reflection": "^1.1.1",
6767
"chalk": "^4.1.2",
6868
"html-entities": "^2.3.2",
6969
"yargs": "^16.0.3"

src/model/markdown-file.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export class MarkdownFile extends File {
5555
});
5656
}
5757

58+
addListItem(text: string) {
59+
this._contents += `* ${text}`;
60+
}
61+
5862
protected static replaceInlineLinks(text: string) {
5963
// Parsing text to extract possible linking classes.
6064
const possibleLinks = text.match(/<<.*?>>/g);

src/model/markdown-generation-util/field-declaration-util.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ import { MarkdownFile } from '../markdown-file';
22
import { FieldMirror, PropertyMirror } from '@cparra/apex-reflection';
33

44
export function declareField(
5-
title: string,
65
markdownFile: MarkdownFile,
76
fields: FieldMirror[] | PropertyMirror[],
87
startingHeadingLevel: number,
8+
grouped = false,
99
) {
10-
markdownFile.addTitle(title, startingHeadingLevel + 1);
1110
markdownFile.addBlankLine();
1211
fields
1312
.sort((propA, propB) => {
@@ -16,27 +15,50 @@ export function declareField(
1615
return 0;
1716
})
1817
.forEach((propertyModel) => {
19-
addFieldSection(markdownFile, propertyModel, startingHeadingLevel);
18+
addFieldSection(markdownFile, propertyModel, startingHeadingLevel, grouped);
2019
});
2120

2221
markdownFile.addHorizontalRule();
2322
}
2423

2524
function addFieldSection(
2625
markdownFile: MarkdownFile,
27-
propertyModel: FieldMirror | PropertyMirror,
26+
mirrorModel: FieldMirror | PropertyMirror,
2827
startingHeadingLevel: number,
28+
grouped: boolean,
2929
) {
30-
markdownFile.addTitle(`\`${propertyModel.name}\` → \`${propertyModel.type}\``, startingHeadingLevel + 2);
30+
if (!grouped) {
31+
markdownFile.addTitle(`\`${mirrorModel.name}\` → \`${mirrorModel.type}\``, startingHeadingLevel + 2);
32+
markdownFile.addBlankLine();
33+
34+
mirrorModel.annotations.forEach((annotation) => {
35+
markdownFile.addText(`\`${annotation.type.toUpperCase()}\` `);
36+
});
3137

32-
propertyModel.annotations.forEach((annotation) => {
38+
if (mirrorModel.docComment?.description) {
39+
markdownFile.addBlankLine();
40+
markdownFile.addText(mirrorModel.docComment.description);
41+
}
3342
markdownFile.addBlankLine();
34-
markdownFile.addText(`\`${annotation.type.toUpperCase()}\``);
35-
});
43+
} else {
44+
let annotations = '';
45+
const hasAnnotations = !!mirrorModel.annotations.length;
46+
if (hasAnnotations) {
47+
annotations += ' [';
48+
}
49+
mirrorModel.annotations.forEach((annotation) => {
50+
annotations += `\`${annotation.type.toUpperCase()}\` `;
51+
});
52+
if (hasAnnotations) {
53+
annotations += ']';
54+
}
3655

37-
if (propertyModel.docComment?.description) {
56+
// If grouped we want to display these as a list
57+
let description = '';
58+
if (mirrorModel.docComment?.description) {
59+
description = ` - ${mirrorModel.docComment?.description}`;
60+
}
61+
markdownFile.addListItem(`\`${mirrorModel.name}\` → \`${mirrorModel.type}\`${annotations} ${description}`);
3862
markdownFile.addBlankLine();
39-
markdownFile.addText(propertyModel.docComment.description);
4063
}
41-
markdownFile.addBlankLine();
4264
}

src/model/markdown-generation-util/method-declaration-util.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ import { ParameterMirror } from '@cparra/apex-reflection/index';
44
import { addCustomDocCommentAnnotations } from './doc-comment-annotation-util';
55

66
export function declareMethod(
7-
title: string,
87
markdownFile: MarkdownFile,
98
methods: ConstructorMirror[] | MethodMirror[],
109
startingHeadingLevel: number,
1110
className = '',
1211
): void {
13-
markdownFile.addTitle(title, startingHeadingLevel + 1);
1412
methods.forEach((currentMethod) => {
1513
const signatureName = isMethod(currentMethod) ? (currentMethod as MethodMirror).name : className;
1614
markdownFile.addTitle(`\`${buildSignature(signatureName, currentMethod)}\``, startingHeadingLevel + 2);

src/model/markdown-generation-util/type-declaration-util.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import { MarkdownFile } from '../markdown-file';
22
import { addCustomDocCommentAnnotations } from './doc-comment-annotation-util';
33
import { Annotation, Type } from '@cparra/apex-reflection';
44

5-
export function declareType(markdownFile: MarkdownFile, typeMirror: Type, startingHeadingLevel: number): void {
6-
markdownFile.addTitle(typeMirror.name, startingHeadingLevel);
7-
5+
export function declareType(markdownFile: MarkdownFile, typeMirror: Type): void {
86
typeMirror.annotations.forEach((currentAnnotation: Annotation) => {
97
markdownFile.addBlankLine();
108
markdownFile.addText(`\`${currentAnnotation.type.toUpperCase()}\``);

0 commit comments

Comments
 (0)