]> iEval git - gruntmaster-page.git/commitdiff
Add article support
authorMarius Gavrilescu <marius@ieval.ro>
Sun, 26 Jan 2014 13:40:40 +0000 (15:40 +0200)
committerMarius Gavrilescu <marius@ieval.ro>
Sun, 26 Jan 2014 13:40:40 +0000 (15:40 +0200)
Makefile.PL
gruntmaster-genallpages
gruntmaster-genarticle [new file with mode: 0755]
gruntmaster-paged
lib/Gruntmaster/Data.pm
lib/Gruntmaster/Page.pm
lib/Gruntmaster/Page/Base.pm

index cc79d4f5bd40da3b359571afc3baa776cc042d1b..c8bd84b31250f7978349c5c369b9a293227daa44 100644 (file)
@@ -4,7 +4,7 @@ use ExtUtils::MakeMaker;
 WriteMakefile(
   NAME              => 'Gruntmaster::Page',
   VERSION_FROM      => 'lib/Gruntmaster/Page.pm',
-  EXE_FILES         => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-contest gruntmaster-problem gruntmaster-job/ ],
+  EXE_FILES         => [ qw/gruntmaster-genarticle gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-contest gruntmaster-problem gruntmaster-job/ ],
   ABSTRACT_FROM     => 'lib/Gruntmaster/Page.pm',
   AUTHOR            => 'Marius Gavrilescu <marius@ieval.ro>',
   MIN_PERL_VERSION  => '5.14.0',
index 8d18eaa62a24aeca900ecc7d6cefa162505e1505..7588f02b65ed54c3510630b569c7e90bb41bd436 100755 (executable)
@@ -11,9 +11,6 @@ sub generate{
   PUBLISH genpage => $what;
 }
 
-generate "index.html";
-generate "learn.html";
-
 generate "ct/index.html";
 generate "ct/$_/index.thml" for contests;
 generate "ct/$_/log/st.html" for contests;
diff --git a/gruntmaster-genarticle b/gruntmaster-genarticle
new file mode 100755 (executable)
index 0000000..f5b4b5f
--- /dev/null
@@ -0,0 +1,6 @@
+#!/usr/bin/perl -w
+use v5.14;
+
+use Gruntmaster::Data qw/PUBLISH/;
+
+PUBLISH genarticle => $_ for @ARGV;
index 5e7bd576231b8b64a89958110ee2a1229403bba1..2dd5001ae973ce4c189a5889431b2a886e7e4a5c 100755 (executable)
@@ -6,7 +6,7 @@ use Gruntmaster::Page;
 
 SUBSCRIBE 'genpage', \&Gruntmaster::Page::generate;
 SUBSCRIBE 'gensrc', \&Gruntmaster::Page::gensrc;
-SUBSCRIBE 'genarticle', \&Gruntmaster::Page::genarticle;
+SUBSCRIBE 'genarticle', \&Gruntmaster::Page::generate;
 WAIT_FOR_MESSAGES 86400 while 1;
 
 1;
index aac9ad1f77e3932adc23c7d1ee9e384f1a2ad5ee..bf5d2e1a808e9e1067544df673b95fad2a143de9 100644 (file)
@@ -52,6 +52,11 @@ sub defhash{
                dynsub "set_${name}_$key", sub ($$) { HSET cp . "$name.$_[0]", $key, $_[1] };
        }
 
+       dynsub "edit_$name", sub {
+               my ($key, %values) = @_;
+               HMSET cp . "$name.$key", %values;
+       };
+
        dynsub "insert_$name", sub {
                my ($key, %values) = @_;
                SADD cp . $name, $key or return;
index eedbec54e17d2e865b8ec4cfe6ddc96224d2ed03..451ed8e3a0a2efbe979f7f510471d56f867500ed 100644 (file)
@@ -7,7 +7,7 @@ use warnings;
 use Fcntl qw/:flock/;
 use File::Basename qw/fileparse/;
 use File::Path qw/make_path/;
-use File::Slurp qw/write_file/;
+use File::Slurp qw/read_file write_file/;
 use IO::Compress::Gzip qw/gzip/;
 use IO::File;
 use Gruntmaster::Data;
@@ -47,7 +47,7 @@ sub declaregen{
 }
 
 sub generate{
-       my ($path) = @_;
+       my ($path, $topic) = @_;
        my ($path_noext, $ext) = $path =~ m/^(.*)\.(.*)$/;
        my ($basename, $directories) = fileparse $path_noext;
        make_path $directories;
@@ -56,17 +56,32 @@ sub generate{
        flock my $lockfh = IO::File->new("<$path_noext.var"), LOCK_EX;
        open my $typemap, ">$path_noext.var.new";
        say $typemap "URI: $basename\n";
-       for my $gen (@generators) {
-               my ($regex, $generator) = @$gen;
-               next unless $path_noext =~ $regex;
+
+       my $fill_typemap = sub {
                for my $lang (@{LANGUAGES()}) {
-                       my $page = $generator->generate($path, $lang);
+                       my $page = $_[0]->($lang);
                        write_file "$path_noext.$lang.$ext.new", $page;
                        say $typemap "URI: $basename.$lang.$ext\nContent-Language: $lang\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
                        gzip \$page => "$path_noext.$lang.gz.$ext.new", Minimal => 1;
                        say $typemap "URI: $basename.$lang.gz.$ext\nContent-Language: $lang\nContent-Encoding: gzip\nContent-Type: " . CONTENT_TYPES->{$ext} . "\n";
                }
-               last
+       };
+
+       if ($topic eq 'genpage') {
+               for my $gen (@generators) {
+                       my ($regex, $generator) = @$gen;
+                       next unless $path_noext =~ $regex;
+                       $fill_typemap->(sub { $generator->generate($path, $_[0]) });
+                       last
+               }
+       } else {
+               my $get_article = sub {
+                       my $article = read_file "$ENV{GRUNTMASTER_ARTICLE_ROOT}/$basename.$_[0]";
+                       my $title   = read_file "$ENV{GRUNTMASTER_ARTICLE_ROOT}/$basename.$_[0].title";
+                       Gruntmaster::Page::Base::header($_[0], $title) . $article . Gruntmaster::Page::Base::footer($_[0])
+               };
+
+               $fill_typemap->($get_article);
        }
 
        for my $lang (@{LANGUAGES()}) {
@@ -84,10 +99,6 @@ sub gensrc{
        write_file "log/src/$job.$ext", job_inmeta($job)->{files}{prog}{content};
 }
 
-sub genarticle{
-       
-}
-
 1;
 __END__
 # Below is stub documentation for your module. You'd better edit it!
index b0b4c57fbac3cd784fa6bc32690ff44867697567..5b93f20992e00411b7d981f0af15edfc32a1e7c6 100644 (file)
@@ -59,7 +59,7 @@ HTML
 );
 
 sub patch_templates {
-       my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
+       my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return %{$_[0]};
        my ($templates, $name) = @_;
        my %out = %$templates;
        for (<$root/$name.*>) {
This page took 0.03824 seconds and 4 git commands to generate.