Modal: html/svg

main
parent 00b60dc9f6
commit eeda14fc62
  1. 52
      wiki-tile.pl

@ -24,8 +24,9 @@ my $border_width = 1;
my $border_colour = 'black'; my $border_colour = 'black';
my $show_coords = 0; my $show_coords = 0;
my $interactive = 1; my $html_document = 1;
my $do_subregions = 1; my $outfile = '-';
my $regiondir;
GetOptions GetOptions
( (
@ -39,8 +40,9 @@ GetOptions
'border-colour|border-color|bc=s' => \$border_colour, 'border-colour|border-color|bc=s' => \$border_colour,
'show-coords|coords!' => \$show_coords, 'show-coords|coords!' => \$show_coords,
'interactive|s!' => \$interactive, 'html-document!' => \$html_document,
'subregions!|sub' => \$do_subregions 'outfile=s' => \$outfile,
'regiondir=s' => \$regiondir
); );
my $grid = HexGrid->new(defaults => { my $grid = HexGrid->new(defaults => {
@ -71,7 +73,7 @@ foreach my $page (values %{$region_query_results->{query}{pages}})
my $region = $grid->make_region($page->{title}); my $region = $grid->make_region($page->{title});
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name); my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name);
$region->{defaults}{colour} = $parsed_template->{named_params}{colour}; $region->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($do_subregions) if($regiondir)
{ {
$region_grids{$page->{title}} = HexGrid->new $region_grids{$page->{title}} = HexGrid->new
( (
@ -110,7 +112,7 @@ foreach my $page (values %{$subregion_query_results->{query}{pages}})
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name); my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name);
my $subregion = $grid->make_region($page->{title}); my $subregion = $grid->make_region($page->{title});
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour}; $subregion->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($do_subregions) if($regiondir)
{ {
my $region_name = $parsed_template->{positional_params}[0]; my $region_name = $parsed_template->{positional_params}[0];
$region_grids{$region_name}->add_region($subregion); $region_grids{$region_name}->add_region($subregion);
@ -186,7 +188,7 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
my $location = $grid->make_region($page->{title}); my $location = $grid->make_region($page->{title});
my $location_with_context; my $location_with_context;
if($do_subregions) if($regiondir)
{ {
$region_grids{$location->{name}} = HexGrid->new $region_grids{$location->{name}} = HexGrid->new
( (
@ -207,7 +209,7 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/) if($parsed_template->{positional_params}[0] =~ /^\s*(-?\s*\d+)\s*,\s*(-?\s*\d+)\s*$/)
{ {
$location->make_tile_at($1,$2); $location->make_tile_at($1,$2);
if($do_subregions) if($regiondir)
{ {
$location_with_context->make_tile_at($1,$2); $location_with_context->make_tile_at($1,$2);
foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles}) foreach my $coords (split /;/, $parsed_template->{named_params}{context_tiles})
@ -220,7 +222,7 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
} }
} }
if($do_subregions) if($regiondir)
{ {
my $region_name = $parsed_template->{positional_params}[1]; my $region_name = $parsed_template->{positional_params}[1];
$region_grids{$region_name}->add_region($location); $region_grids{$region_name}->add_region($location);
@ -275,7 +277,29 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
say wrap_in_html($grid); if($html_document)
{
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!";
say $fh wrap_in_html($grid);
close $fh;
}
else
{
open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!";
say $fh $grid->render;
close $fh;
say STDERR $regiondir;
if($regiondir)
{
chdir $regiondir || croak "Couldn't chdir to $regiondir: $!";
while(my ($region, $region_grid) = each %region_grids)
{
open (my $region_fh, "> $region.svg") or croak "Couldn't open $region.svg for writing: $!";
say $region_fh $region_grid->render;
close $region_fh;
}
}
}
sub wrap_in_html($grid) sub wrap_in_html($grid)
{ {
@ -290,10 +314,10 @@ sub wrap_in_html($grid)
</script> </script>
EOS EOS
$html_builder .= "\n" . $grid->render; $html_builder .= "\n" . $grid->render;
if ($do_subregions) # if ($regiondir)
{ # {
$html_builder .= "\n" . $_->render for values %region_grids; # $html_builder .= "\n" . $_->render for values %region_grids;
} # }
$html_builder .= "\n</body>\n</html>"; $html_builder .= "\n</body>\n</html>";
return $html_builder; return $html_builder;
} }

Loading…
Cancel
Save