10
10
my % routines ;
11
11
12
12
sub MAIN ($ out_dir = ' html' ) {
13
- for (' ' , <type language >) {
13
+ for (' ' , <type language routine >) {
14
14
mkdir " $ out_dir /$ _" unless " $ out_dir /$ _" . IO ~~ : e;
15
15
}
16
16
@@ -39,11 +39,14 @@ ($out_dir = 'html')
39
39
my $ name = $ chunk [0 ]. content[0 ]. content[0 ];
40
40
next if $ name ~~ /\s /;
41
41
% names {$ name }<routine >. push : " /type/$ podname .html#$ name" ;
42
- % routines {$ name }. push : $ chunk ;
42
+ % routines {$ name }. push : $ podname => $ chunk ;
43
43
}
44
44
unlink $ tempfile ;
45
45
}
46
- write-index-file($ out_dir );
46
+ write-index-file(: $ out_dir );
47
+ for % routines . kv -> $ name , @ chunks {
48
+ write-routine-file(: $ out_dir , : $ name , : @ chunks );
49
+ }
47
50
# TODO: write per-routine docs
48
51
# TODO: write top-level disambiguation files
49
52
}
@@ -65,63 +68,82 @@ ($out_dir = 'html')
65
68
}
66
69
}
67
70
68
- sub write-index-file ( $ out_dir ) {
69
- my $ pod = Pod ::Block::Named. new (
71
+ sub pod-with-title ( $ title , * @ blocks ) {
72
+ Pod ::Block::Named. new (
70
73
name => " pod" ,
71
- content => Array . new (
74
+ content => [
72
75
Pod ::Block::Named. new (
73
76
name => " TITLE" ,
74
77
content => Array . new (
75
78
Pod ::Block::Para. new (
76
- content => [" Perl 6 Documentation " ],
79
+ content => [$ title ],
77
80
)
78
81
)
79
82
),
80
- Pod ::Block::Para. new (
81
- content => [' Official Perl 6 documentation' ],
82
- ),
83
- # TODO: add more
84
- Pod ::Heading. new (
85
- level => 1 ,
86
- content => Array . new (
87
- Pod ::Block::Para. new (content => [" Language Documentation" ])
88
- )
89
- ),
90
- % types <language >. pairs . sort . map ({
91
- Pod ::Item. new (
92
- level => 1 ,
93
- content => [
94
- Pod ::FormattingCode. new (
95
- type => ' L' ,
96
- content => [
97
- . key ~ ' |' ~ . value ;
98
- ],
99
- ),
100
- ],
101
- );
102
- }),
103
- Pod ::Heading. new (
104
- level => 1 ,
105
- content => Array . new (
106
- Pod ::Block::Para. new (content => [" Types" ])
107
- )
108
- ),
109
- % types <type >. sort . map ({
110
- Pod ::Item. new (
111
- level => 1 ,
112
- content => [
113
- Pod ::FormattingCode. new (
114
- type => ' L' ,
115
- content => [
116
- . key ~ ' |' ~ . value ;
117
- ],
118
- ),
119
- ],
120
- ),
121
- }),
122
- )
83
+ @ blocks ,
84
+ ]
85
+ );
86
+ }
87
+
88
+ sub pod-block (* @ content ) {
89
+ Pod ::Block::Para. new (: @ content );
90
+ }
91
+
92
+ sub pod-link ($ text , $ url ) {
93
+ Pod ::FormattingCode. new (
94
+ type => ' L' ,
95
+ content => [
96
+ join (' |' , $ text , $ url ),
97
+ ],
98
+ );
99
+ }
100
+
101
+ sub pod-item (* @ content , : $ level = 1 ) {
102
+ Pod ::Item. new (
103
+ : $ level ,
104
+ : @ content ,
105
+ );
106
+ }
107
+
108
+ sub pod-heading ($ name , : $ level = 1 ) {
109
+ Pod ::Heading. new (
110
+ : $ level ,
111
+ : content[pod-block($ name )],
112
+ );
113
+ }
114
+
115
+ sub write-index-file (: $ out_dir ! ) {
116
+ say " Writing $ out_dir /index.html" ;
117
+ my $ pod = pod-with-title(' Perl 6 Documentation' ,
118
+ Pod ::Block::Para. new (
119
+ content => [' Official Perl 6 documentation' ],
120
+ ),
121
+ # TODO: add more
122
+ pod-heading(" Language Documentation" ),
123
+ % types <language >. pairs . sort . map ({
124
+ pod-item( pod-link(. key , . value ) )
125
+ }),
126
+ pod-heading(' Types' ),
127
+ % types <type >. sort . map ({
128
+ pod-item(pod-link(. key , . value ))
129
+ }),
123
130
);
124
131
my $ file = open : w, " $ out_dir /index.html" ;
125
132
$ file . print : pod2html($ pod );
126
133
$ file . close ;
127
134
}
135
+
136
+ sub write-routine-file (: $ name ! , : $ out_dir ! , : @ chunks ! ) {
137
+ say " Writing $ out_dir /routine/$ name .html" ;
138
+ my $ pod = pod-with-title(" Documentation for routine $ name" ,
139
+ pod-block(" Documentation for routine $ name , assembled from the
140
+ following types:" ));
141
+ $ pod . content. push : @ chunks . map (-> Pair (: key($ type ), : value($ chunk )) {
142
+ pod-heading($ type ),
143
+ pod-block(" From " , pod-link($ type , " /type/{ $ type } #$ name" )),
144
+ @$ chunk
145
+ });
146
+ my $ file = open : w, " $ out_dir /routine/$ name .html" ;
147
+ $ file . print : pod2html($ pod );
148
+ $ file . close ;
149
+ }
0 commit comments