use strict;
use warnings;
-use Encode qw/encode/;
use File::Slurp qw/read_file/;
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;
*{"${caller}::TITLE"} = sub () { $title };
*{"${caller}::debug"} = sub {
local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
- $_[0]->({qw/level debug message/ => $_[1]})
+ $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
+ };
+ *{"${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)
};
}
my %orig_header_templates = (
en => <<'HTML',
<!DOCTYPE html>
-<title>TITLE_GOES_HERE</title>
+<title>TITLE_GOES_HERE | MindCoding</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<link rel="stylesheet" href="/css/cyborg" id="stylesheet">
+<link rel="shortcut icon" href="/static/favicon.png">
+<link rel="stylesheet" href="/css/cosmo" id="stylesheet">
<script src="/js" type="text/javascript"></script>
<nav class="navbar navbar-default navbar-static-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <span class="sr-only">Toggle navigation</span><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button>
-<a class="navbar-brand" href="/">Gruntmaster 6000</a>
+<a class="navbar-brand" href="/"><div class="logo logo-sigla"></div></a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
-<li><a href="/pb/">Problem list</a>
+<li><a href="/pb/">Problems</a>
<li><a href="/ct/">Contests</a>
<li><a href="/account">Account</a>
</ul>
<div class="container-fluid">
-<div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
-<div id="subtitle">TITLE_GOES_HERE</div>
+<div class="logo logo-mindcoding center-block"></div>
+<h1 id="title">TITLE_GOES_HERE</h1>
+<div id="result"></div>
+
+<div id="content">
HTML
);
my %orig_footer_templates = (
en => <<'HTML',
+</div>
+
+<div id="sponsors">
+<h3>Official sponsors</h3>
+<div class="logo logo-yardi"></div>
+</div>
+
<footer>
-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.
+<div class="row">
+<div class="col-md-6 column text-center">
+<a class="logo logo-hermes" href="http://www.societatea-hermes.ro"></a>
+</div>
+
+<div class="col-md-6 column text-center">
+<a class="logo logo-facebook" href="http://www.facebook.com/mindcodingcluj"></a>
+</div>
+</div>
+
+<h3> Partners </h3>
+<a href="http://cs.ubbcluj.ro" class="logo logo-csf"></a>
+<a href="http://www.uniunea.ro" class="logo logo-usr"></a>
+<a href="http://www.coscj.ro" class="logo logo-cos"></a>
+<a href="http://www.cluj2015.ro/romana" class="logo logo-eyc"></a>
+<h3> Media Partners </h3>
+<a href="http://www.clujlife.com" class="logo logo-clujlife"></a>
+<a href="http://www.vinsieu.ro/eveniment/cluj/cluj-napoca/alte-evenimente/mindcoding/88970/e.html" class="logo logo-vinsieu"></a>
+<a href="http://www.welcome2cluj.com" class="logo logo-welcome2cluj"></a>
</footer>
+</div>
HTML
);
sub patch_templates {
- my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return %{$_[0]};
+ my $root = 'tmpl';
+ return %{$_[0]} unless -d $root;
my ($templates, $name) = @_;
my %out = %$templates;
for (<$root/$name.*>) {
%out
}
-sub reload_templates (){ $ENV{GRUNTMASTER_RELOAD_TEMPLATES} }
-
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 = patch_templates \%orig_header_templates, 'header' if reload_templates;
$header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
}
sub footer{
- %footer_templates = patch_templates \%orig_footer_templates, 'footer' if reload_templates;
$footer_templates{$_[0]};
}
sub generate{
my ($self, $lang, @args) = @_;
- $templates{$self} = { cook_templates $self->TEMPLATES, $self->NAME => $self->TITLE } if !exists $templates{$self} or reload_templates;
+ $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);
- [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1], 'Vary' => 'Accept-Language'], [ 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 {}