Do header processing in template
authorHeiko Schlittermann <hs@schlittermann.de>
Thu, 24 Dec 2015 00:49:28 +0100
changeset 60 e3d6e4095a2c
parent 59 ade26fe6ecbb
child 61 81fc1e7ce91b
Do header processing in template
once.pl
templates/header.tt
templates/inventory.html
templates/once.tt
--- a/once.pl	Thu Dec 24 00:31:53 2015 +0100
+++ b/once.pl	Thu Dec 24 00:49:28 2015 +0100
@@ -55,6 +55,11 @@
 my $rxVIEW = qr/[a-z\d]{6}-[a-z\d]+/i;      # date-userhash
 my $rxFILE = qr/[a-z\d]{6}-[a-z\d]+-./i;    # date-filehash-deletemode
 
+my $TT_CONFIG = {
+    INCLUDE_PATH => [ map { catfile($RealBin, $_) }
+        qw(var templates.override templates) ]
+        };
+
 umask 077;
 
 # The working (var) directory gets passed to us via ONCE_VAR environment
@@ -225,15 +230,9 @@
     }
 
     # create the view
-    print header(-charset => "UTF-8");
-
     my %tt = (view => $view);
-    my $tt = Template->new(
-        {
-            INCLUDE_PATH => =>
-              [map { catfile($RealBin, $_) } 'var', 'templates.override', 'templates']
-        }
-    ) or die $Template::ERROR;
+    my $tt = Template->new($TT_CONFIG)
+        or die $Template::ERROR;
 
     # List the current content
     if (my @files = map { deslash $_ } glob "$user_dir/*-*/*") {
@@ -323,22 +322,14 @@
 
 sub confirm {
     my ($base, $mimetype) = @_;
-    print header(-charset => "UTF-8"),
-      start_html(-title => "once"),
-      h1 "Download bestätigen";
-    print hr, p <<__;
-        Die Datei `$base' ($mimetype), die Sie herunterladen möchten, wird nach Abschluß des
-        Downloads gelöscht. Virenscanner oder andere Programme, die den Link
-        möglicherweise automatisiert aufrufen, könnten eine versehentliche
-        Löschung der Datei auslösen. Bestätigen Sie deshalb bitte den Download
-        per Knopfdruck.
-__
-    print start_form,
-      hidden('confirmed', 'yes'),
-      submit(-value => 'Bestätigung'),
-      end_form,
-      @footer,
-      end_html;
+    my %tt = (
+        file => { name => $base,
+            mimetype => $mimetype
+            }
+    );
+    my $tt = Template->new($TT_CONFIG)
+        or die $Template::ERROR;
+    $tt->process('confirm.html' => \%tt);
     exit 0;
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/templates/header.tt	Thu Dec 24 00:49:28 2015 +0100
@@ -0,0 +1,8 @@
+Content-Type: text/html; charset=utf-8
+
+[%# keep the empty line above! %]
+[% USE date %]
+[% PROCESS version.tt %]
+[%
+    product = 'ONCE'
+%]
--- a/templates/inventory.html	Thu Dec 24 00:31:53 2015 +0100
+++ b/templates/inventory.html	Thu Dec 24 00:49:28 2015 +0100
@@ -1,6 +1,5 @@
+[% PROCESS header.tt -%]
 <html>
-<!-- some modules the template engine needs -->
-[% PROCESS once.tt -%]
 <head>
 <title>[% product %]</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
--- a/templates/once.tt	Thu Dec 24 00:31:53 2015 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-[% USE date %]
-[% PROCESS version.tt %]
-[%
-    product = 'ONCE'
-%]