use 5.014000;
use strict;
use warnings;
-use parent qw/Exporter/;
-our @EXPORT_OK = qw/generate/;
+use Gruntmaster::Page::Base pb => 'Problems';
+our @ISA = qw/Gruntmaster::Page::Base/;
our $VERSION = '0.001';
-use constant TITLE => 'Problems';
-
-use Fcntl qw/:flock/;
-use HTML::Template::Compiled;
-use IO::File;
-use POSIX qw/strftime/;
-use YAML::Any qw/LoadFile/;
-use Gruntmaster::Page::Common qw/header footer/;
-
-my %templates = (
- en => <<'HTML',
-<h2>Beginner</h2>
-<ul>
-<tmpl_loop beginner><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-
-<h2>Easy</h2>
-<ul>
-<tmpl_loop easy><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-
-<h2>Medium</h2>
-<ul>
-<tmpl_loop medium><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-
-<h2>Advanced</h2>
-<ul>
-<tmpl_loop advanced><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-
-<h2>Hard</h2>
-<ul>
-<tmpl_loop hard><li><a href="<tmpl_var id>"><tmpl_var name></a>
-</tmpl_loop></ul>
-HTML
-);
-
-$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
-$templates{$_} .= footer $_ for keys %templates;
-
-sub generate{
- my ($path, $lang) = @_;
- $path =~ s,/index\.html$,,;
- my $template = $templates{$lang};
- my $htc = HTML::Template::Compiled->new(scalarref => \$template);
- IO::File->new(">$path/meta.yml")->close unless -f "$path/meta.yml";
- flock my $metafh = IO::File->new("<$path/meta.yml"), LOCK_SH;
- my @problems = sort { $b->{name} cmp $a->{name} } map {
- my $meta = LoadFile $_;
- my $id = (m,^$path/(.*)/meta.yml$,)[0];
- +{ id => $id, name => $meta->{name}, level => $meta->{level} } } <$path/*/meta.yml>;
- for my $d(qw/beginner easy medium advanced hard/) {
- $htc->param($d => [grep {$_->{level} eq $d} @problems]);
- }
- $htc->output
+sub _generate{
+ my ($self, $htc, $lang, $env, $ct) = @_;
+ debug $env => "language is '$lang' and contest is '$ct'";
+ local $Gruntmaster::Data::contest = $ct if $ct;
+
+ my @problems = sort { $b->{name} cmp $a->{name} } map +{
+ id => $_,
+ name => problem_name,
+ level => problem_level}, problems;
+
+ for my $d (qw/beginner easy medium advanced hard/) {
+ $htc->param($d => [grep {$_->{level} and $_->{level} eq $d} @problems]);
+ }
+ $htc->param(levels => grep { $_->{level} } @problems);
+ $htc->param(problems => \@problems);
}
1