Skip to content

Commit 2774c81

Browse files
committed
Simplify &write-search-file
1 parent ea1ce1f commit 2774c81

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

htmlify.p6

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ sub MAIN(
138138

139139
for $*DR.lookup("language", :by<kind>).list {
140140
say "Writing language document for {.name} ...";
141-
spurt "html/language/{.filename}.html", p2h(.pod, 'language');
141+
spurt "html{.url}.html", p2h(.pod, 'language');
142142
}
143143
for $*DR.lookup("type", :by<kind>).list {
144144
write-type-source $_;
@@ -213,9 +213,9 @@ sub process-pod-source(:$kind, :$pod, :$filename, :$pod-is-complete) {
213213
:$name,
214214
:$pod,
215215
:url("/$kind/$filename"),
216-
:$filename,
217216
:$summary,
218217
:$pod-is-complete,
218+
:subkinds($kind),
219219
|%type-info,
220220
);
221221

@@ -516,28 +516,16 @@ sub viz-hints ($group) {
516516
sub write-search-file () {
517517
say 'Writing html/js/search.js ...';
518518
my $template = slurp("template/search_template.js");
519-
my @items;
520519
sub escape(Str $s) {
521520
$s.trans([</ \\ ">] => [<\\/ \\\\ \\">]);
522521
}
523-
@items.push: $*DR.lookup('language', :by<kind>).sort(*.name).map({
524-
qq[\{ label: "Language: {.name}", value: "{.name}", url: "{.url}" \}]
525-
});
526-
@items.push: $*DR.lookup('type', :by<kind>).sort(*.name).map({
527-
qq[\{ label: "Type: {.name}", value: "{.name}", url: "{.url}" \}]
528-
});
529-
@items.push: $*DR.lookup('routine', :by<kind>).unique(:as{.name}).sort(*.name).map({
530-
do for .subkinds // 'Routine' -> $subkind {
531-
qq[\{ label: "{ $subkind.tclc }: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
522+
my $items = <language type routine syntax>.map({
523+
$*DR.lookup($_, :by<kind>).unique(:as{.name}).sort({.name})
524+
}).flat.map({
525+
.subkinds.map: -> $subkind {
526+
qq[\{ label: "{$subkind.wordcase}: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
532527
}
533-
});
534-
@items.push: $*DR.lookup('syntax', :by<kind>).sort(*.name).map({
535-
do for .subkinds // 'Syntax' -> $subkind {
536-
qq[\{ label: "{ $subkind.tclc }: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
537-
}
538-
});
539-
540-
my $items = @items.join(",\n");
528+
}).join(",\n");
541529
spurt("html/js/search.js", $template.subst("ITEMS", $items));
542530
}
543531

lib/Perl6/Documentable.pm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class Perl6::Documentable {
66

77
has Str $.name;
88
has Str $.url;
9-
has Str $.filename;
109
has $.pod;
1110
has Bool $.pod-is-complete;
1211
has Str $.summary = '';
@@ -27,11 +26,6 @@ class Perl6::Documentable {
2726
!! english-list @.subkinds // $.kind;
2827
}
2928

30-
method filename() {
31-
$!filename //= $.kind eq 'operator'
32-
?? "html/language/operators.html"
33-
!! "html/$.kind/$.name.html";
34-
}
3529
method url() {
3630
$!url //= $.kind eq 'operator'
3731
?? "/language/operators#" ~ uri_escape("@.subkinds[] $.name".subst(/\s+/, '_', :g))

0 commit comments

Comments
 (0)