From 881bf723426827f7909f5b5fd526bc5cf7f47c08 Mon Sep 17 00:00:00 2001 From: Daniel Asher Resnick Date: Mon, 10 Jul 2023 16:30:22 -0500 Subject: [PATCH] Refactor modality --- wiki-tile.pl | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/wiki-tile.pl b/wiki-tile.pl index f88df88..a07c86f 100644 --- a/wiki-tile.pl +++ b/wiki-tile.pl @@ -277,36 +277,19 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}}) -if($html_document) +open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; +say $fh ($html_document ? wrap_in_html($grid) : $grid->render); +close $fh; +if($regiondir) { - open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; - say $fh wrap_in_html($grid); - close $fh; - if($regiondir) - { - chdir $regiondir || croak "Couldn't chdir to $regiondir: $!"; - while(my ($region, $region_grid) = each %region_grids) - { - open (my $region_fh, "> $region.html") or croak "Couldn't open $region.html for writing: $!"; - say $region_fh wrap_in_html($region_grid); - close $region_fh; - } - } -} -else -{ - open (my $fh, "> $outfile") or croak "Couldn't open $outfile for writing: $!"; - say $fh $grid->render; - close $fh; - if($regiondir) + chdir $regiondir || croak "Couldn't chdir to $regiondir: $!"; + my $extension = $html_document ? 'html' : 'svg'; + while(my ($region, $region_grid) = each %region_grids) { - 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; - } + open (my $region_fh, "> $region.$extension") + or croak "Couldn't open $region.extension for writing: $!"; + say $region_fh ($html_document ? wrap_in_html($region_grid) : $region_grid->render); + close $region_fh; } } @@ -323,10 +306,6 @@ sub wrap_in_html($grid) EOS $html_builder .= "\n" . $grid->render; - # if ($regiondir) - # { - # $html_builder .= "\n" . $_->render for values %region_grids; - # } $html_builder .= "\n\n"; return $html_builder; }