Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[htmilfy] debug mode, pod pretty printer
  • Loading branch information
moritz committed Jul 6, 2012
1 parent 7f16b18 commit 878b8be
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions htmlify.pl
Expand Up @@ -6,10 +6,35 @@
# this script isn't in bin/ because it's not meant
# to be installed.

my $*DEBUG = False;

my %names;
my %types;
my %routines;


sub pod-gist(Pod::Block $pod, $level = 0) {
my $leading = ' ' x $level;
my %confs;
my @chunks;
for <config name level caption type> {
my $thing = $pod.?"$_"();
if $thing {
%confs{$_} = $thing ~~ Iterable ?? $thing.perl !! $thing.Str;
}
}
@chunks = $leading, $pod.^name, (%confs.perl if %confs), "\n";
for $pod.content.list -> $c {
if $c ~~ Pod::Block {
@chunks.push: pod-gist($c, $level + 2);
}
else {
@chunks.push: $c.indent($level + 2), "\n";
}
}
@chunks.join;
}

sub recursive-dir($dir) {
my @todo = $dir;
gather while @todo {
Expand All @@ -25,7 +50,8 @@
}
}

sub MAIN($out_dir = 'html') {
sub MAIN($out_dir = 'html', Bool :$debug) {
$*DEBUG = $debug;
for ('', <type language routine>) {
mkdir "$out_dir/$_" unless "$out_dir/$_".IO ~~ :e;
}
Expand All @@ -47,12 +73,14 @@ ($out_dir = 'html')
shell("perl6 -Ilib --doc=Serialization $_.path() > $tempfile");
# assume just one pod block for now
my ($pod) = eval slurp $tempfile;
say pod-gist($pod) if $*DEBUG;
my @chunks = chunks-grep($pod.content,
:from({ $_ ~~ Pod::Heading and .level == 2}),
:to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
);
for @chunks -> $chunk {
my $name = $chunk[0].content[0].content[0];
say "$podname.$name" if $*DEBUG;
next if $name ~~ /\s/;
%names{$name}<routine>.push: "/type/$podname.html#" ~ uri_escape($name);
%routines{$name}.push: $podname => $chunk;
Expand All @@ -61,10 +89,11 @@ ($out_dir = 'html')
unlink $tempfile;
}
write-index-file(:$out_dir);
say "Writing per-routine files...";
for %routines.kv -> $name, @chunks {
write-routine-file(:$out_dir, :$name, :@chunks);
}
# TODO: write per-routine docs
say "done writing per-routine files";
# TODO: write top-level disambiguation files
}

Expand Down Expand Up @@ -155,7 +184,7 @@ ($out_dir = 'html')
}

sub write-routine-file(:$name!, :$out_dir!, :@chunks!) {
say "Writing $out_dir/routine/$name.html";
say "Writing $out_dir/routine/$name.html" if $*DEBUG;
my $pod = pod-with-title("Documentation for routine $name",
pod-block("Documentation for routine $name, assembled from the
following types:"),
Expand Down

0 comments on commit 878b8be

Please sign in to comment.