]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Ct.pm
Make all generators inherit from a common base
[gruntmaster-page.git] / lib / Gruntmaster / Page / Ct.pm
index c222e62217b05a2d8a16f3617b1c00a76ea252ad..f5c6c1f0d2cc9ed6ee53f83137f3b6bb1a5314c4 100644 (file)
@@ -3,22 +3,13 @@ package Gruntmaster::Page::Ct;
 use 5.014000;
 use strict;
 use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base ct => 'Contests';
+our @ISA = qw/Gruntmaster::Page::Base/;
 our $VERSION = '0.001';
 
-use constant TITLE => 'Contests';
-
-use Fcntl qw/:flock/;
-use HTML::Template::Compiled;
-use IO::File;
-use POSIX qw/strftime/;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page qw/header footer/;
-
-my %templates = (
-  en => <<'HTML',
-<tmpl_if runningn>
+use constant TEMPLATES => {
+       en => <<'HTML',
+<tmpl_if running>
 <h1>Running contests</h1>
 <table border>
 <thead>
@@ -32,7 +23,7 @@ my %templates = (
 </table>
 </tmpl_if>
 
-<tmpl_if pendingn>
+<tmpl_if pending>
 <h1>Pending contests</h1>
 <table border>
 <thead>
@@ -46,7 +37,7 @@ my %templates = (
 </table>
 </tmpl_if>
 
-<tmpl_if finishedn>
+<tmpl_if finished>
 <h1>Finished contests</h1>
 <table border>
 <thead>
@@ -60,40 +51,28 @@ my %templates = (
 </table>
 </tmpl_if>
 HTML
-);
-
-$templates{$_}  = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
+};
 
-sub generate{
-  my $template = $templates{$_[1]};
-  my $htc = HTML::Template::Compiled->new(scalarref => \$template);
-  IO::File->new('>ct/meta.yml')->close unless -f 'ct/meta.yml';
-  flock my $metafh = IO::File->new('<ct/meta.yml'), LOCK_SH;
+sub _generate{
+       my ($self, $htc, $path, $lang) = @_;
 
-  my (@running, @pending, @finished);
-  for (<ct/*/meta.yml>) {
-       my $meta = LoadFile $_;
-       my $id = (m,^ct/(.*)/meta.yml$,)[0];
-       my $ct = { id => $id,
-                          name => $meta->{name},
-                          start => strftime ('%c', localtime $meta->{start}),
-                          end => strftime ('%c', localtime $meta->{end}),
-                          owner => $meta->{owner}};
+       my (@running, @pending, @finished);
+       for (contests) {
+               my $ct = { id => $_,
+                                  name => contest_name,
+                                  start => strftime ('%c', localtime contest_start),
+                                  end => strftime ('%c', localtime contest_end),
+                                  owner => contest_owner };
 
-       my $time = time;
-       push @pending, $ct if time < $meta->{start};
-       push @running, $ct if time >= $meta->{start} && time < $meta->{end};
-       push @finished, $ct if time > $meta->{end};
-  }
+               my $time = time;
+               push @pending, $ct if time < contest_start;
+               push @running, $ct if time >= contest_start && time < contest_end;
+               push @finished, $ct if time > contest_end;
+       }
 
-  $htc->param(runningn => scalar @running);
-  $htc->param(pendingn => scalar @pending);
-  $htc->param(finishedn => scalar @finished);
-  $htc->param(running => \@running);
-  $htc->param(pending => \@pending);
-  $htc->param(finished => \@finished);
-  $htc->output
+       $htc->param(running => \@running);
+       $htc->param(pending => \@pending);
+       $htc->param(finished => \@finished);
 }
 
 1
This page took 0.025367 seconds and 4 git commands to generate.