From 49c1467ab6c3bfeb9aeba883d29a7be7dfefe93e Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 12:46:59 +0200 Subject: [PATCH 01/16] Add X-Forever --- lib/Gruntmaster/Page/Base.pm | 13 ++++++++++--- lib/Gruntmaster/Page/CSS.pm | 2 +- lib/Gruntmaster/Page/JS.pm | 2 +- lib/Gruntmaster/Page/Register.pm | 3 +-- lib/Gruntmaster/Page/Src.pm | 2 +- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index bc8e9ce..0585985 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -13,6 +13,9 @@ use HTML::Template::Compiled; use POSIX (); use Gruntmaster::Data (); use List::Util (); +use LWP::UserAgent; + +my $ua = LWP::UserAgent->new; sub import { my $caller = caller; @@ -29,8 +32,12 @@ sub import { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) }; - *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] } - + *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] }; + *{"${caller}::purge"} = sub { + return unless $ENV{PURGE_HOST}; + my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]"); + $ua->request($req) + }; } ################################################## @@ -139,7 +146,7 @@ sub generate{ my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',); $self->_generate($htc, $lang, @args); - [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language'], [ encode 'UTF-8' => $htc->output ] ] + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ encode 'UTF-8' => $htc->output ] ] } sub _generate {} diff --git a/lib/Gruntmaster/Page/CSS.pm b/lib/Gruntmaster/Page/CSS.pm index 25b6137..2553ab6 100644 --- a/lib/Gruntmaster/Page/CSS.pm +++ b/lib/Gruntmaster/Page/CSS.pm @@ -16,7 +16,7 @@ sub generate{ return [404, ['Content-Type' => 'text/plain'], [ 'Not found' ]] unless -e "css/themes/$theme.css"; my $css = read_file "css/themes/$theme.css"; $css .= read_file $_ for ; - [200, ['Content-Type' => 'text/css', 'Cache-Control' => 'public, max-age=604800'], [minify $css] ] + [200, ['Content-Type' => 'text/css', 'Cache-Control' => 'public, max-age=604800', 'X-Forever' => 1], [minify $css] ] } sub variants{ [[css => 1, 'text/css', undef, undef, undef, undef]] } diff --git a/lib/Gruntmaster/Page/JS.pm b/lib/Gruntmaster/Page/JS.pm index dca5aff..9e78192 100644 --- a/lib/Gruntmaster/Page/JS.pm +++ b/lib/Gruntmaster/Page/JS.pm @@ -15,7 +15,7 @@ sub generate{ debug $env => ""; my $js; $js .= read_file $_ for ; - [200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'public, max-age=604800'], [$js] ] + [200, ['Content-Type' => 'application/javascript', 'Cache-Control' => 'public, max-age=604800', 'X-Forever' => 1], [$js] ] } sub variants{ [[js => 1, 'application/javascript', undef, undef, undef, undef]] } diff --git a/lib/Gruntmaster/Page/Register.pm b/lib/Gruntmaster/Page/Register.pm index 4b93a84..dcb9451 100644 --- a/lib/Gruntmaster/Page/Register.pm +++ b/lib/Gruntmaster/Page/Register.pm @@ -23,8 +23,7 @@ sub generate{ insert_user $username, name => $name, email => $email, phone => $phone, town => $town, university => $university, level => $level; - #PUBLISH genpage => "us/index.html"; - #PUBLISH genpage => "us/$username.html"; + purge "/us/"; reply 'Registered successfully'; } diff --git a/lib/Gruntmaster/Page/Src.pm b/lib/Gruntmaster/Page/Src.pm index b7b9433..8e51d8b 100644 --- a/lib/Gruntmaster/Page/Src.pm +++ b/lib/Gruntmaster/Page/Src.pm @@ -22,7 +22,7 @@ sub generate{ debug $env => "Contest is $ct, job is $job and extension is $ext"; local $Gruntmaster::Data::contest = $ct if $ct; - [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800'], [job_inmeta($job)->{files}{prog}{content}] ] + [200, ['Content-Type' => CONTENT_TYPES->{$ext}, 'Cache-Control' => 'max-age=604800', 'X-Forever' => 1], [job_inmeta($job)->{files}{prog}{content}] ] } sub variants{ [[file => 1, undef, undef, undef, undef, undef]] } -- 2.39.2 From b3a3626fc8cd7bc0afd107d5791825e56fc36c19 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 12:47:39 +0200 Subject: [PATCH 02/16] Remove all EXE_FILES since they are not needed anymore --- Makefile.PL | 1 - gruntmaster-genallpages | 31 ------------------------------- gruntmaster-genarticle | 6 ------ gruntmaster-genpage | 6 ------ gruntmaster-paged | 13 ------------- 5 files changed, 57 deletions(-) delete mode 100755 gruntmaster-genallpages delete mode 100755 gruntmaster-genarticle delete mode 100755 gruntmaster-genpage delete mode 100755 gruntmaster-paged diff --git a/Makefile.PL b/Makefile.PL index c8bd84b..dfb2291 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,7 +4,6 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Gruntmaster::Page', VERSION_FROM => 'lib/Gruntmaster/Page.pm', - 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 ', MIN_PERL_VERSION => '5.14.0', diff --git a/gruntmaster-genallpages b/gruntmaster-genallpages deleted file mode 100755 index 2d1709e..0000000 --- a/gruntmaster-genallpages +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/perl -w -use v5.14; - -use Gruntmaster::Page; -use Gruntmaster::Page::Log; -use Gruntmaster::Data qw/contests jobcard problems users PUBLISH/; - -sub generate{ - my $what = shift; - say STDERR "Generating page $what"; - PUBLISH genpage => $what; -} - -generate "ct/index.html"; -generate "ct/$_/index.html" for contests; - -generate "us/index.html"; -generate "us/$_.html" for users; - -for my $ct (undef, contests) { - local $Gruntmaster::Data::contest = $ct; - my $ctp = defined $ct ? "ct/$ct/" : ''; - generate "${ctp}log/st.html"; - generate "${ctp}log/index.html"; - my $pagecnt = jobcard / Gruntmaster::Page::Log::PAGE_SIZE; - generate "${ctp}log/$_.html" for 1 .. $pagecnt; - generate "${ctp}log/job/$_.html" for 1 .. jobcard; - generate "${ctp}submit.html"; - generate "${ctp}pb/index.html"; - generate "${ctp}pb/$_.html" for problems; -} diff --git a/gruntmaster-genarticle b/gruntmaster-genarticle deleted file mode 100755 index f5b4b5f..0000000 --- a/gruntmaster-genarticle +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl -w -use v5.14; - -use Gruntmaster::Data qw/PUBLISH/; - -PUBLISH genarticle => $_ for @ARGV; diff --git a/gruntmaster-genpage b/gruntmaster-genpage deleted file mode 100755 index 4f6c7f2..0000000 --- a/gruntmaster-genpage +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl -w -use v5.14; - -use Gruntmaster::Data qw/PUBLISH/; - -PUBLISH genpage => $_ for @ARGV; diff --git a/gruntmaster-paged b/gruntmaster-paged deleted file mode 100755 index 2dd5001..0000000 --- a/gruntmaster-paged +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/perl -w -use v5.14; - -use Gruntmaster::Data qw/SUBSCRIBE WAIT_FOR_MESSAGES/; -use Gruntmaster::Page; - -SUBSCRIBE 'genpage', \&Gruntmaster::Page::generate; -SUBSCRIBE 'gensrc', \&Gruntmaster::Page::gensrc; -SUBSCRIBE 'genarticle', \&Gruntmaster::Page::generate; -WAIT_FOR_MESSAGES 86400 while 1; - -1; -__END__ -- 2.39.2 From 05ebc75e25f02d68373483efa678424a4fdfa3f8 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 13:11:33 +0200 Subject: [PATCH 03/16] Convert div id="subtitle" to a h1 id="title" --- css/custom.css | 4 ++-- lib/Gruntmaster/Page/Base.pm | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/css/custom.css b/css/custom.css index 4cc0ab7..9619a30 100644 --- a/css/custom.css +++ b/css/custom.css @@ -1,10 +1,10 @@ -div#subtitle{ +h1#title{ font-family: "Liberation Mono","DejaVu Sans Mono","Lucida Console",monospace; font-weight: bold; text-align: center; padding: 0; margin: 0; - font-size: 3em; + font-size: 3em !important; } footer{ diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index 0585985..e8434ef 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -84,7 +84,7 @@ my %orig_header_templates = (
-
TITLE_GOES_HERE
+

TITLE_GOES_HERE

HTML ); -- 2.39.2 From 5ab7adadc5d72e6bd8a19ced0c508df2775d9958 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 13:35:43 +0200 Subject: [PATCH 04/16] Change default font to serif --- css/themes/cerulean.css | 2 +- css/themes/cosmo.css | 3 +-- css/themes/cyborg.css | 3 +-- css/themes/slate.css | 2 +- 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/css/themes/cerulean.css b/css/themes/cerulean.css index 92780b6..149ca75 100644 --- a/css/themes/cerulean.css +++ b/css/themes/cerulean.css @@ -272,7 +272,7 @@ html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 14px; line-height: 1.42857143; color: #555555; diff --git a/css/themes/cosmo.css b/css/themes/cosmo.css index 396a585..99be757 100644 --- a/css/themes/cosmo.css +++ b/css/themes/cosmo.css @@ -1,4 +1,3 @@ -@import url("//fonts.googleapis.com/css?family=Open+Sans:400italic,700italic,400,700"); /*! * Bootswatch v3.1.0 * Homepage: http://bootswatch.com @@ -273,7 +272,7 @@ html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { - font-family: "Open Sans", Calibri, Candara, Arial, sans-serif; + font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 15px; line-height: 1.42857143; color: #333333; diff --git a/css/themes/cyborg.css b/css/themes/cyborg.css index 46a8fa2..5038cc7 100644 --- a/css/themes/cyborg.css +++ b/css/themes/cyborg.css @@ -1,4 +1,3 @@ -@import url("//fonts.googleapis.com/css?family=Droid+Sans:400,700"); /*! * Bootswatch v3.1.0 * Homepage: http://bootswatch.com @@ -273,7 +272,7 @@ html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { - font-family: "Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 14px; line-height: 1.42857143; color: #888888; diff --git a/css/themes/slate.css b/css/themes/slate.css index 8e3d6fe..767b6fe 100644 --- a/css/themes/slate.css +++ b/css/themes/slate.css @@ -272,7 +272,7 @@ html { -webkit-tap-highlight-color: rgba(0, 0, 0, 0); } body { - font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + font-family: "DejaVu Serif", Georgia, "Times New Roman", Times, serif; font-size: 14px; line-height: 1.42857143; color: #c8c8c8; -- 2.39.2 From 3c53f79540e4015db087fd0bfb9b1af9baef1294 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 14:38:36 +0200 Subject: [PATCH 05/16] Fix incorrect usage of $Gruntmaster::Data::contest --- lib/Gruntmaster/Page/Log/Entry.pm | 2 +- lib/Gruntmaster/Page/Submit.pm | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Gruntmaster/Page/Log/Entry.pm b/lib/Gruntmaster/Page/Log/Entry.pm index af9e1db..8864df8 100644 --- a/lib/Gruntmaster/Page/Log/Entry.pm +++ b/lib/Gruntmaster/Page/Log/Entry.pm @@ -26,7 +26,7 @@ HTML sub _generate{ my ($self, $htc, $lang, $env, $ct, $id) = @_; debug $env => "language is '$lang', contest is '$ct' and id is '$id'"; - local $Gruntmaster::Data::contest = $ct; + local $Gruntmaster::Data::contest = $ct if $ct; my @tests = (); diff --git a/lib/Gruntmaster/Page/Submit.pm b/lib/Gruntmaster/Page/Submit.pm index 096af4d..b08399e 100644 --- a/lib/Gruntmaster/Page/Submit.pm +++ b/lib/Gruntmaster/Page/Submit.pm @@ -34,7 +34,7 @@ sub generate{ die if defined $contest && (time > contest_end $contest); return reply 'A required parameter was not supplied' if grep { !defined } $problem, $format, $prog; - local $Gruntmaster::Data::contest = $contest; + local $Gruntmaster::Data::contest = $contest if $contest; my $job = push_job ( date => time, -- 2.39.2 From 1053baeebc541fc3508aabb6121759bb4a884e23 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 14:38:47 +0200 Subject: [PATCH 06/16] Handle Unicode correctly --- lib/Gruntmaster/Page/Base.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index e8434ef..cf29eac 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -4,7 +4,6 @@ use 5.014000; use strict; use warnings; -use Encode qw/encode/; use File::Slurp qw/read_file/; use HTML::Template::Compiled; @@ -146,7 +145,9 @@ sub generate{ my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',); $self->_generate($htc, $lang, @args); - [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ encode 'UTF-8' => $htc->output ] ] + my $out = $htc->output; + utf8::downgrade($out); + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ $out ] ] } sub _generate {} -- 2.39.2 From 6b5b5f177f66282e6ffb0166b4f73ae933777f9f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 19:25:08 +0200 Subject: [PATCH 07/16] Make Log::Entry table nicer --- lib/Gruntmaster/Page/Log/Entry.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Gruntmaster/Page/Log/Entry.pm b/lib/Gruntmaster/Page/Log/Entry.pm index 8864df8..66dad19 100644 --- a/lib/Gruntmaster/Page/Log/Entry.pm +++ b/lib/Gruntmaster/Page/Log/Entry.pm @@ -13,7 +13,7 @@ Compiler output:
Results: - +
-- 2.39.2 From 8e1eb2c1fbf99436083b0854235142f766c5167f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 20:17:12 +0200 Subject: [PATCH 08/16] Add nice tables to standings --- lib/Gruntmaster/Page/St.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index 5803183..a812cfa 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -9,7 +9,7 @@ our $VERSION = '0.001'; use constant TEMPLATES => { en => <<'HTML', -
Test numberResultTime
+
UsernameTotal
UsernameScore -- 2.39.2 From cd9dd057cd0753fddc5fdad881eeda263909dc24 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 6 Feb 2014 23:58:00 +0200 Subject: [PATCH 09/16] Add run script --- run | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 run diff --git a/run b/run new file mode 100755 index 0000000..e56ffc2 --- /dev/null +++ b/run @@ -0,0 +1,2 @@ +#!/bin/bash +PURGE_HOST=ngm.ieval.ro AAP_ROOTDIR=/var/www/auth/us plackup -s Starlet -Ilib -R . -p 8081 -- 2.39.2 From c3c3874db430b28740de388a50558debf4129485 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 01:22:21 +0200 Subject: [PATCH 10/16] Title should use default heading font --- css/custom.css | 1 - 1 file changed, 1 deletion(-) diff --git a/css/custom.css b/css/custom.css index 9619a30..ecf11bf 100644 --- a/css/custom.css +++ b/css/custom.css @@ -1,5 +1,4 @@ h1#title{ - font-family: "Liberation Mono","DejaVu Sans Mono","Lucida Console",monospace; font-weight: bold; text-align: center; padding: 0; -- 2.39.2 From c7a5e4e0074d51c2368d26bf31ef659286c7f7c2 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 10:34:26 +0200 Subject: [PATCH 11/16] Update 90-custom.js --- js/90-custom.js | 60 +++++++++++++++++++++---------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/js/90-custom.js b/js/90-custom.js index bff6ab1..3759c1b 100644 --- a/js/90-custom.js +++ b/js/90-custom.js @@ -1,44 +1,34 @@ -function set_style(name){ - $('#stylesheet').attr("href", "/css/" + name); - localStorage.setItem("theme", name); +(function(){ + 'use strict'; + function set_style(name){ + $('#stylesheet').attr("href", "/css/" + name); + localStorage.setItem("theme", name); + } - $('#yardi').attr('src', name == "slate" || name == "cyborg" ? "/img/yardi-white.png" : "/img/yardi-blue.png"); -} + $( document ).ready(function() { + var hiddenDiv = $(document.createElement('div')); -$( document ).ready(function() { - var txt = $('#comments'); - hiddenDiv = $(document.createElement('div')), - content = null; + hiddenDiv.addClass('hiddendiv common'); - txt.addClass('txtstuff'); - hiddenDiv.addClass('hiddendiv common'); + $('body').append(hiddenDiv); - $('body').append(hiddenDiv); + $("textarea.autoresize").on('keyup', function () { + var content = $(this).val(); - $("textarea.autoresize").on('keyup', function () { - content = $(this).val(); + content = content.replace(/\n/g, '
'); + hiddenDiv.html(content + '
'); - content = content.replace(/\n/g, '
'); - hiddenDiv.html(content + '
'); + $(this).css('height', hiddenDiv.height()+23); + }); - $(this).css('height', hiddenDiv.height()+23); + $('#theme_slate' ).on('click', function () { set_style("slate"); }); + $('#theme_cerulean').on('click', function () { set_style("cerulean"); }); + $('#theme_cyborg' ).on('click', function () { set_style("cyborg"); }); + $('#theme_cosmo' ).on('click', function () { set_style("cosmo"); }); }); - $('#theme_slate' ).on('click', function () { set_style("slate"); }); - $('#theme_cerulean').on('click', function () { set_style("cerulean"); }); - $('#theme_cyborg' ).on('click', function () { set_style("cyborg"); }); - $('#theme_cosmo' ).on('click', function () { set_style("cosmo"); }); -}); - -var theme = localStorage.getItem("theme"); -if(theme) { - set_style(theme); - $(document).ready(function(){ - $('#yardi').attr('src', theme == "slate" || theme == "cyborg" ? "/img/yardi-white.png" : "/img/yardi-blue.png"); - }) -} - -$( document ).ready(function() { - var sb=$('#sidebar').detach(); - sb.appendTo($('#sponsors')); -}); + var theme = localStorage.getItem("theme"); + if(theme) { + set_style(theme); + } +})(); -- 2.39.2 From f5f2104e633c5b2746beea44edc9f938188f269f Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 11:37:44 +0200 Subject: [PATCH 12/16] Add cursor: pointer to dropdown and remove margin: 0 from title --- css/custom.css | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/css/custom.css b/css/custom.css index ecf11bf..bc0b7ea 100644 --- a/css/custom.css +++ b/css/custom.css @@ -1,8 +1,6 @@ h1#title{ font-weight: bold; text-align: center; - padding: 0; - margin: 0; font-size: 3em !important; } @@ -48,4 +46,8 @@ div.container-fluid { div#result{ text-align: center; -} \ No newline at end of file +} + +a.dropdown-toggle{ + cursor: pointer; +} -- 2.39.2 From 21d3525127c2c7aeb0b8a7266125681aed90d998 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 11:53:43 +0200 Subject: [PATCH 13/16] Mark articles as X-Forever and set max-age to 300 --- lib/Plack/App/Gruntmaster.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Plack/App/Gruntmaster.pm b/lib/Plack/App/Gruntmaster.pm index 1fc3a85..508a81c 100644 --- a/lib/Plack/App/Gruntmaster.pm +++ b/lib/Plack/App/Gruntmaster.pm @@ -35,7 +35,7 @@ sub call { my $content = read_file "a/$article.$lang"; my $title = read_file "a/$article.$lang.title"; my $html = Gruntmaster::Page::Base::header($lang, $title) . $content . Gruntmaster::Page::Base::footer($lang); - return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language'], [$html] ] + return [200, ['Content-Type' => 'text/html', 'Content-Language' => $lang, 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=300'], [$html] ] } } -- 2.39.2 From ff57a758b0a8e3389c99b75682c2c5646f47ae99 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 17:42:35 +0200 Subject: [PATCH 14/16] Add Cache-Control to most requests --- lib/Gruntmaster/Page/Base.pm | 6 ++++-- lib/Gruntmaster/Page/Log.pm | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index cf29eac..cf7d229 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -31,7 +31,7 @@ sub import { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) }; - *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain'], [ @_ ] ] }; + *{"${caller}::reply"} = sub { [200, ['Content-Type' => 'text/plain', 'Cache-Control' => 'no-cache'], [ @_ ] ] }; *{"${caller}::purge"} = sub { return unless $ENV{PURGE_HOST}; my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]"); @@ -147,11 +147,13 @@ sub generate{ $self->_generate($htc, $lang, @args); my $out = $htc->output; utf8::downgrade($out); - [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1], [ $out ] ] + [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language', 'X-Forever' => 1, 'Cache-Control' => 'max-age=' . $self->max_age], [ $out ] ] } sub _generate {} +sub max_age { 60 } + sub variants { [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ] } diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index 4773fec..9192d95 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -55,4 +55,6 @@ sub _generate{ $htc->param(prev => $page - 1) unless $page == 1; } +sub max_age { 5 } + 1 -- 2.39.2 From 7e3d8247f03853c8fd28a48dcd4681a02df32cdd Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Fri, 7 Feb 2014 17:56:39 +0200 Subject: [PATCH 15/16] Add Cache-Control to static files --- app.psgi | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app.psgi b/app.psgi index 20092c9..5bed878 100644 --- a/app.psgi +++ b/app.psgi @@ -55,7 +55,8 @@ sub authenticate { builder { enable 'ContentLength'; - enable 'Static', path => qr,/static/,; + enable_if { $_[0]->{PATH_INFO} =~ qr,^/static/,} Header => set => ['Cache-Control', 'public, max-age=604800']; + enable 'Static', path => qr,^/static/,; enable 'Log4perl', category => 'plack', conf => 'log.conf'; enable \&require_admin; enable_if \&some_auth_required, 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000'; -- 2.39.2 From 9da2f4958089ae517865b808be61bb12d43b61de Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Sat, 8 Feb 2014 20:06:13 +0200 Subject: [PATCH 16/16] Move templates to tmpl/ --- lib/Gruntmaster/Page/Base.pm | 127 +++++++----------------------- lib/Gruntmaster/Page/Ct.pm | 46 ----------- lib/Gruntmaster/Page/Ct/Entry.pm | 11 --- lib/Gruntmaster/Page/Log.pm | 21 ----- lib/Gruntmaster/Page/Log/Entry.pm | 16 ---- lib/Gruntmaster/Page/Pb.pm | 31 -------- lib/Gruntmaster/Page/Pb/Entry.pm | 32 -------- lib/Gruntmaster/Page/St.pm | 17 ---- lib/Gruntmaster/Page/Us.pm | 7 -- lib/Gruntmaster/Page/Us/Entry.pm | 9 --- tmpl/ct.en | 41 ++++++++++ tmpl/ct_entry.en | 6 ++ tmpl/footer.en | 5 ++ tmpl/header.en | 42 ++++++++++ tmpl/log.en | 16 ++++ tmpl/log_entry.en | 11 +++ tmpl/pb.en | 26 ++++++ tmpl/pb_entry.en | 27 +++++++ tmpl/st.en | 12 +++ tmpl/us.en | 2 + tmpl/us_entry.en | 4 + 21 files changed, 219 insertions(+), 290 deletions(-) create mode 100644 tmpl/ct.en create mode 100644 tmpl/ct_entry.en create mode 100644 tmpl/footer.en create mode 100644 tmpl/header.en create mode 100644 tmpl/log.en create mode 100644 tmpl/log_entry.en create mode 100644 tmpl/pb.en create mode 100644 tmpl/pb_entry.en create mode 100644 tmpl/st.en create mode 100644 tmpl/us.en create mode 100644 tmpl/us_entry.en diff --git a/lib/Gruntmaster/Page/Base.pm b/lib/Gruntmaster/Page/Base.pm index cf7d229..89f8478 100644 --- a/lib/Gruntmaster/Page/Base.pm +++ b/lib/Gruntmaster/Page/Base.pm @@ -9,12 +9,34 @@ use HTML::Template::Compiled; ################################################## +sub read_templates { + my $root = 'tmpl'; + my $name = shift; + + map { m/\.(.+)$/; $1 => scalar read_file $_ } ; +} + +my %header_templates = read_templates 'header'; +my %footer_templates = read_templates 'footer'; + +sub header{ + my ($language, $title) = @_; + $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger; +} + +sub footer{ + $footer_templates{$_[0]}; +} + +################################################## + use POSIX (); use Gruntmaster::Data (); use List::Util (); use LWP::UserAgent; my $ua = LWP::UserAgent->new; +my %templates; sub import { my $caller = caller; @@ -25,8 +47,6 @@ sub import { no strict 'refs'; *{"${caller}::strftime"} = \&POSIX::strftime; - *{"${caller}::NAME"} = sub () { $name }; - *{"${caller}::TITLE"} = sub () { $title }; *{"${caller}::debug"} = sub { local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]}) @@ -37,112 +57,19 @@ sub import { my $req = HTTP::Request->new(PURGE => "http://$ENV{PURGE_HOST}$_[0]"); $ua->request($req) }; -} - -################################################## -my %orig_header_templates = ( - en => <<'HTML', - -TITLE_GOES_HERE - - - - - - - - -
- -

TITLE_GOES_HERE

-
-HTML -); - -my %orig_footer_templates = ( - en => <<'HTML', - -
-Dilmom: Why don't you call your product the Gruntmaster 6000? -Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000? -Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable. -
-HTML -); - -sub patch_templates { - my $root = 'tmpl'; - return %{$_[0]} unless -d $root; - my ($templates, $name) = @_; - my %out = %$templates; - for (<$root/$name.*>) { - m/\.(.+)$/; - $out{$1} = read_file $_ + if ($name) { + $templates{$caller} = { read_templates $name }; + $templates{$caller}{$_} = header ($_, $title) . $templates{$caller}{$_} for keys $templates{$caller}; + $templates{$caller}{$_} .= footer $_ for keys $templates{$caller}; } - - %out -} - -my %header_templates = patch_templates \%orig_header_templates, 'header'; -my %footer_templates = patch_templates \%orig_footer_templates, 'footer'; - -sub header{ - my ($language, $title) = @_; - $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger; -} - -sub footer{ - $footer_templates{$_[0]}; -} - -sub cook_templates { - my ($templates, $name, $title) = @_; - - my %out = patch_templates $templates, $name; - $out{$_} = header ($_, $title) . $out{$_} for keys %out; - $out{$_} .= footer $_ for keys %out; - - %out } ################################################## -my %templates; - sub generate{ my ($self, $lang, @args) = @_; - $templates{$self} = { cook_templates $self->TEMPLATES, $self->NAME => $self->TITLE } unless exists $templates{$self}; - my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$self}{$lang}, default_escape => 'HTML',); $self->_generate($htc, $lang, @args); my $out = $htc->output; @@ -155,7 +82,7 @@ sub _generate {} sub max_age { 60 } sub variants { - [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ] + [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $templates{$_[0]} ] } 1 diff --git a/lib/Gruntmaster/Page/Ct.pm b/lib/Gruntmaster/Page/Ct.pm index ede2562..b62b975 100644 --- a/lib/Gruntmaster/Page/Ct.pm +++ b/lib/Gruntmaster/Page/Ct.pm @@ -7,52 +7,6 @@ use Gruntmaster::Page::Base ct => 'Contests'; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', - -

Running contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
- - -

Pending contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
- - -

Finished contests

- - - -
NameStart dateEnd dateOwner -
- - - - -
-
-HTML -}; - sub _generate{ my ($self, $htc, $lang, $env) = @_; debug $env => "language is '$lang'"; diff --git a/lib/Gruntmaster/Page/Ct/Entry.pm b/lib/Gruntmaster/Page/Ct/Entry.pm index 83e2705..acc076e 100644 --- a/lib/Gruntmaster/Page/Ct/Entry.pm +++ b/lib/Gruntmaster/Page/Ct/Entry.pm @@ -7,17 +7,6 @@ use Gruntmaster::Page::Base ct_entry => ''; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', -Contest start time:
-Contest end time:

- -Problems
-Job log
-Standings
-HTML -}; - sub _generate{ my ($self, $htc, $lang, $env, $id) = @_; debug $env => "language is '$lang' and id is '$id'"; diff --git a/lib/Gruntmaster/Page/Log.pm b/lib/Gruntmaster/Page/Log.pm index 9192d95..68f45fd 100644 --- a/lib/Gruntmaster/Page/Log.pm +++ b/lib/Gruntmaster/Page/Log.pm @@ -9,27 +9,6 @@ our $VERSION = '0.001'; use constant PAGE_SIZE => 10; -use constant TEMPLATES => { - en => <<'HTML', - - - -
IDProblemDateSizeUserResult -
- - - data-private> - - -
- -

-HTML -}; - sub _generate{ my ($self, $htc, $lang, $env, $ct, $page) = @_; debug $env => "language is '$lang', contest is '$ct' and page is '$page'"; diff --git a/lib/Gruntmaster/Page/Log/Entry.pm b/lib/Gruntmaster/Page/Log/Entry.pm index 66dad19..57591b5 100644 --- a/lib/Gruntmaster/Page/Log/Entry.pm +++ b/lib/Gruntmaster/Page/Log/Entry.pm @@ -7,22 +7,6 @@ use Gruntmaster::Page::Base log_entry => 'Job '; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', -Compiler output: -
- -Results: - - - -
Test numberResultTime -
- -
-HTML -}; - sub _generate{ my ($self, $htc, $lang, $env, $ct, $id) = @_; debug $env => "language is '$lang', contest is '$ct' and id is '$id'"; diff --git a/lib/Gruntmaster/Page/Pb.pm b/lib/Gruntmaster/Page/Pb.pm index ffdde60..ba78869 100644 --- a/lib/Gruntmaster/Page/Pb.pm +++ b/lib/Gruntmaster/Page/Pb.pm @@ -7,37 +7,6 @@ use Gruntmaster::Page::Base pb => 'Problems'; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', - -

Beginner

-
- -
- -

Easy

-
- -
- -

Medium

-
- -
- -

Hard

-
- -
- - -
- -
-
-HTML -}; - sub _generate{ my ($self, $htc, $lang, $env, $ct) = @_; debug $env => "language is '$lang' and contest is '$ct'"; diff --git a/lib/Gruntmaster/Page/Pb/Entry.pm b/lib/Gruntmaster/Page/Pb/Entry.pm index 2672769..f178b50 100644 --- a/lib/Gruntmaster/Page/Pb/Entry.pm +++ b/lib/Gruntmaster/Page/Pb/Entry.pm @@ -7,38 +7,6 @@ use Gruntmaster::Page::Base pb_entry => ''; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', -
-
- -
- -
-
-
Author
-
Owner
-
- - -

Submit solution

-
- - - -
-
-
- - -
-
-
-HTML -}; - use constant FORMATS => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; sub _generate{ diff --git a/lib/Gruntmaster/Page/St.pm b/lib/Gruntmaster/Page/St.pm index a812cfa..099c193 100644 --- a/lib/Gruntmaster/Page/St.pm +++ b/lib/Gruntmaster/Page/St.pm @@ -7,23 +7,6 @@ use Gruntmaster::Page::Base st => 'Standings'; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', - - - -
UsernameTotal -
UsernameScore - - -
- - - -
-HTML -}; - use constant LEVEL_VALUES => { beginner => 100, easy => 250, diff --git a/lib/Gruntmaster/Page/Us.pm b/lib/Gruntmaster/Page/Us.pm index b4dcb3f..915ee50 100644 --- a/lib/Gruntmaster/Page/Us.pm +++ b/lib/Gruntmaster/Page/Us.pm @@ -7,13 +7,6 @@ use Gruntmaster::Page::Base us => 'Users'; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', -
- -HTML -}; - sub _generate{ my ($self, $htc, $lang, $env) = @_; debug $env => "language is '$lang'"; diff --git a/lib/Gruntmaster/Page/Us/Entry.pm b/lib/Gruntmaster/Page/Us/Entry.pm index e375ab8..628f9fa 100644 --- a/lib/Gruntmaster/Page/Us/Entry.pm +++ b/lib/Gruntmaster/Page/Us/Entry.pm @@ -7,15 +7,6 @@ use Gruntmaster::Page::Base us_entry => ''; our @ISA = qw/Gruntmaster::Page::Base/; our $VERSION = '0.001'; -use constant TEMPLATES => { - en => <<'HTML', -

-Town:
-University:
-Level: -HTML -}; - sub _generate{ my ($self, $htc, $lang, $env, $us) = @_; debug $env => "language is '$lang', user is '$us'"; diff --git a/tmpl/ct.en b/tmpl/ct.en new file mode 100644 index 0000000..e18bc2a --- /dev/null +++ b/tmpl/ct.en @@ -0,0 +1,41 @@ + +

Running contests

+ + + +
NameStart dateEnd dateOwner +
+ + + + +
+
+ + +

Pending contests

+ + + +
NameStart dateEnd dateOwner +
+ + + + +
+
+ + +

Finished contests

+ + + +
NameStart dateEnd dateOwner +
+ + + + +
+
diff --git a/tmpl/ct_entry.en b/tmpl/ct_entry.en new file mode 100644 index 0000000..2919bb3 --- /dev/null +++ b/tmpl/ct_entry.en @@ -0,0 +1,6 @@ +Contest start time:
+Contest end time:

+ +Problems
+Job log
+Standings
diff --git a/tmpl/footer.en b/tmpl/footer.en new file mode 100644 index 0000000..c0f928d --- /dev/null +++ b/tmpl/footer.en @@ -0,0 +1,5 @@ +

+Dilmom: Why don't you call your product the Gruntmaster 6000? +Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000? +Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable. +
diff --git a/tmpl/header.en b/tmpl/header.en new file mode 100644 index 0000000..5ca7976 --- /dev/null +++ b/tmpl/header.en @@ -0,0 +1,42 @@ + +TITLE_GOES_HERE + + + + + + + + +
+ +

TITLE_GOES_HERE

+
diff --git a/tmpl/log.en b/tmpl/log.en new file mode 100644 index 0000000..2ef59af --- /dev/null +++ b/tmpl/log.en @@ -0,0 +1,16 @@ + + + +
IDProblemDateSizeUserResult +
+ + + data-private> + + +
+ + diff --git a/tmpl/log_entry.en b/tmpl/log_entry.en new file mode 100644 index 0000000..45cd405 --- /dev/null +++ b/tmpl/log_entry.en @@ -0,0 +1,11 @@ +Compiler output: +
+ +Results: + + + +
Test numberResultTime +
+ +
diff --git a/tmpl/pb.en b/tmpl/pb.en new file mode 100644 index 0000000..3a8194f --- /dev/null +++ b/tmpl/pb.en @@ -0,0 +1,26 @@ + +

Beginner

+
+ +
+ +

Easy

+
+ +
+ +

Medium

+
+ +
+ +

Hard

+
+ +
+ + +
+ +
+
diff --git a/tmpl/pb_entry.en b/tmpl/pb_entry.en new file mode 100644 index 0000000..4933cb1 --- /dev/null +++ b/tmpl/pb_entry.en @@ -0,0 +1,27 @@ +
+
+ +
+ +
+
+
Author
+
Owner
+
+ + +

Submit solution

+
+ + + +
+
+
+ + +
+
+
diff --git a/tmpl/st.en b/tmpl/st.en new file mode 100644 index 0000000..1e4c8ec --- /dev/null +++ b/tmpl/st.en @@ -0,0 +1,12 @@ + + + +
UsernameTotal +
UsernameScore + + +
+ + + +
diff --git a/tmpl/us.en b/tmpl/us.en new file mode 100644 index 0000000..174bc80 --- /dev/null +++ b/tmpl/us.en @@ -0,0 +1,2 @@ +
+ diff --git a/tmpl/us_entry.en b/tmpl/us_entry.en new file mode 100644 index 0000000..b6c988d --- /dev/null +++ b/tmpl/us_entry.en @@ -0,0 +1,4 @@ +

+Town:
+University:
+Level: -- 2.39.2