index: release v1.18 with only altgr index linked
[sheet.git] / keyboard.plp
1 <(common.inc.plp)><:
2
3 $Request ||= 'altgr/windows';
4 my $mode = lc $Request;
5 my $include = "keyboard/$mode.eng";
6
7 if (-e (my $page = "keyboard/$Request/index.inc.plp")) {
8         Include $page;
9         exit;
10 }
11
12 my $info = eval { Data($include) } || {};
13 warn "error in $include: ", @{$@} if ref $@;
14 $mode = $info->{title} // $mode;
15
16 my $showkeys //= !exists $get{keys} ? undef :
17         ($get{keys} ne '0' && ($get{keys} || 'always'));
18 my @keystyle = (
19         '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
20         '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
21         !$showkeys ? '<style> .no {visibility:hidden} </style>' :
22         $showkeys eq 'ghost' ? '<style> .no, .alias {opacity:.5} </style>' : (),
23         '<script type="text/javascript" src="/keys.js?1.6" async></script>',
24 );
25
26 Html({
27         title => "\L$mode\E keyboard cheat sheet",
28         version => $info->{version} || '0.1',
29         canonical => -e "$Request.plp" ? "/$Request" : undef, # historic shorthand
30         description => $info->{description} //
31                 ["Keyboard cheat sheet for the default controls of $mode."],
32         keywords => [@{ $info->{keywords} // [] }, qw'
33                 sheet cheat reference overview keyboard control commands shortkey
34         '],
35         image => $info->{image},
36         stylesheet => [qw( light dark circus mono red )],
37         data => ["$include.inc.pl"],
38         raw => \@keystyle,
39 });
40
41 %{$info} or Abort(
42         "Requested keyboard <q>$mode</q> not available",
43         '404 request not found',
44 );
45
46 say "<h1>$mode keyboard</h1>";
47 say "<p>$_</p>" for $info->{intro} // ();
48 say "<h2>", $info->{mode}->{''}, " (default)</h2>"
49         if $info->{mode} and %{ $info->{mode} } > 1;
50
51 use Shiar_Sheet::Keyboard 2.08;
52 my $keys = Shiar_Sheet::Keyboard->new($info);
53 $keys->map($get{map}) or undef $get{map};
54 $keys->print_rows($get{rows} || $info->{moderows}, $info->{rows});
55
56 {
57         say "<hr/>\n";
58         say '<div class="help">';
59
60         use List::MoreUtils qw( part );
61         my @gflags = part {/^g\d/} sort keys %{ $keys->{flag} };
62
63         say "\t", '<div class="left">';
64         $keys->print_legend('legend-types', $gflags[1]);
65         say "\t</div>\n";
66
67         say "\t", '<div class="right">';
68         $keys->print_legend('legend-options', $gflags[0]);
69         say '';
70
71         say "\t\t", '<ul class="legend legend-set">';
72
73         say "\t\t<li>keyboard <strong>map</strong> is ",
74                 ($get{map} ? 'set to ' : ''), "<em>$keys->{map}</em>";
75         say "\t\t<li><strong>keys</strong> are ",
76                 "<em>", ($showkeys ? 'always shown' : 'hidden if unassigned'), "</em>",
77                 (!defined $showkeys && ' by default');
78         say "\t\t<li>default <strong>style</strong> is ",
79                 (defined $get{style} && 'set to '), "<em>$style</em>";
80
81         say "\t\t</ul>";
82         say "\t</div>\n";
83         say "</div>\n";
84 }