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