map: generic page to show data tables
authorMischa POSLAWSKY <perl@shiar.org>
Sun, 26 Jun 2022 13:39:28 +0000 (15:39 +0200)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 11 Jul 2022 02:02:34 +0000 (04:02 +0200)
map.plp [new file with mode: 0644]

diff --git a/map.plp b/map.plp
new file mode 100644 (file)
index 0000000..aa74c1c
--- /dev/null
+++ b/map.plp
@@ -0,0 +1,29 @@
+<(common.inc.plp)><:
+my $mapfile = sprintf 'map-%s.nld.tsv', $Request || 'numbers';
+open my $table, '<', $mapfile;
+my ($title, $description) = split /\t/, readline $table;
+
+Html({
+       title => $title,
+       version => '1.0',
+       data => [$mapfile],
+       description => $description,
+       raw => '<style>td,th{text-align:left}</style>',
+});
+
+say "<h1>\u$title</h1>";
+say "<p>$description</p>";
+
+say '<table><thead>';
+while (my $row = readline $table) {
+       my @cols = split /\t/, $row;
+       @cols > 1 or last;
+       say '<tbody>' if $. == 3;
+       print '<tr>';
+       for (@cols) {
+               print /^\d / ? '<th>' : '<td>';
+               s/^.\K /&nbsp;/g; # icon glyph
+               print;
+       }
+}
+say '</table>';