cc: alternate stylesheets
[sheet.git] / cc.plp
1 <:
2 use utf8;
3 use strict;
4 use warnings;
5 use open IO => ':utf8';
6
7 our $VERSION = 'v1.0';
8
9 $header{content_type} = 'text/html; charset=utf-8';
10
11 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
12  "http://www.w3.org/TR/html4/loose.dtd">
13 <html>
14
15 <head>
16 <meta http-equiv="content-type" content="<:= $header{content_type} :>">
17 <title>country code cheat sheet</title>
18 <link rel="stylesheet" type="text/css" media="all" href="/base.css"><:
19         my %styles = map {$_ => $_} qw(dark mono red);
20         our $style = exists $get{style} && $styles{$get{style}} || 'light';
21         printf(qq{\n<link rel="%s" type="text/css" media="all" href="%s" title="%s">},
22                 $_ eq $style ? 'stylesheet' : 'alternate stylesheet', "/$_.css", $_
23         ) for keys %styles;
24 :>
25 </head>
26
27 <body>
28 <h1>Country codes</h1>
29
30 <:
31 my $cc = do 'cc.inc.pl';
32
33 sub quote {
34         local $_ = shift;
35         s/"/&quot;/g;
36         s/</&lt;/g;
37         s/>/&gt;/g;
38         return $_;
39 }
40
41 {
42         printf '<table class="mcmap">';
43         print '<col><colgroup span="26">';
44         for my $section (qw{thead}) {
45                 print "<$section><tr><th>↱";
46                 print '<th>', $_ for 'a' .. 'z';
47                 print "\n";
48         }
49         print '<tbody>';
50         for my $row ('a' .. 'z') {
51                 print '<tr><th>', $row;
52                 for my $col ('a' .. 'z') {
53                         my $code = $row . $col;
54                         my $country = $cc->{$code} or do {
55                                 print $code =~ /^x|^q[m-z]|^aa|^zz/ ? '<td class="X Co">' : '<td>';
56                                 next;
57                         };
58                         my ($name, $class, $short, $ref) = @$country;
59                         $ref ||= $code;
60                         local $_ = $ref;
61                         if (exists $get{show}) {
62                                 my $img = "flag/$ref.png";
63                                 $_ = sprintf '<img src="/%s" alt="%s">', $img, $ref if -e $img;
64                         }
65                         else {
66                                 $_ = $short || $name;
67                                 s/,.*//;
68                                 s/(?<=.)\(.*\)\s*//;
69                                 s/ republic\b//gi;
70                                 s/ islands?\b//gi;
71                                 s/\bthe //g;
72                                 s/ and / & /g;
73                                 s/\bsaint /st /gi;
74                                 s/South /S-/g;
75                                 s/North /N-/g;
76                                 s/New /n./g;
77                                 s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
78                                 s/(\S{4}[b-df-hj-np-tv-xz])(\S{2,})/$1./g;  # abbreviate (at consonant)
79                                 $_ = quote($_);
80                         }
81                         $name =~ s/([^,]*), (.*)/$2 $1/;
82                         printf "\n".'<td class="%s" title="%s">%s',
83                                 $_ ? 'X '.$class : '', quote("$code: $name"), $_;
84                 }
85                 print "\n";
86         }
87         print "</table>\n";
88 }
89
90 :>
91 <hr>
92
93 <div class="legend">
94         <table class="glyphs"><tr>
95         <td class="X c-af">africa
96         <td class="X c-eu">europe
97         <td class="X c-as">asia
98         <td class="X c-aa">antarctica
99         <td class="X c-oc">oceania
100         <td class="X c-sa">south america
101         <td class="X c-na">north america
102         <td class="">reserved
103         <td class="X Co">user-assigned
104         </table>
105 </div>
106
107 <p class="footer">
108         <a href="/" rel="home">sheet.shiar.nl</a>/charset
109         <a href="git://git.shiar.nl/sheet" rel="vcs-git" title="Git repository"><:= $VERSION :></a>
110         created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
111         <a title="Licensed under the GNU Affero General Public License, version 3" rel="copyright"
112            href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a>
113 </p>
114
115 </html>