]> iEval git - gruntmaster-page.git/blob - lib/Gruntmaster/Page/Ct.pm
Add user hash Gruntmaster::Data
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct.pm
1 package Gruntmaster::Page::Ct;
2
3 use 5.014000;
4 use strict;
5 use warnings;
6 use parent qw/Exporter/;
7 our @EXPORT_OK = qw/generate/;
8 our $VERSION = '0.001';
9
10 use constant TITLE => 'Contests';
11
12 use HTML::Template::Compiled;
13 use POSIX qw/strftime/;
14 use Gruntmaster::Page::Common qw/header footer/;
15 use Gruntmaster::Data qw/contest_name contest_start contest_end contest_owner/;
16
17 my %templates = (
18 en => <<'HTML',
19 <tmpl_if running>
20 <h1>Running contests</h1>
21 <table border>
22 <thead>
23 <tr><th>Name<th>Start date<th>End date<th>Owner
24 <tbody>
25 <tmpl_loop running><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
26 <td><tmpl_var start>
27 <td><tmpl_var end>
28 <td><tmpl_var owner>
29 </tmpl_loop>
30 </table>
31 </tmpl_if>
32
33 <tmpl_if pending>
34 <h1>Pending contests</h1>
35 <table border>
36 <thead>
37 <tr><th>Name<th>Start date<th>End date<th>Owner
38 <tbody>
39 <tmpl_loop pending><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
40 <td><tmpl_var start>
41 <td><tmpl_var end>
42 <td><tmpl_var owner>
43 </tmpl_loop>
44 </table>
45 </tmpl_if>
46
47 <tmpl_if finished>
48 <h1>Finished contests</h1>
49 <table border>
50 <thead>
51 <tr><th>Name<th>Start date<th>End date<th>Owner
52 <tbody>
53 <tmpl_loop finished><tr><td><a href="<tmpl_var id>"><tmpl_var name></a>
54 <td><tmpl_var start>
55 <td><tmpl_var end>
56 <td><tmpl_var owner>
57 </tmpl_loop>
58 </table>
59 </tmpl_if>
60 HTML
61 );
62
63 $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
64 $templates{$_} .= footer $_ for keys %templates;
65
66 sub generate{
67 my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]});
68
69 my (@running, @pending, @finished);
70 for (contests) {
71 my $ct = { id => $_,
72 name => contest_name,
73 start => strftime ('%c', localtime contest_start),
74 end => strftime ('%c', localtime contest_end),
75 owner => contest_owner };
76
77 my $time = time;
78 push @pending, $ct if time < contest_start;
79 push @running, $ct if time >= contest_start && time < contest_end;
80 push @finished, $ct if time > contest_end;
81 }
82
83 $htc->param(running => \@running);
84 $htc->param(pending => \@pending);
85 $htc->param(finished => \@finished);
86 $htc->output
87 }
88
89 1
This page took 0.050699 seconds and 4 git commands to generate.