@@ -38,7 +38,7 @@ my @menu =
38
38
39
39
my $ head = slurp ' template/head.html' ;
40
40
my $ footer = footer-html;
41
- sub header-html ($ current-selection = ' nothing selected' ) {
41
+ sub header-html ($ current-selection = ' nothing selected' ) is cached {
42
42
state $ header = slurp ' template/header.html' ;
43
43
44
44
my $ menu-items = [~ ]
@@ -139,40 +139,12 @@ sub MAIN(Bool :$debug, Bool :$typegraph = False) {
139
139
140
140
my $ dr = Perl6::Documentable::Registry. new ;
141
141
142
- say ' Reading lib/Language ...' ;
143
- my @ lang-doc-sources =
144
- recursive-dir(' lib/Language/' )\
145
- . map ({; . path . subst (' lib/Language/' , ' ' ). subst (rx {\. pod$ }, ' ' ) => $ _ })\
146
- . sort ;
147
-
148
- say ' Processing Language Pod files ...' ;
149
- for @ lang-doc-sources . kv -> $ num , (: key($ podname ), : value($ file )) {
150
- printf " % 4d/% d : % -40s => % s\n " , $ num , + @ lang-doc-sources , $ file . path , " language/$ podname" ;
151
- my $ pod = EVAL (slurp ($ file . path ) ~ " \n \$=pod" )[0 ];
152
- write-language-file(: $ dr , : what<language >, : $ pod , : $ podname );
153
- }
154
-
155
- # TODO: Abstract this duplication
156
- say ' Reading lib/Type ...' ;
157
- my @ type-doc-sources =
158
- recursive-dir(' lib/Type/' ). grep (*. f )\
159
- . map : {; . path . subst (' lib/Type/' , ' ' ). subst (rx {\. pod$ }, ' ' ). subst (: g, ' /' , ' ::' ) => $ _ };
160
-
161
142
say ' Reading type graph ...' ;
162
143
$ tg = Perl6::TypeGraph. new-from-file(' type-graph.txt' );
163
- {
164
- my % h = $ tg . sorted. kv . flat . reverse ;
165
- @ type-doc-sources .= sort : { % h {. key } // -1 };
166
- }
144
+ my % h = $ tg . sorted. kv . flat . reverse ;
167
145
168
- # TODO: Abstract this duplication as well
169
- say ' Processing Type Pod files ...' ;
170
- for @ type-doc-sources . kv -> $ num , (: key($ podname ), : value($ file )) {
171
- printf " % 4d/% d : % -40s => % s\n " , $ num , + @ type-doc-sources , $ file . path , " type/$ podname" ;
172
- my $ pod = EVAL (slurp ($ file . path ) ~ " \n \$=pod" )[0 ];
173
- say pod-gist($ pod [0 ]) if $ * DEBUG ;
174
- write-type-file(: $ dr , : what<type >, : $ pod , : $ podname );
175
- }
146
+ process-pod-dir ' Language' , : $ dr ;
147
+ process-pod-dir ' Type' , : $ dr : sorted-by{ % h {. key } // -1 };
176
148
177
149
say ' Composing doc registry ...' ;
178
150
$ dr . compose;
@@ -194,7 +166,28 @@ sub MAIN(Bool :$debug, Bool :$typegraph = False) {
194
166
say ' Processing complete.' ;
195
167
}
196
168
197
- sub write-language-file (: $ dr , : $ what , : $ pod , : $ podname ) {
169
+ sub process-pod-dir ($ dir , : $ dr , : & sorted-by = &[cmp ]) {
170
+ say " Reading lib/$ dir ..." ;
171
+ my @ pod-sources =
172
+ recursive-dir(" lib/$ dir /" )\
173
+ . map ({;
174
+ . path . subst (" lib/$ dir /" , ' ' )\
175
+ . subst (rx {\. pod$ }, ' ' )\
176
+ . subst (: g, ' /' , ' ::' )
177
+ => $ _
178
+ }). sort (& sorted-by );
179
+
180
+ say " Processing $ dir Pod files ..." ;
181
+ my $ total = + @ pod-sources ;
182
+ my $ what = $ dir . lc ;
183
+ for @ pod-sources . kv -> $ num , (: key($ podname ), : value($ file )) {
184
+ printf " % 4d/% d : % -40s => % s\n " , $ num , $ total , $ file . path , " $ what /$ podname" ;
185
+ my $ pod = EVAL (slurp ($ file . path ) ~ " \n \$=pod" )[0 ];
186
+ process-pod-file($ what , : $ dr , : what($ what ), : $ pod , : $ podname );
187
+ }
188
+ }
189
+
190
+ multi process-pod-file (" language" , : $ dr , : $ what , : $ pod , : $ podname ) {
198
191
spurt " html/$ what /$ podname .html" , p2h($ pod , $ what );
199
192
my $ name = $ pod . content[0 ]. name eq " TITLE"
200
193
?? $ pod . content[0 ]. content[0 ]. content[0 ]
@@ -229,7 +222,7 @@ sub write-language-file(:$dr, :$what, :$pod, :$podname) {
229
222
}
230
223
}
231
224
232
- sub write-type -file (: $ dr , : $ what , : $ pod , : $ podname ) {
225
+ multi process-pod -file (" type " , : $ dr , : $ what , : $ pod , : $ podname ) {
233
226
my @ chunks = chunks-grep($ pod . content,
234
227
: from({ $ _ ~~ Pod ::Heading and . level == 2 }),
235
228
: to({ $ ^ b ~~ Pod ::Heading and $ ^ b . level <= $ ^ a . level}),
@@ -522,8 +515,6 @@ sub write-search-file($dr) {
522
515
spurt (" html/js/search.js" , $ template . subst (" ITEMS" , $ items ));
523
516
}
524
517
525
- my % operator_disambiguation_file_written ;
526
-
527
518
sub write-disambiguation-files ($ dr ) {
528
519
say ' Writing disambiguation files ...' ;
529
520
for $ dr . grouped-by(' name' ). kv -> $ name , $ p is copy {
@@ -564,10 +555,6 @@ sub write-disambiguation-files($dr) {
564
555
}
565
556
my $ html = p2h($ pod , ' routine' );
566
557
spurt " html/$ name .html" , $ html ;
567
- if all ($ p >>. kind) eq ' operator' {
568
- spurt " html/op/$ name .html" , $ html ;
569
- % operator_disambiguation_file_written {$ p [0 ]. name } = 1 ;
570
- }
571
558
}
572
559
say ' ' ;
573
560
}
@@ -634,8 +621,8 @@ sub write-routine-file($dr, $name) {
634
621
pod-block(" Documentation for $ subkind $ name , assembled from the
635
622
following types:" ),
636
623
@ docs . map ({
637
- pod-heading(" { . name } in { . origin. name } " ), # TODO: better way to get link to origin
638
- pod-block(" From " , pod-link(. origin. name , . origin. url ~ ' #' ~ (. subkinds ~~ / fix / ?? . subkinds~ ' _ ' !! ' ' ) ~ . name )),
624
+ pod-heading(" { . human-kind } { . name } defined in { . origin. human-kind } { . origin . name } " ),
625
+ pod-block(" From " , pod-link(. origin. name , . origin. url ~ ' #' ~ (. subkinds~ ' _ ' if . subkinds ~~ / fix / ) ~ . name )),
639
626
. pod. list,
640
627
})
641
628
);
@@ -648,7 +635,7 @@ sub write-qualified-method-call(:$name!, :$pod!, :$type!) {
648
635
pod-block(' From ' , pod-link($ type , " /type/{ $ type } #$ name" )),
649
636
@$ pod ,
650
637
);
651
- spurt " html/{ $ type } .{ $ name } .html" , p2h($ p , ' routine' );
638
+ spurt " html/routine/ { $ type } .{ $ name } .html" , p2h($ p , ' routine' );
652
639
}
653
640
654
641
sub footer-html () {
0 commit comments