Skip to content

Commit cf64d0c

Browse files
committed
Don't limit macros to predefined lists.
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.
1 parent 74b7713 commit cf64d0c

File tree

4 files changed

+24
-45
lines changed

4 files changed

+24
-45
lines changed

bin/dev_scripts/PODtoHTML.pm

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,38 @@ use POSIX qw(strftime);
3131
use WeBWorK::Utils::PODParser;
3232

3333
our @sections = (
34-
bin => 'Scripts',
35-
conf => 'Config Files',
3634
doc => 'Documentation',
35+
bin => 'Scripts',
36+
macros => 'Macros',
3737
lib => 'Libraries',
38-
macros => 'Macros'
38+
);
39+
our %macro_names = (
40+
answers => 'Answers',
41+
contexts => 'Contexts',
42+
core => 'Core',
43+
deprecated => 'Deprecated',
44+
graph => 'Graph',
45+
math => 'Math',
46+
misc => 'Miscellaneous',
47+
parsers => 'Parsers',
48+
ui => 'User Interface'
3949
);
4050

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

4555
my @section_list = ref($o{sections}) eq 'ARRAY' ? @{ $o{sections} } : @sections;
46-
my @macros_list = ref($o{macros}) eq 'ARRAY' ? @{ $o{macros} } : ();
4756
my $section_hash = {@section_list};
48-
my $macros_hash = {@macros_list};
4957
my $section_order = [ map { $section_list[ 2 * $_ ] } 0 .. $#section_list / 2 ];
50-
my $macros_order = @macros_list ? [ map { $macros_list[ 2 * $_ ] } 0 .. $#macros_list / 2 ] : [];
5158
delete $o{sections};
52-
delete $o{macros};
5359

5460
my $self = {
5561
%o,
5662
idx => {},
5763
section_hash => $section_hash,
5864
section_order => $section_order,
59-
macros_hash => $macros_hash,
60-
macros_order => $macros_order,
65+
macros_hash => {},
6166
};
6267
return bless $self, $class;
6368
}
@@ -140,12 +145,7 @@ sub update_index {
140145
if ($subdir eq 'macros') {
141146
$idx->{macros} = [];
142147
if ($pod_name =~ m!^(.+)/(.+)$!) {
143-
my $macros = $self->{macros_hash};
144-
if ($macros->{$1}) {
145-
push @{ $idx->{$1} }, [ $html_rel_path, $2 ];
146-
} else {
147-
warn "no macro for '$pod_name'\n";
148-
}
148+
push @{ $self->{macros_hash}{$1} }, [ $html_rel_path, $2 ];
149149
} else {
150150
push @{ $idx->{doc} }, [ $html_rel_path, $pod_name ];
151151
}
@@ -171,7 +171,8 @@ sub write_index {
171171
sections => $self->{section_hash},
172172
section_order => $self->{section_order},
173173
macros => $self->{macros_hash},
174-
macros_order => $self->{macros_order},
174+
macros_order => [ sort keys %{ $self->{macros_hash} } ],
175+
macro_names => \%macro_names,
175176
date => strftime('%a %b %e %H:%M:%S %Z %Y', localtime)
176177
}
177178
);

bin/dev_scripts/generate-ww-pg-pod.pl

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -96,39 +96,18 @@ sub process_dir {
9696
my $source_dir = shift;
9797
return unless $source_dir =~ /\/webwork2$/ || $source_dir =~ /\/pg$/;
9898

99-
my $is_pg = $source_dir =~ /\/pg$/;
10099
my $dest_dir = $source_dir;
101-
$dest_dir =~ s/^$webwork_root/$output_dir\/webwork2/ unless $is_pg;
102-
$dest_dir =~ s/^$pg_root/$output_dir\/pg/ if $is_pg;
100+
$dest_dir =~ s/^$webwork_root/$output_dir\/webwork2/ if ($source_dir =~ /\/webwork2$/);
101+
$dest_dir =~ s/^$pg_root/$output_dir\/pg/ if ($source_dir =~ /\/pg$/);
103102

104103
remove_tree($dest_dir);
105104
make_path($dest_dir);
106105

107-
my $sections =
108-
$is_pg
109-
? [ doc => 'Documentation', bin => 'Scripts', macros => 'Macros', lib => 'Libraries' ]
110-
: [ bin => 'Scripts', doc => 'Documentation', lib => 'Libraries' ];
111-
my $macros = $is_pg
112-
? [
113-
core => 'Core',
114-
contexts => 'Contexts',
115-
parsers => 'Parsers',
116-
answers => 'Answers',
117-
graph => 'Graph',
118-
math => 'Math',
119-
ui => 'User Interface',
120-
misc => 'Miscellaneous',
121-
deprecated => 'Deprecated'
122-
]
123-
: [];
124-
125106
my $htmldocs = PODtoHTML->new(
126107
source_root => $source_dir,
127108
dest_root => $dest_dir,
128109
template_dir => "$webwork_root/bin/dev_scripts/pod-templates",
129110
dest_url => $base_url,
130-
sections => $sections,
131-
macros => $macros,
132111
verbose => $verbose
133112
);
134113
$htmldocs->convert_pods;

bin/dev_scripts/pod-templates/category-index.mt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,14 @@
2525
%
2626
% my ($index, $macro_index, $content, $macro_content) = ('', '', '', '');
2727
% for my $macro (@$macros_order) {
28-
% next unless defined $pod_index->{$macro};
2928
% my $new_index = begin
30-
<a href="#macro-<%= $macro %>" class="nav-link"><%= $macros->{$macro} %></a>
29+
<a href="#macro-<%= $macro %>" class="nav-link"><%= $macro_names->{$macro} // $macro %></a>
3130
% end
3231
% $macro_index .= $new_index->();
3332
% my $new_content = begin
34-
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macros->{$macro} %></a></h3>
33+
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macro_names->{$macro} // $macro %></a></h3>
3534
<div class="list-group mb-2">
36-
% for my $file (sort { $a->[1] cmp $b->[1] } @{ $pod_index->{$macro} }) {
35+
% for my $file (sort { $a->[1] cmp $b->[1] } @{ $macros->{$macro} }) {
3736
<a href="<%= $file->[0] %>" class="list-group-item list-group-item-action"><%= $file->[1] %></a>
3837
% }
3938
</div>

templates/ContentGenerator/PODViewer.html.ep

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
</div>
3030
<h2><a href="#_podtop_" id="macros"><%= $section_names{macros} %></a></h2>
3131
% end
32-
% for my $macro (qw(core contexts parsers answers graph math ui misc deprecated)) {
32+
% for my $macro (sort keys %$macros) {
3333
% content_for macros_toc => begin
34-
<%= link_to $macro_names{$macro} => "#macro-$macro", class => 'nav-link' %>
34+
<%= link_to $macro_names{$macro} // $macro => "#macro-$macro", class => 'nav-link' %>
3535
% end
3636
% content_for pod_links => begin
3737
<h3><a href="#_podtop_" id="macro-<%= $macro %>"><%= $macro_names{$macro} %></a></h3>

0 commit comments

Comments
 (0)