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