6
6
# this script isn't in bin/ because it's not meant
7
7
# to be installed.
8
8
9
+ my $ * DEBUG = False ;
10
+
9
11
my % names ;
10
12
my % types ;
11
13
my % routines ;
12
14
15
+
16
+ sub pod-gist (Pod ::Block $ pod , $ level = 0 ) {
17
+ my $ leading = ' ' x $ level ;
18
+ my % confs ;
19
+ my @ chunks ;
20
+ for <config name level caption type > {
21
+ my $ thing = $ pod .? " $ _" ();
22
+ if $ thing {
23
+ % confs {$ _ } = $ thing ~~ Iterable ?? $ thing . perl !! $ thing . Str ;
24
+ }
25
+ }
26
+ @ chunks = $ leading , $ pod .^ name , (% confs . perl if % confs ), " \n " ;
27
+ for $ pod . content. list -> $ c {
28
+ if $ c ~~ Pod ::Block {
29
+ @ chunks . push : pod-gist($ c , $ level + 2 );
30
+ }
31
+ else {
32
+ @ chunks . push : $ c . indent($ level + 2 ), " \n " ;
33
+ }
34
+ }
35
+ @ chunks . join ;
36
+ }
37
+
13
38
sub recursive-dir ($ dir ) {
14
39
my @ todo = $ dir ;
15
40
gather while @ todo {
25
50
}
26
51
}
27
52
28
- sub MAIN ($ out_dir = ' html' ) {
53
+ sub MAIN ($ out_dir = ' html' , Bool : $ debug ) {
54
+ $ * DEBUG = $ debug ;
29
55
for (' ' , <type language routine >) {
30
56
mkdir " $ out_dir /$ _" unless " $ out_dir /$ _" . IO ~~ : e;
31
57
}
@@ -47,12 +73,14 @@ ($out_dir = 'html')
47
73
shell (" perl6 -Ilib --doc=Serialization $ _. path () > $ tempfile" );
48
74
# assume just one pod block for now
49
75
my ($ pod ) = eval slurp $ tempfile ;
76
+ say pod-gist($ pod ) if $ * DEBUG ;
50
77
my @ chunks = chunks-grep($ pod . content,
51
78
: from({ $ _ ~~ Pod ::Heading and . level == 2 }),
52
79
: to({ $ ^ b ~~ Pod ::Heading and $ ^ b . level <= $ ^ a . level}),
53
80
);
54
81
for @ chunks -> $ chunk {
55
82
my $ name = $ chunk [0 ]. content[0 ]. content[0 ];
83
+ say " $ podname .$ name" if $ * DEBUG ;
56
84
next if $ name ~~ /\s /;
57
85
% names {$ name }<routine >. push : " /type/$ podname .html#" ~ uri_escape($ name );
58
86
% routines {$ name }. push : $ podname => $ chunk ;
@@ -61,10 +89,11 @@ ($out_dir = 'html')
61
89
unlink $ tempfile ;
62
90
}
63
91
write-index-file(: $ out_dir );
92
+ say " Writing per-routine files..." ;
64
93
for % routines . kv -> $ name , @ chunks {
65
94
write-routine-file(: $ out_dir , : $ name , : @ chunks );
66
95
}
67
- # TODO: write per-routine docs
96
+ say " done writing per-routine files " ;
68
97
# TODO: write top-level disambiguation files
69
98
}
70
99
@@ -155,7 +184,7 @@ ($out_dir = 'html')
155
184
}
156
185
157
186
sub write-routine-file (: $ name ! , : $ out_dir ! , : @ chunks ! ) {
158
- say " Writing $ out_dir /routine/$ name .html" ;
187
+ say " Writing $ out_dir /routine/$ name .html" if $ * DEBUG ;
159
188
my $ pod = pod-with-title(" Documentation for routine $ name" ,
160
189
pod-block(" Documentation for routine $ name , assembled from the
161
190
following types:" ),
0 commit comments