Skip to content
Browse files

htmlify.pl: Factor two major Pod file processing blocks out of MAIN; …

…no functional changes
  • Loading branch information...
1 parent 923f9e1 commit a7d2b13d2f5b187d54610bf3bd5e2716e2e774c8 @japhb japhb committed Sep 4, 2012
Showing with 136 additions and 124 deletions.
  1. +136 −124 htmlify.pl
View
260 htmlify.pl
@@ -115,158 +115,170 @@ (Bool :$debug, Bool :$typegraph = False)
$pod .= [0];
if $what eq 'language' {
- spurt "html/$what/$podname.html", p2h($pod);
- if $podname eq 'operators' {
- 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 $heading = $chunk[0].content[0].content[0];
- next unless $heading ~~ / ^ [in | pre | post | circum | postcircum ] fix | listop /;
- my $what = ~$/;
- my $operator = $heading.split(' ', 2)[1];
- $dr.add-new(
+ write-language-file(:$dr, :$what, :$pod, :$podname);
+ }
+ else {
+ write-type-file(:$dr, :$what, :$pod, :$podname);
+ }
+ }
+
+ say 'Composing doc registry ...';
+ $dr.compose;
+
+ write-disambiguation-files($dr);
+ write-op-disambiguation-files($dr);
+ write-operator-files($dr);
+ write-type-graph-images(:force($typegraph));
+ write-search-file($dr);
+ write-index-file($dr);
+
+ say 'Writing per-routine files ...';
+ my %routine-seen;
+ for $dr.lookup('routine', :by<kind>).list -> $d {
+ next if %routine-seen{$d.name}++;
+ write-routine-file($dr, $d.name);
+ print '.'
+ }
+ say '';
+
+ say 'Processing complete.';
+}
+
+sub write-language-file(:$dr, :$what, :$pod, :$podname) {
+ spurt "html/$what/$podname.html", p2h($pod);
+ if $podname eq 'operators' {
+ 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 $heading = $chunk[0].content[0].content[0];
+ next unless $heading ~~ / ^ [in | pre | post | circum | postcircum ] fix | listop /;
+ my $what = ~$/;
+ my $operator = $heading.split(' ', 2)[1];
+ $dr.add-new(
:kind<operator>,
:subkind($what),
+ :name($operator),
:pod($chunk),
:!pod-is-complete,
- :name($operator),
- );
- }
- }
- $dr.add-new(
+ );
+ }
+ }
+ $dr.add-new(
:kind<language>,
:name($podname),
:$pod,
:pod-is-complete,
- );
+ );
+}
- next;
- }
- $pod = $pod[0];
+sub write-type-file(:$dr, :$what, :$pod, :$podname) {
+ $pod = $pod[0];
+ say pod-gist($pod) if $*DEBUG;
- 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}),
- );
-
- if $tg.types{$podname} -> $t {
- $pod.content.push: Pod::Block::Named.new(
- name => 'Image',
- content => [ "/images/type-graph-$podname.png"],
- );
- $pod.content.push: pod-link(
- 'Full-size type graph image as SVG',
- "/images/type-graph-$podname.svg",
- );
- my @mro = $t.mro;
- @mro.shift; # current type is already taken care of
- for $t.roles -> $r {
+ my @chunks = chunks-grep($pod.content,
+ :from({ $_ ~~ Pod::Heading and .level == 2}),
+ :to({ $^b ~~ Pod::Heading and $^b.level <= $^a.level}),
+ );
+
+ if $tg.types{$podname} -> $t {
+ $pod.content.push: Pod::Block::Named.new(
+ name => 'Image',
+ content => [ "/images/type-graph-$podname.png"],
+ );
+ $pod.content.push: pod-link(
+ 'Full-size type graph image as SVG',
+ "/images/type-graph-$podname.svg",
+ );
+
+ my @mro = $t.mro;
+ @mro.shift; # current type is already taken care of
+
+ for $t.roles -> $r {
+ next unless %methods-by-type{$r};
+ $pod.content.push:
+ pod-heading("Methods supplied by role $r"),
+ pod-block(
+ "$podname does role ",
+ pod-link($r.name, "/type/$r"),
+ ", which provides the following methods:",
+ ),
+ %methods-by-type{$r}.list,
+ ;
+ }
+ for @mro -> $c {
+ next unless %methods-by-type{$c};
+ $pod.content.push:
+ pod-heading("Methods supplied by class $c"),
+ pod-block(
+ "$podname inherits from class ",
+ pod-link($c.name, "/type/$c"),
+ ", which provides the following methods:",
+ ),
+ %methods-by-type{$c}.list,
+ ;
+ for $c.roles -> $r {
next unless %methods-by-type{$r};
$pod.content.push:
pod-heading("Methods supplied by role $r"),
pod-block(
- "$podname does role ",
- pod-link($r.name, "/type/$r"),
- ", which provides the following methods:",
- ),
- %methods-by-type{$r}.list,
- ;
- }
- for @mro -> $c {
- next unless %methods-by-type{$c};
- $pod.content.push:
- pod-heading("Methods supplied by class $c"),
- pod-block(
"$podname inherits from class ",
pod-link($c.name, "/type/$c"),
+ ", which does role ",
+ pod-link($r.name, "/type/$r"),
", which provides the following methods:",
),
- %methods-by-type{$c}.list,
+ %methods-by-type{$r}.list,
;
- for $c.roles -> $r {
- next unless %methods-by-type{$r};
- $pod.content.push:
- pod-heading("Methods supplied by role $r"),
- pod-block(
- "$podname inherits from class ",
- pod-link($c.name, "/type/$c"),
- ", which does role ",
- pod-link($r.name, "/type/$r"),
- ", which provides the following methods:",
- ),
- %methods-by-type{$r}.list,
- ;
- }
}
}
- my $d = $dr.add-new(
- :kind<type>,
- # TODO: subkind
- :$pod,
- :pod-is-complete,
- :name($podname),
- );
+ }
+ my $d = $dr.add-new(
+ :kind<type>,
+ # TODO: subkind
+ :$pod,
+ :pod-is-complete,
+ :name($podname),
+ );
- for @chunks -> $chunk {
- my $name = $chunk[0].content[0].content[0];
- say "$podname.$name" if $*DEBUG;
- next if $name ~~ /\s/;
- %methods-by-type{$podname}.push: $chunk;
- # deterimine whether it's a sub or method
- my Str $subkind;
- {
- my %counter;
- for first-code-block($chunk).lines {
- if ms/^ 'multi'? (sub|method)»/ {
- %counter{$0}++;
- }
- }
- if %counter == 1 {
- ($subkind,) = %counter.keys;
- }
- if %counter<method> {
- write-qualified-method-call(
- :$name,
- :pod($chunk),
- :type($podname),
- );
+ for @chunks -> $chunk {
+ my $name = $chunk[0].content[0].content[0];
+ say "$podname.$name" if $*DEBUG;
+ next if $name ~~ /\s/;
+ %methods-by-type{$podname}.push: $chunk;
+ # determine whether it's a sub or method
+ my Str $subkind;
+ {
+ my %counter;
+ for first-code-block($chunk).lines {
+ if ms/^ 'multi'? (sub|method)»/ {
+ %counter{$0}++;
}
}
-
- $dr.add-new(
- :kind<routine>,
- :$subkind,
- :$name,
- :pod($chunk),
- :!pod-is-complete,
- :origin($d),
- );
+ if %counter == 1 {
+ ($subkind,) = %counter.keys;
+ }
+ if %counter<method> {
+ write-qualified-method-call(
+ :$name,
+ :pod($chunk),
+ :type($podname),
+ );
+ }
}
- spurt "html/$what/$podname.html", p2h($pod);
- }
-
- say 'Composing doc registry ...';
- $dr.compose;
- write-disambiguation-files($dr);
- write-op-disambiguation-files($dr);
- write-operator-files($dr);
- write-type-graph-images(:force($typegraph));
- write-search-file($dr);
- write-index-file($dr);
- say 'Writing per-routine files ...';
- my %routine-seen;
- for $dr.lookup('routine', :by<kind>).list -> $d {
- next if %routine-seen{$d.name}++;
- write-routine-file($dr, $d.name);
- print '.'
+ $dr.add-new(
+ :kind<routine>,
+ :$subkind,
+ :$name,
+ :pod($chunk),
+ :!pod-is-complete,
+ :origin($d),
+ );
}
- say '';
- say 'Processing complete.';
+ spurt "html/$what/$podname.html", p2h($pod);
}
sub chunks-grep(:$from!, :&to!, *@elems) {

0 comments on commit a7d2b13

Please sign in to comment.
Something went wrong with that request. Please try again.