[lintian] 05/09: r/html_reports: Refactor template loading
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository lintian.
commit 83f750ac1e9226b48980dd4c5beb39b7823c26a9
Author: Niels Thykier <niels@thykier.net>
Date: Sun Apr 24 20:33:17 2016 +0000
r/html_reports: Refactor template loading
Signed-off-by: Niels Thykier <niels@thykier.net>
---
reporting/html_reports | 52 +++++++++++++++++++++++++-------------------------
1 file changed, 26 insertions(+), 26 deletions(-)
diff --git a/reporting/html_reports b/reporting/html_reports
index 812c20a..511db5c 100755
--- a/reporting/html_reports
+++ b/reporting/html_reports
@@ -84,9 +84,6 @@ $mirror_timestamp =~ s/\n.*//s;
# ------------------------------
# Initialize templates
-# The path to our templates.
-our $TEMPLATES = "$LINTIAN_ROOT/reporting/templates";
-
# This only has to be done once, so do it at the start and then reuse the same
# templates throughout.
our %templates;
@@ -150,29 +147,6 @@ my @attrs = qw(maintainers source-packages binary-packages udeb-packages
main();
sub main {
- for my $template (
- qw/head foot clean index maintainer maintainers packages tag
- tags tags-severity tag-not-seen tags-all/
- ) {
- open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/$template.tmpl");
- my %options = (TYPE => 'FILEHANDLE', SOURCE => $fd);
- $templates{$template} = Text::Template->new(%options)
- or die "cannot load template $template: $Text::Template::ERROR\n";
- close($fd);
- }
-
- {
- open(my $fd, '<:encoding(UTF-8)', "$TEMPLATES/lintian.css.tmpl");
- $templates{'lintian.css'} = Text::Template->new(
- TYPE => 'FILEHANDLE',
- SOURCE => $fd,
- DELIMITERS => ['{{{', '}}}'],
- )
- or die(
- "cannot load template for lintian.css: $Text::Template::ERROR\n");
- close($fd);
- }
-
setup_output_dir(
'output_dir' => $HTML_TMP_DIR,
'lintian_manual' => "${LINTIAN_ROOT}/doc/lintian.html",
@@ -182,6 +156,8 @@ sub main {
[map { "${LINTIAN_ROOT}/reporting/$_"} qw(images resources)],
);
+ load_templates("$LINTIAN_ROOT/reporting/templates");
+
# Create lintian.css from a template, install the output file as a resource
# and discard the original output file. We do this after installing all
# resources, so the .css file can refer to resources.
@@ -203,6 +179,30 @@ sub main {
# ------------------------------
# Utility functions
+sub load_templates {
+ my ($template_dir) = @_;
+ for my $template (
+ qw/head foot clean index maintainer maintainers packages tag
+ tags tags-severity tag-not-seen tags-all/
+ ) {
+ open(my $fd, '<:encoding(UTF-8)', "${template_dir}/$template.tmpl");
+ my %options = (TYPE => 'FILEHANDLE', SOURCE => $fd);
+ $templates{$template} = Text::Template->new(%options)
+ or die "cannot load template $template: $Text::Template::ERROR\n";
+ close($fd);
+ }
+
+ open(my $fd, '<:encoding(UTF-8)', "${template_dir}/lintian.css.tmpl");
+ $templates{'lintian.css'} = Text::Template->new(
+ TYPE => 'FILEHANDLE',
+ SOURCE => $fd,
+ DELIMITERS => ['{{{', '}}}'],
+ )
+ or die("cannot load template for lintian.css: $Text::Template::ERROR\n");
+ close($fd);
+ return;
+}
+
sub process_data {
my ($state_cache) = @_;
my @maintainers = sort(uniq(keys(%by_maint), keys(%by_uploader)));
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/lintian/lintian.git
Reply to: