Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Simplify &write-search-file
  • Loading branch information
Mouq committed Feb 7, 2015
1 parent ea1ce1f commit 2774c81
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
28 changes: 8 additions & 20 deletions htmlify.p6
Expand Up @@ -138,7 +138,7 @@ sub MAIN(

for $*DR.lookup("language", :by<kind>).list {
say "Writing language document for {.name} ...";
spurt "html/language/{.filename}.html", p2h(.pod, 'language');
spurt "html{.url}.html", p2h(.pod, 'language');
}
for $*DR.lookup("type", :by<kind>).list {
write-type-source $_;
Expand Down Expand Up @@ -213,9 +213,9 @@ sub process-pod-source(:$kind, :$pod, :$filename, :$pod-is-complete) {
:$name,
:$pod,
:url("/$kind/$filename"),
:$filename,
:$summary,
:$pod-is-complete,
:subkinds($kind),
|%type-info,
);

Expand Down Expand Up @@ -516,28 +516,16 @@ sub viz-hints ($group) {
sub write-search-file () {
say 'Writing html/js/search.js ...';
my $template = slurp("template/search_template.js");
my @items;
sub escape(Str $s) {
$s.trans([</ \\ ">] => [<\\/ \\\\ \\">]);
}
@items.push: $*DR.lookup('language', :by<kind>).sort(*.name).map({
qq[\{ label: "Language: {.name}", value: "{.name}", url: "{.url}" \}]
});
@items.push: $*DR.lookup('type', :by<kind>).sort(*.name).map({
qq[\{ label: "Type: {.name}", value: "{.name}", url: "{.url}" \}]
});
@items.push: $*DR.lookup('routine', :by<kind>).unique(:as{.name}).sort(*.name).map({
do for .subkinds // 'Routine' -> $subkind {
qq[\{ label: "{ $subkind.tclc }: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
my $items = <language type routine syntax>.map({
$*DR.lookup($_, :by<kind>).unique(:as{.name}).sort({.name})
}).flat.map({
.subkinds.map: -> $subkind {
qq[\{ label: "{$subkind.wordcase}: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
}
});
@items.push: $*DR.lookup('syntax', :by<kind>).sort(*.name).map({
do for .subkinds // 'Syntax' -> $subkind {
qq[\{ label: "{ $subkind.tclc }: {escape .name}", value: "{escape .name}", url: "{.url}" \}]
}
});

my $items = @items.join(",\n");
}).join(",\n");
spurt("html/js/search.js", $template.subst("ITEMS", $items));
}

Expand Down
6 changes: 0 additions & 6 deletions lib/Perl6/Documentable.pm
Expand Up @@ -6,7 +6,6 @@ class Perl6::Documentable {

has Str $.name;
has Str $.url;
has Str $.filename;
has $.pod;
has Bool $.pod-is-complete;
has Str $.summary = '';
Expand All @@ -27,11 +26,6 @@ class Perl6::Documentable {
!! english-list @.subkinds // $.kind;
}

method filename() {
$!filename //= $.kind eq 'operator'
?? "html/language/operators.html"
!! "html/$.kind/$.name.html";
}
method url() {
$!url //= $.kind eq 'operator'
?? "/language/operators#" ~ uri_escape("@.subkinds[] $.name".subst(/\s+/, '_', :g))
Expand Down

0 comments on commit 2774c81

Please sign in to comment.