Skip to content

Commit

Permalink
Don't limit macros to predefined lists.
Browse files Browse the repository at this point in the history
To keep from having to update the list each time a macro directory
is added/removed/changed, just sort the macros by their directory
alphabetically. There is still a hash of macro names to allow both
translated or custom names instead of using the directory as its
name, but any directory that isn't in the list will also be included
without updating the list.
  • Loading branch information
somiaj committed Dec 10, 2024
1 parent 74b7713 commit cf64d0c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 45 deletions.
33 changes: 17 additions & 16 deletions bin/dev_scripts/PODtoHTML.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,38 @@ use POSIX qw(strftime);
use WeBWorK::Utils::PODParser;

our @sections = (
bin => 'Scripts',
conf => 'Config Files',
doc => 'Documentation',
bin => 'Scripts',
macros => 'Macros',
lib => 'Libraries',
macros => 'Macros'
);
our %macro_names = (
answers => 'Answers',
contexts => 'Contexts',
core => 'Core',
deprecated => 'Deprecated',
graph => 'Graph',
math => 'Math',
misc => 'Miscellaneous',
parsers => 'Parsers',
ui => 'User Interface'
);

sub new {
my ($invocant, %o) = @_;
my $class = ref $invocant || $invocant;

my @section_list = ref($o{sections}) eq 'ARRAY' ? @{ $o{sections} } : @sections;
my @macros_list = ref($o{macros}) eq 'ARRAY' ? @{ $o{macros} } : ();
my $section_hash = {@section_list};
my $macros_hash = {@macros_list};
my $section_order = [ map { $section_list[ 2 * $_ ] } 0 .. $#section_list / 2 ];
my $macros_order = @macros_list ? [ map { $macros_list[ 2 * $_ ] } 0 .. $#macros_list / 2 ] : [];
delete $o{sections};
delete $o{macros};

my $self = {
%o,
idx => {},
section_hash => $section_hash,
section_order => $section_order,
macros_hash => $macros_hash,
macros_order => $macros_order,
macros_hash => {},
};
return bless $self, $class;
}
Expand Down Expand Up @@ -140,12 +145,7 @@ sub update_index {
if ($subdir eq 'macros') {
$idx->{macros} = [];
if ($pod_name =~ m!^(.+)/(.+)$!) {
my $macros = $self->{macros_hash};
if ($macros->{$1}) {
push @{ $idx->{$1} }, [ $html_rel_path, $2 ];
} else {
warn "no macro for '$pod_name'\n";
}
push @{ $self->{macros_hash}{$1} }, [ $html_rel_path, $2 ];
} else {
push @{ $idx->{doc} }, [ $html_rel_path, $pod_name ];
}
Expand All @@ -171,7 +171,8 @@ sub write_index {
sections => $self->{section_hash},
section_order => $self->{section_order},
macros => $self->{macros_hash},
macros_order => $self->{macros_order},
macros_order => [ sort keys %{ $self->{macros_hash} } ],
macro_names => \%macro_names,
date => strftime('%a %b %e %H:%M:%S %Z %Y', localtime)
}
);
Expand Down
25 changes: 2 additions & 23 deletions bin/dev_scripts/generate-ww-pg-pod.pl
Original file line number Diff line number Diff line change
Expand Up @@ -96,39 +96,18 @@ sub process_dir {
my $source_dir = shift;
return unless $source_dir =~ /\/webwork2$/ || $source_dir =~ /\/pg$/;

my $is_pg = $source_dir =~ /\/pg$/;
my $dest_dir = $source_dir;
$dest_dir =~ s/^$webwork_root/$output_dir\/webwork2/ unless $is_pg;
$dest_dir =~ s/^$pg_root/$output_dir\/pg/ if $is_pg;
$dest_dir =~ s/^$webwork_root/$output_dir\/webwork2/ if ($source_dir =~ /\/webwork2$/);
$dest_dir =~ s/^$pg_root/$output_dir\/pg/ if ($source_dir =~ /\/pg$/);

remove_tree($dest_dir);
make_path($dest_dir);

my $sections =
$is_pg
? [ doc => 'Documentation', bin => 'Scripts', macros => 'Macros', lib => 'Libraries' ]
: [ bin => 'Scripts', doc => 'Documentation', lib => 'Libraries' ];
my $macros = $is_pg
? [
core => 'Core',
contexts => 'Contexts',
parsers => 'Parsers',
answers => 'Answers',
graph => 'Graph',
math => 'Math',
ui => 'User Interface',
misc => 'Miscellaneous',
deprecated => 'Deprecated'
]
: [];

my $htmldocs = PODtoHTML->new(
source_root => $source_dir,
dest_root => $dest_dir,
template_dir => "$webwork_root/bin/dev_scripts/pod-templates",
dest_url => $base_url,
sections => $sections,
macros => $macros,
verbose => $verbose
);
$htmldocs->convert_pods;
Expand Down
7 changes: 3 additions & 4 deletions bin/dev_scripts/pod-templates/category-index.mt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@
%
% my ($index, $macro_index, $content, $macro_content) = ('', '', '', '');
% for my $macro (@$macros_order) {
% next unless defined $pod_index->{$macro};
% my $new_index = begin
<a href="#macro-<%= $macro %>" class="nav-link"><%= $macros->{$macro} %></a>
<a href="#macro-<%= $macro %>" class="nav-link"><%= $macro_names->{$macro} // $macro %></a>
% end
% $macro_index .= $new_index->();
% my $new_content = begin
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macros->{$macro} %></a></h3>
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macro_names->{$macro} // $macro %></a></h3>
<div class="list-group mb-2">
% for my $file (sort { $a->[1] cmp $b->[1] } @{ $pod_index->{$macro} }) {
% for my $file (sort { $a->[1] cmp $b->[1] } @{ $macros->{$macro} }) {
<a href="<%= $file->[0] %>" class="list-group-item list-group-item-action"><%= $file->[1] %></a>
% }
</div>
Expand Down
4 changes: 2 additions & 2 deletions templates/ContentGenerator/PODViewer.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
</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)) {
% for my $macro (sort keys %$macros) {
% content_for macros_toc => begin
<%= link_to $macro_names{$macro} => "#macro-$macro", class => 'nav-link' %>
<%= link_to $macro_names{$macro} // $macro => "#macro-$macro", class => 'nav-link' %>
% end
% content_for pod_links => begin
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macro_names{$macro} %></a></h3>
Expand Down

0 comments on commit cf64d0c

Please sign in to comment.