]> iEval git - gruntmaster-page.git/blobdiff - lib/Gruntmaster/Page/Common.pm
Add user list and user pages
[gruntmaster-page.git] / lib / Gruntmaster / Page / Common.pm
index 65cf53c334777f90fea6f96659d80fa75621a1e8..37cdf710fc60e21223a52f01a7b00fe379f262ad 100644 (file)
@@ -4,17 +4,18 @@ use 5.014000;
 use strict;
 use warnings;
 use parent qw/Exporter/;
-our @EXPORT_OK = qw/header footer patch_templates/;
+our @EXPORT_OK = qw/header footer cook_templates reload_templates/;
 
 use File::Slurp qw/read_file/;
 
-my %header_templates = (
+my %orig_header_templates = (
   en => <<'HTML',
 <!DOCTYPE html>
 <title>TITLE_GOES_HERE</title>
 <link rel="stylesheet" href="/gm.css">
-<script src="/jquery-2.0.3.min.js"></script>
-<script src="/view.js"></script>
+<script src="/zepto.var" defer></script>
+<script src="/view.js" defer></script>
+<script src="/form.js" defer></script>
 <meta charset="utf-8">
 
 <span id="admin"></span>
@@ -26,7 +27,7 @@ my %header_templates = (
 HTML
 );
 
-my %footer_templates = (
+my %orig_footer_templates = (
   en => <<'HTML',
 
 <footer>
@@ -37,25 +38,42 @@ Dilmom: Well, it's a stripped-down version of the Gruntmaster 9000, of course. B
 HTML
 );
 
-sub patch_templates (\%$){
+sub patch_templates {
        my $root = $ENV{GRUNTMASTER_TEMPLATE_ROOT} or return;
        my ($templates, $name) = @_;
+       my %out = %$templates;
        for (<$root/$name*>) {
                m/\.(.+)$/;
-               $templates->{$1} = read_file $_
+               $out{$1} = read_file $_
        }
+
+       %out
 }
 
-patch_templates %header_templates, 'header';
-patch_templates %footer_templates, 'footer';
+my %header_templates = patch_templates \%orig_header_templates, 'header';
+my %footer_templates = patch_templates \%orig_footer_templates, 'footer';
+
+sub reload_templates () { $ENV{GRUNTMASTER_RELOAD_TEMPLATES} }
 
 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 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
+}
+
 1;
This page took 0.027027 seconds and 4 git commands to generate.