X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;ds=inline;f=lib%2FGruntmaster%2FPage%2FPb.pm;h=a2cccff504516d7c90969a00977c2be54a584ec8;hb=9be91908e37325aae1af68d98f8aafce310c6950;hp=efe7d26a42d986dbde5dc51b9add82aca7b91c24;hpb=42546e6c1b709dc4c8d8e7048becc14278b6cdf0;p=plack-app-gruntmaster.git
diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm
index efe7d26..a2cccff 100644
--- a/lib/Gruntmaster/Page/Pb.pm
+++ b/lib/Gruntmaster/Page/Pb.pm
@@ -14,12 +14,33 @@ 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/header footer/;
my %templates = (
en => <<'HTML',
+
Beginner
+
+Easy
+
+
+Medium
+
+
+Advanced
+
+
+Hard
+
HTML
);
@@ -28,15 +49,19 @@ $templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates;
$templates{$_} .= footer $_ for keys %templates;
sub generate{
- my $template = $templates{$_[1]};
+ my ($path, $lang) = @_;
+ $path =~ s,/index\.html$,,;
+ my $template = $templates{$lang};
my $htc = HTML::Template::Compiled->new(scalarref => \$template);
- IO::File->new('>pb/meta.yml')->close unless -f 'pb/meta.yml';
- flock my $metafh = IO::File->new('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,^pb/(.*)/meta.yml$,)[0];
- +{ id => $id, name => $meta->{name} } } ;
- $htc->param(problems => \@problems);
+ 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
}