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 };
29 ##################################################
31 my %orig_header_templates = (
34 <title>TITLE_GOES_HERE</title>
35 <link rel="stylesheet" href="/gm.css">
36 <script src="/zepto.var" defer></script>
37 <script src="/view.js" defer></script>
38 <script src="/form.js" defer></script>
39 <meta charset="utf-8">
41 <span id="admin"></span>
42 <div id="title"><span class="i">i</span><span class="Eval">Eval</span></div>
43 <div id="subtitle">TITLE_GOES_HERE</div>
45 <nav><ul><li><a href="/learn.var">Learn</a><li><a href="/pb/">Practice</a><li><a href="/ct/">Compete</a><li><a href="/log/">Job log</a></ul></nav>
50 my %orig_footer_templates = (
54 Dilmom: Why don't you call your product the Gruntmaster 6000?
55 Dilbert: What kind of product do you see when you imagine a Gruntmaster 6000?
56 Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. But it's software-upgradeable.
62 my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT
} or return;
63 my ($templates, $name) = @_;
64 my %out = %$templates;
65 for (<$root/$name*>) {
67 $out{$1} = read_file
$_
73 sub reload_templates
(){ $ENV{GRUNTMASTER_RELOAD_TEMPLATES
} }
75 my %header_templates = patch_templates \
%orig_header_templates, 'header';
76 my %footer_templates = patch_templates \
%orig_footer_templates, 'footer';
79 my ($language, $title) = @_;
80 %header_templates = patch_templates \
%orig_header_templates, 'header' if reload_templates
;
81 $header_templates{$language} =~ s/TITLE_GOES_HERE/$title/ger;
85 %footer_templates = patch_templates \
%orig_footer_templates, 'footer' if reload_templates
;
86 $footer_templates{$_[0]};
90 my ($templates, $name, $title) = @_;
92 my %out = patch_templates
$templates, $name;
93 $out{$_} = header
($_, $title) . $out{$_} for keys %out;
94 $out{$_} .= footer
$_ for keys %out;
99 ##################################################
104 my ($self, $path, $lang) = @_;
106 $templates{$self} = { cook_templates
$self->TEMPLATES, $self->NAME => $self->TITLE } if !exists $templates{$self} or reload_templates
;
108 my $htc = HTML
::Template
::Compiled
->new(scalarref
=> \
$templates{$self}{$lang}, default_escape
=> 'HTML',);
109 $self->_generate($htc, $path, $lang);