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 $show_coords = 0;
my $interactive = 1;
my $do_subregions = 1;
my $html_document = 1;
my $outfile = '-';
my $regiondir;
GetOptions
(
@ -39,8 +40,9 @@ GetOptions
'border-colour|border-color|bc=s' => \$border_colour,
'show-coords|coords!' => \$show_coords,
'interactive|s!' => \$interactive,
'subregions!|sub' => \$do_subregions
'html-document!' => \$html_document,
'outfile=s' => \$outfile,
'regiondir=s' => \$regiondir
);
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 $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name);
$region->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($do_subregions)
if($regiondir)
{
$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 $subregion = $grid->make_region($page->{title});
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($do_subregions)
if($regiondir)
{
my $region_name = $parsed_template->{positional_params}[0];
$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_with_context;
if($do_subregions)
if($regiondir)
{
$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*$/)
{
$location->make_tile_at($1,$2);
if($do_subregions)
if($regiondir)
{
$location_with_context->make_tile_at($1,$2);
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];
$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)
{
@ -290,10 +314,10 @@ sub wrap_in_html($grid)
</script>
EOS
$html_builder .= "\n" . $grid->render;
if ($do_subregions)
{
$html_builder .= "\n" . $_->render for values %region_grids;
}
# if ($regiondir)
# {
# $html_builder .= "\n" . $_->render for values %region_grids;
# }
$html_builder .= "\n</body>\n</html>";
return $html_builder;
}

Loading…
Cancel
Save