From 2b0036ac8e077cc20cf9db6ff8dad4091ab50cb3 Mon Sep 17 00:00:00 2001 From: Marius Gavrilescu Date: Thu, 16 Jan 2014 22:38:51 +0200 Subject: [PATCH] Centralize template cooking and introduce reloadable templates --- lib/Gruntmaster/Page/Account.pm | 12 ++++-------- lib/Gruntmaster/Page/Common.pm | 31 ++++++++++++++++++++++++------- lib/Gruntmaster/Page/Ct.pm | 10 ++++------ lib/Gruntmaster/Page/Ct/Entry.pm | 10 ++++------ lib/Gruntmaster/Page/Index.pm | 10 ++++------ lib/Gruntmaster/Page/Learn.pm | 10 ++++------ lib/Gruntmaster/Page/Log.pm | 9 ++++----- lib/Gruntmaster/Page/Log/Entry.pm | 10 ++++------ lib/Gruntmaster/Page/Pb.pm | 10 ++++------ lib/Gruntmaster/Page/Pb/Entry.pm | 12 ++++-------- lib/Gruntmaster/Page/St.pm | 10 ++++------ lib/Gruntmaster/Page/Submit.pm | 14 ++++++-------- 12 files changed, 70 insertions(+), 78 deletions(-) diff --git a/lib/Gruntmaster/Page/Account.pm b/lib/Gruntmaster/Page/Account.pm index f757e9f..20acc6a 100644 --- a/lib/Gruntmaster/Page/Account.pm +++ b/lib/Gruntmaster/Page/Account.pm @@ -7,12 +7,10 @@ use parent qw/Exporter/; our @EXPORT_OK = qw/generate/; our $VERSION = '0.001'; -use constant TITLE => 'Account'; - use HTML::Template::Compiled; -use Gruntmaster::Page::Common qw/header footer patch_templates/; +use Gruntmaster::Page::Common qw/cook_templates reload_templates/; -my %templates = ( +my %orig_templates = ( en => <<'HTML',
@@ -48,12 +46,10 @@ Confirm new password:
HTML ); -patch_templates %templates, 'account'; - -$templates{$_} = header($_, TITLE) . $templates{$_} for keys %templates; -$templates{$_} .= footer $_ for keys %templates; +my %templates = cook_templates %orig_templates, account => 'Account'; sub generate{ + %templates = cook_templates %orig_templates, account => 'Account' if reload_templates; HTML::Template::Compiled->new(scalarref => \$templates{$_[1]})->output } diff --git a/lib/Gruntmaster/Page/Common.pm b/lib/Gruntmaster/Page/Common.pm index 667dae8..37cdf71 100644 --- a/lib/Gruntmaster/Page/Common.pm +++ b/lib/Gruntmaster/Page/Common.pm @@ -4,11 +4,11 @@ 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', TITLE_GOES_HERE @@ -27,7 +27,7 @@ my %header_templates = ( HTML ); -my %footer_templates = ( +my %orig_footer_templates = ( en => <<'HTML',