Skip to content

Commit f76ebf0

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 0407723 commit f76ebf0

File tree

4 files changed

+25
-44
lines changed

4 files changed

+25
-44
lines changed

bin/dev_scripts/PODtoHTML.pm

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,33 +31,39 @@ 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+
conf => 'Config Files',
39+
);
40+
our %macro_names = (
41+
answers => 'Answers',
42+
contexts => 'Contexts',
43+
core => 'Core',
44+
deprecated => 'Deprecated',
45+
graph => 'Graph',
46+
math => 'Math',
47+
misc => 'Miscellaneous',
48+
parsers => 'Parsers',
49+
ui => 'User Interface'
3950
);
4051

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

4556
my @section_list = ref($o{sections}) eq 'ARRAY' ? @{ $o{sections} } : @sections;
46-
my @macros_list = ref($o{macros}) eq 'ARRAY' ? @{ $o{macros} } : ();
4757
my $section_hash = {@section_list};
48-
my $macros_hash = {@macros_list};
4958
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 ] : [];
5159
delete $o{sections};
52-
delete $o{macros};
5360

5461
my $self = {
5562
%o,
5663
idx => {},
5764
section_hash => $section_hash,
5865
section_order => $section_order,
59-
macros_hash => $macros_hash,
60-
macros_order => $macros_order,
66+
macros_hash => {},
6167
};
6268
return bless $self, $class;
6369
}
@@ -141,11 +147,7 @@ sub update_index {
141147
$idx->{macros} = [];
142148
if ($pod_name =~ m!^(.+)/(.+)$!) {
143149
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-
}
150+
push @{ $macros->{$1} }, [ $html_rel_path, $2 ];
149151
} else {
150152
push @{ $idx->{doc} }, [ $html_rel_path, $pod_name ];
151153
}
@@ -171,7 +173,8 @@ sub write_index {
171173
sections => $self->{section_hash},
172174
section_order => $self->{section_order},
173175
macros => $self->{macros_hash},
174-
macros_order => $self->{macros_order},
176+
macros_order => [ sort keys %{ $self->{macros_hash} } ],
177+
macro_names => \%macro_names,
175178
date => strftime('%a %b %e %H:%M:%S %Z %Y', localtime)
176179
}
177180
);

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)