style: mark development version
[sheet.git] / countries.plp
1 <(common.inc.plp)><:
2
3 Html({
4         title => 'country code cheat sheet',
5         version => 'v1.0',
6         description =>
7                 "Table of ISO-3166-2 country codes with the names of reserved territories.",
8         keywords => [qw'country code cc tld territory land table'],
9         stylesheet => [qw'light dark circus mono red'],
10 });
11
12 :>
13 <h1>ISO-3166-2α2 Country codes</h1>
14
15 <:
16 my $cc = do 'countries.inc.pl';
17
18 {
19         printf '<table class="mcmap">';
20         print '<col><colgroup span="26">';
21         for my $section (qw{thead}) {
22                 print "<$section><tr><th>↳";
23                 print '<th>', $_ for 'a' .. 'z';
24                 print "\n";
25         }
26         print '<tbody>';
27         for my $row ('a' .. 'z') {
28                 print '<tr><th>', $row;
29                 for my $col ('a' .. 'z') {
30                         my $code = $row . $col;
31                         my $country = $cc->{$code} or do {
32                                 print $code =~ /^x|^q[m-z]|^aa|^zz/ ? '<td class="X Co">' : '<td>';
33                                 next;
34                         };
35                         my ($name, $class, $short, $ref) = @$country;
36                         $ref ||= $code;
37                         local $_ = $ref;
38                         if (exists $get{show}) {
39                                 my $img = "flag/$ref.png";
40                                 $_ = sprintf '<img src="/%s" alt="%s">', $img, $ref if -e $img;
41                         }
42                         else {
43                                 $_ = $short || $name;
44                                 s/,.*//;
45                                 s/(?<=.)\(.*\)\s*//;
46                                 s/ republic\b//gi;
47                                 s/ islands?\b//gi;
48                                 s/\bthe //g;
49                                 s/ and / & /g and s/(?<=.)[a-z ]+//g;
50                                 s/\bsaint /st /gi;
51                                 s/South(?:ern)? /S-/g;
52                                 s/North(?:ern)? /N-/g;
53                                 s/New /n./g;
54                                 s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
55                                 s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
56                                 $_ = EscapeHTML($_);
57                         }
58                         $name =~ s/([^,]*), (.*)/$2 $1/;
59                         printf "\n".'<td class="%s" title="%s">%s',
60                                 $_ ? 'X '.$class : '', EscapeHTML("$code: $name"), $_;
61                 }
62                 print "\n";
63         }
64         print "</table>\n";
65 }
66
67 :>
68 <hr>
69
70 <div class="legend">
71         <table class="glyphs"><tr>
72         <td class="X c-af">africa
73         <td class="X c-eu">europe
74         <td class="X c-as">asia
75         <td class="X c-aa">antarctica
76         <td class="X c-oc">oceania
77         <td class="X c-sa">south america
78         <td class="X c-na">north america
79         <td class="">reserved
80         <td class="X Co">user-assigned
81         </table>
82
83         <div class="right">
84                 <ul class="legend legend-set">
85                 <li><strong>show</strong>
86                         <em><:= exists $get{show} ? 'flag images' : 'english names' :></em><:=
87                                 !exists $get{show} && ' by default' :>
88                 <li>default <strong>style</strong> is
89                         <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
90                 </ul>
91         </div>
92 </div>
93