Skip to content

Commit 55384d8

Browse files
authored
Merge pull request #4 from GB609/feature/internal-sections
allow to mark entire sections as `@internal`
2 parents a556a0e + b1318c4 commit 55384d8

File tree

3 files changed

+110
-8
lines changed

3 files changed

+110
-8
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,9 @@ say-hello-world() {
426426
427427
### `@internal`
428428
429-
When you want to skip documentation generation for a particular function, you can specify this
430-
`@internal` tag.
431-
It allows you to have the same style of doc comments across the script and keep internal
432-
functions hidden from users.
429+
When you want to skip documentation generation for a particular function, you can specify this `@internal` tag.
430+
When used in `@section` blocks, all functions until the next `@endsection` or `@section` will be considered internal.
431+
It allows you to have the same style of doc comments across the script and keep internal functions hidden from users.
433432
434433
**Example**
435434

shdoc

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ function process_function(text) {
110110
}
111111

112112
debug("→ function")
113+
if (internal_section){
114+
debug("→ → function: contained in internal section, skip")
115+
return
116+
}
117+
113118
if (is_internal) {
114119
debug("→ → function: it is internal, skip")
115120
is_internal = 0
@@ -242,7 +247,6 @@ function reset() {
242247
function reset_section() {
243248
debug("→ reset_section()")
244249

245-
delete section_docblock
246250
delete docblock_filter
247251
section = ""
248252
section_description = ""
@@ -475,6 +479,13 @@ function process_section() {
475479
debug("→ → no valid section name - skip")
476480
return;
477481
}
482+
if (is_internal){
483+
debug("→ → section marked as internal - skip")
484+
internal_section = 1
485+
is_internal = 0
486+
reset_section();
487+
return;
488+
}
478489

479490
debug("→ → section: [" section "]")
480491
debug("→ → section_description: [" section_description "]")
@@ -658,7 +669,12 @@ function debug(msg) {
658669

659670
/^[[:space:]]*# @internal/ {
660671
debug("→ @internal")
661-
is_internal = 1
672+
# ignore the flag while we are in an internal section
673+
# to prevent dangling values not reset by function blocks
674+
# because internal_section is checked first in process_function
675+
if (!internal_section){
676+
is_internal = 1
677+
}
662678

663679
next
664680
}
@@ -713,13 +729,17 @@ in_description {
713729
section_description = ""
714730
section_active = 0
715731
function_nesting = 2
732+
internal_section = 0
716733

717734
next
718735
}
719736

720737
/^[[:space:]]*# @section/ {
721738
debug("→ @section")
722739
sub(/^[[:space:]]*# @section /, "")
740+
if (internal_section){
741+
internal_section = 0
742+
}
723743
section = $0
724744
section_active = 1
725745
function_nesting = 3
@@ -729,10 +749,8 @@ in_description {
729749

730750
/^[[:space:]]*# @example/ {
731751
debug("→ @example")
732-
733752
in_example = 1
734753

735-
736754
next
737755
}
738756

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Make an entire section internal.
2+
# None of its functions should appear in doc or toc.
3+
# The section itself also shouldn't appear.
4+
# Internal flag should be cleared by starting a next section, or ending the current one.
5+
6+
tests:put input <<EOF
7+
# @name Project Name
8+
# @description Testing @internal on sections...
9+
10+
# @section Section A
11+
# @description line 1
12+
# line 2
13+
# @internal
14+
15+
# @description implicitely internal 1
16+
internal-a() {
17+
}
18+
19+
# @description implicitely internal 2
20+
internal-b() {
21+
22+
}
23+
24+
# @section Must be visible
25+
# @description Resets internal flag by @section
26+
27+
# @description must be visible
28+
b-visible() {
29+
}
30+
31+
# @section Another internal section
32+
# @description terminated by @endsection
33+
# @internal
34+
35+
not-visible() {
36+
}
37+
38+
# @endsection
39+
40+
visible() {
41+
}
42+
43+
# @section public section
44+
# @description with function
45+
46+
# @description must be visible
47+
visible-in-section() {
48+
}
49+
50+
# @endsection
51+
52+
EOF
53+
54+
tests:put expected <<EOF
55+
# Project Name
56+
57+
## Overview
58+
59+
Testing @internal on sections...
60+
61+
## Index
62+
63+
* [Must be visible](#must-be-visible)
64+
* [b-visible](#b-visible)
65+
* [public section](#public-section)
66+
* [visible-in-section](#visible-in-section)
67+
68+
## Must be visible
69+
70+
Resets internal flag by @section
71+
72+
### b-visible
73+
74+
must be visible
75+
76+
## public section
77+
78+
with function
79+
80+
### visible-in-section
81+
82+
must be visible
83+
EOF
84+
85+
assert

0 commit comments

Comments
 (0)