X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FPage%2FCt.pm;h=1c108fddf5162f534ede875c41128c6e89c3d69d;hb=4aa8ba862bf3a79362df73c3d1e8707e8135af23;hp=c222e62217b05a2d8a16f3617b1c00a76ea252ad;hpb=fe78f0c128c35e68e65850b02057997bad6717fe;p=plack-app-gruntmaster.git diff --git a/lib/Gruntmaster/Page/Ct.pm b/lib/Gruntmaster/Page/Ct.pm index c222e62..1c108fd 100644 --- a/lib/Gruntmaster/Page/Ct.pm +++ b/lib/Gruntmaster/Page/Ct.pm @@ -7,18 +7,14 @@ use parent qw/Exporter/; our @EXPORT_OK = qw/generate/; 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/; +use Gruntmaster::Page::Common qw/cook_templates reload_templates/; +use Gruntmaster::Data qw/contests contest_name contest_start contest_end contest_owner/; -my %templates = ( - en => <<'HTML', - +my %orig_templates = ( + en => <<'HTML', +

Running contests

@@ -32,7 +28,7 @@ my %templates = (
- +

Pending contests

@@ -46,7 +42,7 @@ my %templates = (
- +

Finished contests

@@ -62,38 +58,30 @@ my %templates = ( HTML ); -$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; -$templates{$_} .= footer $_ for keys %templates; +my %templates = cook_templates %orig_templates, ct => 'Contests'; 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(' 'Contests' if reload_templates; + my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$_[1]}); - my (@running, @pending, @finished); - for () { - 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); + $htc->output } 1