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