chiark / gitweb /
mason/dhandler: Bring not-found handling into the dhandler.
[bridge-toys] / mason / dhandler
1 <!-- -*-html-*-
2   -
3   - Generate a dealing list for a single hand
4   -
5   - (c) 2013 Mark Wooding
6  -->
7
8 <table class=deal>\
9 <%perl>
10         my @line = Deal::line;
11         my ($row, $col, $box) = (0, 0, 0);
12         for (my $i = 0; $i < @line; $i++) {
13           if ($col) {
14             $m->out(" ");
15           } else {
16             if (!$box) {
17               my $class =
18                 $row == 0 ? "first" :
19                 $i + $nrow*$nbox >= @line ? "last" :
20                 "mid";
21               $m->out("\n<tr class=$class>");
22             }
23             my $class = ($box + $row)%2 ? "odd " : "even";
24             $m->out("\n  <td class=$class>");
25           }
26           $m->out($line[$i]);
27           $col++;
28           if ($col >= $nbox) { $col = 0; $box++; }
29           if ($box >= $nrow) { $box = 0; $row++; }
30         }
31         $m->out("\n");
32 </%perl>
33 </table>
34 %#
35 <%flags>
36         inherit => "%html"
37 </%flags>
38 %#
39 <%args>
40         $nbox => 4
41         $nrow => 4
42 </%args>
43 %#
44 <%method title>\
45 % if ($fail) {
46 Not found\
47 % } else {
48 Single hand\
49 % }
50 </%method>
51 %#
52 <%def .not-found>
53 <h1>Not found</h1>
54 Failed to find &lsquo;<code><% $what |h %></code>&rsquo;.
55 % return 404;
56 <%args>
57         $what
58 </%args>
59 </%def>
60 %#
61 <%once>
62         use Deal;
63 </%once>
64 %#
65 <%shared>
66         my $fail = ($m->dhandler_arg ne "");
67 </%shared>
68 %#
69 <%init>
70         return $m->comp(".not-found", what => $m->dhandler_arg)
71           if $fail;
72 </%init>