Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #408 from azawawi/master
Add 5to6-perlfunc functions to search index
  • Loading branch information
azawawi committed Mar 4, 2016
2 parents 997e03d + a406f32 commit 7b7d42d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -9,3 +9,4 @@ html/language/
html/syntax/
html/images/type-graph*
html/js/search.js
.precomp
28 changes: 25 additions & 3 deletions htmlify.p6
Expand Up @@ -35,6 +35,7 @@ use experimental :pack;
my $type-graph;
my %routines-by-type;
my %*POD2HTML-CALLBACKS;
my %p5to6-functions;

# TODO: Generate menulist automatically
my @menu =
Expand Down Expand Up @@ -227,6 +228,11 @@ sub process-pod-source(:$kind, :$pod, :$filename, :$pod-is-complete) {

find-definitions :$pod, :$origin, :url("/$kind/$filename");
find-references :$pod, :$origin, :url("/$kind/$filename");

# Special handling for 5to6-perlfunc
if $filename eq '5to6-perlfunc' {
find-p5to6-functions( :$pod, :$origin, :url("/$kind/$filename"))
}
}

# XXX: Generalize
Expand Down Expand Up @@ -320,6 +326,18 @@ sub find-references(:$pod!, :$url, :$origin) {
}
}

sub find-p5to6-functions(:$pod!, :$url, :$origin) {
if $pod ~~ Pod::Item {
my $func-name = ~$pod.contents[0].contents;
%p5to6-functions{$func-name} = 1;
}
elsif $pod.?contents {
for $pod.contents -> $sub-pod {
find-p5to6-functions(:pod($sub-pod), :$url, :$origin) if $sub-pod ~~ Pod::Block;
}
}
}

sub register-reference(:$pod!, :$origin, :$url) {
if $pod.meta {
for @( $pod.meta ) -> $meta {
Expand Down Expand Up @@ -602,15 +620,19 @@ sub write-search-file () {
sub escape(Str $s) {
$s.trans([</ \\ ">] => [<\\/ \\\\ \\">]);
}
my $items = $*DR.get-kinds.map(-> $kind {
my @items = $*DR.get-kinds.map(-> $kind {
$*DR.lookup($kind, :by<kind>).categorize({escape .name})\
.pairs.sort({.key}).map: -> (:key($name), :value(@docs)) {
qq[[\{ category: "{
( @docs > 1 ?? $kind !! @docs.[0].subkinds[0] ).wordcase
}", value: "$name", url: "{@docs.[0].url}" \}]] #"
}
}).flat.join(",\n");
spurt("html/js/search.js", $template.subst("ITEMS", $items));
}).flat;
@items.append( %p5to6-functions.keys.map( {
my $url = "/language/5to6-perlfunc.html#" ~ uri_escape($_);
sprintf( q[[{ category: "5to6-perlfunc", value: "%s", url: "%s" }]], $_, $url);
}) );
spurt("html/js/search.js", $template.subst("ITEMS", @items.join(",\n") ));
}

sub write-disambiguation-files () {
Expand Down

0 comments on commit 7b7d42d

Please sign in to comment.