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 6, 2024
1 parent dd844c7 commit ea0cbf4
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 14 deletions.
25 changes: 22 additions & 3 deletions lib/WeBWorK/ContentGenerator/PODViewer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,32 @@ sub PODindex ($c) {

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

my $sections = {};
my $docs = [];
my $macros = {};
my $libs = [];
for (sort keys %$podFiles) {
my $section = $_ =~ s/::.*$//r;
push(@{ $sections->{$section} }, $podFiles->{$_} =~ s!^$pgRoot/$section/!!r);
if ($section eq 'doc') {
push(@$docs, $podFiles->{$_} =~ s!^$pgRoot/!!r);
} elsif ($section eq 'lib') {
push(@$libs, $podFiles->{$_} =~ s!^$pgRoot/lib/!!r);
} else {
my $macro = $podFiles->{$_} =~ s!^$pgRoot/macros/(.+)/.+$!$1!r;
if ($macro =~ /^$pgRoot/) {
push(@$docs, $podFiles->{$_} =~ s!^$pgRoot/!!r);
} else {
push(@{ $macros->{$macro} }, $podFiles->{$_} =~ s!^$pgRoot/macros/$macro/!!r);
}
}
}

return $c->render('ContentGenerator/PODViewer', sections => $sections, sidebar_title => $c->maketext('Categories'));
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 ea0cbf4

Please sign in to comment.