1
1
# !/usr/bin/env perl6
2
2
use v6 ;
3
+ use Pod ::To::HTML;
3
4
4
5
# this script isn't in bin/ because it's not meant
5
6
# to be installed.
6
7
8
+ my % names ;
9
+ my % types ;
7
10
my % routines ;
8
11
9
12
sub MAIN ($ out_dir = ' html' ) {
10
13
mkdir $ out_dir unless $ out_dir . IO ~~ : e;
14
+ mkdir " $ out_dir /type" unless " $ out_dir /type" . IO ~~ : e;
11
15
12
16
# TODO: be recursive instead
13
17
my @ source = dir(' lib' ). grep (*. f ). grep (rx {\. pod$ });
@@ -16,12 +20,11 @@ ($out_dir = 'html')
16
20
17
21
for (@ source ) {
18
22
my $ podname = . basename . subst (rx {\. pod$ }, ' ' ). subst (: g, ' /' , ' ::' );
23
+ # XXX just to speed stuff up for index creation debugging
19
24
say " $ _. path () => $ podname" ;
20
- shell (" perl6 --doc=HTML $ _. path () > $ out_dir /$ podname .html" );
21
-
22
- # disable the rest of the processing for now, doesn't
23
- # really do anthing except burning CPU cycles
24
- next ;
25
+ % names {$ podname }<type >. push : " /type/$ podname" ;
26
+ % types {$ podname } = " /type/$ podname" ;
27
+ shell (" perl6 --doc=HTML $ _. path () > $ out_dir /type/$ podname .html" );
25
28
26
29
shell (" perl6 -Ilib --doc=Serialization $ _. path () > $ tempfile" );
27
30
# assume just one pod block for now
@@ -30,11 +33,17 @@ ($out_dir = 'html')
30
33
: from({ $ _ ~~ Pod ::Heading and . level == 2 }),
31
34
: to({ $ ^ b ~~ Pod ::Heading and $ ^ b . level <= $ ^ a . level}),
32
35
);
33
- for @ chunks {
34
- say . perl ;
36
+ for @ chunks -> $ chunk {
37
+ my $ name = $ chunk [0 ]. content[0 ]. content[0 ];
38
+ next if $ name ~~ /\s /;
39
+ % names {$ name }<routine >. push : " /type/$ podname .html#$ name" ;
40
+ % routines {$ name }. push : $ chunk ;
35
41
}
36
42
unlink $ tempfile ;
37
43
}
44
+ write-index-file($ out_dir );
45
+ # TODO: write per-routine docs
46
+ # TODO: write top-level disambiguation files
38
47
}
39
48
40
49
sub chunks-grep (: $ from ! , : & to ! , * @ elems ) {
@@ -53,3 +62,45 @@ ($out_dir = 'html')
53
62
take [@ current ] if @ current ;
54
63
}
55
64
}
65
+
66
+ sub write-index-file ($ out_dir ) {
67
+ my $ pod = Pod ::Block::Named. new (
68
+ name => " pod" ,
69
+ content => Array . new (
70
+ Pod ::Block::Named. new (
71
+ name => " TITLE" ,
72
+ content => Array . new (
73
+ Pod ::Block::Para. new (
74
+ content => [" Perl 6 Documentation" ],
75
+ )
76
+ )
77
+ ),
78
+ Pod ::Block::Para. new (
79
+ content => [' Official Perl 6 documentation' ],
80
+ ),
81
+ # TODO: add more
82
+ Pod ::Heading. new (
83
+ level => 1 ,
84
+ content => Array . new (
85
+ Pod ::Block::Para. new (content => [" Types" ])
86
+ )
87
+ ),
88
+ % types . sort . map : {
89
+ Pod ::Item. new (
90
+ level => 1 ,
91
+ content => [
92
+ Pod ::FormattingCode. new (
93
+ type => ' L' ,
94
+ content => [
95
+ . key ~ ' |' ~ . value ;
96
+ ],
97
+ ),
98
+ ],
99
+ ),
100
+ }
101
+ )
102
+ );
103
+ my $ file = open : w, " $ out_dir /index.html" ;
104
+ $ file . print : pod2html($ pod );
105
+ $ file . close ;
106
+ }
0 commit comments