1 package Gruntmaster
::Page
::Base
;
7 use File
::Slurp qw
/read_file/;
8 use HTML
::Template
::Compiled
;
10 ##################################################
13 use Gruntmaster
::Data
();
18 my ($self, $name, $title) = @_;
20 Gruntmaster
::Data
->export_to_level(1, $caller);
21 List
::Util
->export_to_level(1, $caller, qw
/sum/);
24 *{"${caller}::strftime"} = \
&POSIX
::strftime
;
25 *{"${caller}::NAME"} = sub () { $name };
26 *{"${caller}::TITLE"} = sub () { $title };
27 *{"${caller}::debug"} = sub {
28 local $Log::Log4perl
::caller_depth
= $Log::Log4perl
::caller_depth
+ 1;
29 $_[0]->({qw
/level debug message/ => $_[1]})
33 ##################################################
35 my %orig_header_templates = (
38 <title>TITLE_GOES_HERE</title>
39 <link rel="stylesheet" href="/static/gm.css">
40 <script src="/static/zepto.var" defer></script>
41 <script src="/static/view.js" defer></script>
42 <script src="/static/form.js" defer></script>
43 <meta charset="utf-8">
45 <span id="admin"></span>
46 <div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
47 <div id="subtitle">TITLE_GOES_HERE</div>
50 <li><a href="/pb/">Problems</a>
51 <li><a href="/ct/">Contests</a>
52 <li><a href="/log/">Job log</a></ul></nav>
57 my %orig_footer_templates = (
61 Dilmom: Why don't you call your product the Gruntmaster 6000?
62 Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?
63 Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable.
69 my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT
} or return %{$_[0]};
70 my ($templates, $name) = @_;
71 my %out = %$templates;
72 for (<$root/$name.*>) {
74 $out{$1} = read_file
$_
80 sub reload_templates
(){ $ENV{GRUNTMASTER_RELOAD_TEMPLATES
} }
82 my %header_templates = patch_templates \
%orig_header_templates, 'header';
83 my %footer_templates = patch_templates \
%orig_footer_templates, 'footer';
86 my ($language, $title) = @_;
87 %header_templates = patch_templates \
%orig_header_templates, 'header' if reload_templates
;
88 $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
92 %footer_templates = patch_templates \
%orig_footer_templates, 'footer' if reload_templates
;
93 $footer_templates{$_[0]};
97 my ($templates, $name, $title) = @_;
99 my %out = patch_templates
$templates, $name;
100 $out{$_} = header
($_, $title) . $out{$_} for keys %out;
101 $out{$_} .= footer
$_ for keys %out;
106 ##################################################
111 my ($self, $lang, @args) = @_;
113 $templates{$self} = { cook_templates
$self->TEMPLATES, $self->NAME => $self->TITLE } if !exists $templates{$self} or reload_templates
;
115 my $htc = HTML
::Template
::Compiled
->new(scalarref
=> \
$templates{$self}{$lang}, default_escape
=> 'HTML',);
116 $self->_generate($htc, $lang, @args);
117 [200, ['Content-Type' => 'text/html', 'Content-Language' => $_[1]], [ $htc->output ] ]
123 [ map { [ $_, 1, 'text/html', undef, undef, $_, undef ]} keys $_[0]->TEMPLATES ]