Skip to content

Commit

Permalink
Split up macros on PODViewer index page.
Browse files Browse the repository at this point in the history
This splits up the macros on the PODViwer index page to be
grouped by their location in the `pg/macros` directory. In addition
macros are listed before the libraries. The two macros not in a
subdirectory, `PG.pl` and `PGcourse.pl`, are grouped with the pod
in `pg/doc`. This makes finding the POD for a specific macro easier.
  • Loading branch information
somiaj committed Nov 11, 2024
1 parent 22b6dbf commit 0c563c9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 17 deletions.
33 changes: 27 additions & 6 deletions lib/WeBWorK/ContentGenerator/PODViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,36 @@ use WeBWorK::Utils::PODParser;
sub PODindex ($c) {
my $pgRoot = $c->ce->{pg_dir};

my $podFiles = Pod::Simple::Search->new->inc(0)->limit_re(qr/^doc|^lib|^macros/)->survey($pgRoot);
my $docFiles = Pod::Simple::Search->new->inc(0)->survey("$pgRoot/doc");
my $macroFiles = Pod::Simple::Search->new->inc(0)->survey("$pgRoot/macros");
my $libFiles = Pod::Simple::Search->new->inc(0)->survey("$pgRoot/lib");

my $sections = {};
for (sort keys %$podFiles) {
my $section = $_ =~ s/::.*$//r;
push(@{ $sections->{$section} }, $podFiles->{$_} =~ s!^$pgRoot/$section/!!r);
my $docs = [];
for (sort keys %$docFiles) {
push(@$docs, $docFiles->{$_} =~ s!^$pgRoot/!!r);
}

return $c->render('ContentGenerator/PODViewer', sections => $sections, sidebar_title => $c->maketext('Categories'));
my $macros = {};
for (sort keys %$macroFiles) {
if ($macroFiles->{$_} =~ m!^$pgRoot/macros/(.+)/.+$!) {
push(@{ $macros->{$1} }, $macroFiles->{$_} =~ s!^$pgRoot/macros/$1/!!r);
} else {
push(@$docs, $macroFiles->{$_} =~ s!^$pgRoot/!!r);
}
}

my $libs = [];
for (sort keys %$libFiles) {
push(@$libs, $libFiles->{$_} =~ s!^$pgRoot/lib/!!r);
}

return $c->render(
'ContentGenerator/PODViewer',
docs => $docs,
macros => $macros,
libs => $libs,
sidebar_title => $c->maketext('Categories')
);
}

sub renderPOD ($c) {
Expand Down
58 changes: 47 additions & 11 deletions templates/ContentGenerator/PODViewer.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,62 @@
% lib => maketext('Libraries'),
% macros => maketext('Macros')
% );
% my %macro_names = (
% answers => maketext('Answers'),
% contexts => maketext('Contexts'),
% core => maketext('Core'),
% deprecated => maketext('Deprecated'),
% graph => maketext('Graph'),
% math => maketext('Math'),
% misc => maketext('Miscellaneous'),
% parsers => maketext('Parsers'),
% ui => maketext('User Interface')
% );
%
% for my $section (sort keys %$sections) {
% content_for toc => begin
<%= link_to $section_names{$section} => "#$section", class => 'nav-link' %>
% content_for pod_links => begin
<h2><a href="#_podtop_" id="doc"><%= $section_names{doc} %></a></h2>
<div class="list-group mb-2">
% for (@$docs) {
% my $link_name = $_ =~ s!^(doc|macros)/!!r;
<%= link_to $link_name, 'pod_viewer', { filePath => "$_" },
class => 'list-group-item list-group-item-action' =%>
% }
</div>
<h2><a href="#_podtop_" id="macros"><%= $section_names{macros} %></a></h2>
% end
% for my $macro (qw(core contexts parsers answers graph math ui misc deprecated)) {
% content_for macros_toc => begin
<%= link_to $macro_names{$macro} => "#macro-$macro", class => 'nav-link' %>
% end
% content_for subjects => begin
<h2><a href="#_podtop_" id="<%= $section %>"><%= $section_names{$section} %></a></h2>
% content_for pod_links => begin
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macro_names{$macro} %></a></h3>
<div class="list-group mb-2">
% for (@{ $sections->{$section} }) {
% my $link_name = $_;
% $link_name = $1 =~ s!/!::!gr if $link_name =~ m/^(.*)\.pm$/;
<%= link_to $link_name, 'pod_viewer', { filePath => "$section/$_" },
% for (@{ $macros->{$macro} }) {
<%= link_to $_, 'pod_viewer', { filePath => "macros/$macro/$_" },
class => 'list-group-item list-group-item-action' =%>
% }
</div>
% end
% }
% content_for pod_links => begin
<h2><a href="#_podtop_" id="lib"><%= $section_names{lib} %></a></h2>
<div class="list-group mb-2">
% for (@$libs) {
% my $link_name = $_;
% $link_name = $1 =~ s!/!::!gr if $link_name =~ m/^(.*)\.pm$/;
<%= link_to $link_name, 'pod_viewer', { filePath => "lib/$_" },
class => 'list-group-item list-group-item-action' =%>
% }
</div>
% end
% content_for sidebar => begin
<nav class="nav flex-column w-100">
<%= content 'toc' %>
<%= link_to $section_names{doc} => '#doc', class => 'nav-link' %>
<%= link_to $section_names{macros} => '#macros', class => 'nav-link' %>
<div class="nav flex-column ms-3">
<%= content 'macros_toc' %>
</div>
<%= link_to $section_names{lib} => '#lib', class => 'nav-link' %>
</nav>
% end
<%= content 'subjects' %>
<%= content 'pod_links' %>

0 comments on commit 0c563c9

Please sign in to comment.