mason: Use an autohandler for the HTML skeleton.
[bridge-toys] / mason / dhandler
CommitLineData
bba7b95e
MW
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%#
bba7b95e
MW
35<%args>
36 $nbox => 4
37 $nrow => 4
38</%args>
39%#
8faa0e7d
MW
40<%method title>\
41% if ($fail) {
42Not found\
43% } else {
44Single hand\
45% }
46</%method>
47%#
48<%def .not-found>
49<h1>Not found</h1>
50Failed to find &lsquo;<code><% $what |h %></code>&rsquo;.
51% return 404;
52<%args>
53 $what
54</%args>
55</%def>
bba7b95e
MW
56%#
57<%once>
58 use Deal;
59</%once>
60%#
8faa0e7d
MW
61<%shared>
62 my $fail = ($m->dhandler_arg ne "");
63</%shared>
64%#
bba7b95e 65<%init>
8faa0e7d
MW
66 return $m->comp(".not-found", what => $m->dhandler_arg)
67 if $fail;
bba7b95e 68</%init>