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