Skip to content

Commit 878b8be

Browse files
committed
[htmilfy] debug mode, pod pretty printer
1 parent 7f16b18 commit 878b8be

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

htmlify.pl

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,35 @@
66
# this script isn't in bin/ because it's not meant
77
# to be installed.
88

9+
my $*DEBUG = False;
10+
911
my %names;
1012
my %types;
1113
my %routines;
1214

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+
1338
sub recursive-dir($dir) {
1439
my @todo = $dir;
1540
gather while @todo {
@@ -25,7 +50,8 @@
2550
}
2651
}
2752

28-
sub MAIN($out_dir = 'html') {
53+
sub MAIN($out_dir = 'html', Bool :$debug) {
54+
$*DEBUG = $debug;
2955
for ('', <type language routine>) {
3056
mkdir "$out_dir/$_" unless "$out_dir/$_".IO ~~ :e;
3157
}
@@ -47,12 +73,14 @@ ($out_dir = 'html')
4773
shell("perl6 -Ilib --doc=Serialization $_.path() > $tempfile");
4874
# assume just one pod block for now
4975
my ($pod) = eval slurp $tempfile;
76+
say pod-gist($pod) if $*DEBUG;
5077
my @chunks = chunks-grep($pod.content,
5178
:from({ $_ ~~ Pod::Heading and .level == 2}),
5279
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
5380
);
5481
for @chunks -> $chunk {
5582
my $name = $chunk[0].content[0].content[0];
83+
say "$podname.$name" if $*DEBUG;
5684
next if $name ~~ /\s/;
5785
%names{$name}<routine>.push: "/type/$podname.html#" ~ uri_escape($name);
5886
%routines{$name}.push: $podname => $chunk;
@@ -61,10 +89,11 @@ ($out_dir = 'html')
6189
unlink $tempfile;
6290
}
6391
write-index-file(:$out_dir);
92+
say "Writing per-routine files...";
6493
for %routines.kv -> $name, @chunks {
6594
write-routine-file(:$out_dir, :$name, :@chunks);
6695
}
67-
# TODO: write per-routine docs
96+
say "done writing per-routine files";
6897
# TODO: write top-level disambiguation files
6998
}
7099

@@ -155,7 +184,7 @@ ($out_dir = 'html')
155184
}
156185

157186
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;
159188
my $pod = pod-with-title("Documentation for routine $name",
160189
pod-block("Documentation for routine $name, assembled from the
161190
following types:"),

0 commit comments

Comments
 (0)