From bf3cc4b6658497e7f7d15bbe16d1795fefb7cf05 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 19 Jun 2007 11:25:35 +0000 Subject: [PATCH] =?utf8?q?Einf=C3=BChrung=20des=20Modules=20"Template"=20a?= =?utf8?q?ls=20schnellere=20Alternative=20(Faktor=209)=20zu=20"HTML::Templ?= =?utf8?q?ate".=20Wird=20via=20$form->parse=5Fhtml=5Ftemplate2()=20aufgeru?= =?utf8?q?fen.=20Umstellung=20der=20von=20ReportGenerator=20verwendeten=20?= =?utf8?q?Vorlage=20auf=20die=20Verwendung=20von=20"Template".?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Form.pm | 66 +++++++++++++--- SL/InstallationCheck.pm | 1 + SL/ReportGenerator.pm | 4 +- doc/INSTALL | 5 +- doc/UPGRADE | 3 +- locale/de/locales.pl | 2 +- .../report_generator/html_report_de.html | 74 +++++++++--------- .../report_generator/html_report_master.html | 76 +++++++++---------- 8 files changed, 138 insertions(+), 93 deletions(-) diff --git a/SL/Form.pm b/SL/Form.pm index 464405ca4..ac107cd86 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -40,6 +40,7 @@ use Data::Dumper; use Cwd; use HTML::Template; +use Template; use SL::Template; use CGI::Ajax; use SL::DBUtils; @@ -474,7 +475,7 @@ sub header { $main::lxdebug->leave_sub(); } -sub parse_html_template { +sub _prepare_html_template { $main::lxdebug->enter_sub(); my ($self, $file, $additional_params) = @_; @@ -508,14 +509,6 @@ sub parse_html_template { die($info); } - my $template = HTML::Template->new("filename" => $file, - "die_on_bad_params" => 0, - "strict" => 0, - "case_sensitive" => 1, - "loop_context_vars" => 1, - "global_vars" => 1); - - $additional_params = {} unless ($additional_params); if ($self->{"DEBUG"}) { $additional_params->{"DEBUG"} = $self->{"DEBUG"}; } @@ -539,10 +532,29 @@ sub parse_html_template { $additional_params->{"conf_latex_templates"} = $main::latex; $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates; - my @additional_param_names = keys(%{$additional_params}); + $main::lxdebug->leave_sub(); + + return $file; +} + +sub parse_html_template { + $main::lxdebug->enter_sub(); + + my ($self, $file, $additional_params) = @_; + + $additional_params ||= { }; + + $file = $self->_prepare_html_template($file, $additional_params); + + my $template = HTML::Template->new("filename" => $file, + "die_on_bad_params" => 0, + "strict" => 0, + "case_sensitive" => 1, + "loop_context_vars" => 1, + "global_vars" => 1); + foreach my $key ($template->param()) { - my $param = $self->{$key}; - $param = $additional_params->{$key} if (grep(/^${key}$/, @additional_param_names)); + my $param = $additional_params->{$key} || $self->{$key}; $param = [] if (($template->query("name" => $key) eq "LOOP") && (ref($param) ne "ARRAY")); $template->param($key => $param); } @@ -556,6 +568,36 @@ sub parse_html_template { return $output; } +sub parse_html_template2 { + $main::lxdebug->enter_sub(); + + my ($self, $file, $additional_params) = @_; + + $additional_params ||= { }; + + $file = $self->_prepare_html_template($file, $additional_params); + + my $template = Template->new({ 'INTERPOLATE' => 0, + 'PRE_CHOMP' => Template::Constants::CHOMP_COLLAPSE, + 'POST_CHOMP' => Template::Constants::CHOMP_COLLAPSE, + 'EVAL_PERL' => 0, + 'ABSOLUTE' => 1, + 'CACHE_SIZE' => 0, + }) || die; + + map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self }; + + my $output; + $template->process($file, $additional_params, \$output); + $main::lxdebug->message(0, $output); + + $output = $main::locale->{iconv}->convert($output) if ($main::locale); + + $main::lxdebug->leave_sub(); + + return $output; +} + sub show_generic_error { my ($self, $error, $title, $action) = @_; diff --git a/SL/InstallationCheck.pm b/SL/InstallationCheck.pm index dc2a124f0..2c92136a3 100644 --- a/SL/InstallationCheck.pm +++ b/SL/InstallationCheck.pm @@ -16,6 +16,7 @@ use vars qw(@required_modules); { "name" => "IO::Wrap", "url" => "http://search.cpan.org/~dskoll/" }, { "name" => "Text::CSV_XS", "url" => "http://search.cpan.org/~hmbrand/" }, { "name" => "List::Util", "url" => "http://search.cpan.org/~gbarr/" }, + { "name" => "Template", "url" => "http://search.cpan.org/~abw/" }, ); sub module_available { diff --git a/SL/ReportGenerator.pm b/SL/ReportGenerator.pm index f3030b284..57a8c958c 100644 --- a/SL/ReportGenerator.pm +++ b/SL/ReportGenerator.pm @@ -279,7 +279,7 @@ sub prepare_html_content { foreach my $col_name (@visible_columns) { my $col = $row->{$col_name}; $col->{CELL_ROWS} = [ ]; - foreach my $i (0 .. scalar(@{ $col->{data} })) { + foreach my $i (0 .. scalar(@{ $col->{data} }) - 1) { push @{ $col->{CELL_ROWS} }, { 'data' => $self->html_format($col->{data}->[$i]), 'link' => $col->{link}->[$i], @@ -329,7 +329,7 @@ sub generate_html_content { my $self = shift; my $variables = $self->prepare_html_content(); - return $self->{form}->parse_html_template('report_generator/html_report', $variables); + return $self->{form}->parse_html_template2('report_generator/html_report', $variables); } sub verify_paper_size { diff --git a/doc/INSTALL b/doc/INSTALL index 0d8234167..4d25d0ce2 100644 --- a/doc/INSTALL +++ b/doc/INSTALL @@ -34,11 +34,12 @@ sind: * Text::CSV_XS * IO::Wrap (aus dem Paket IO::Stringy) * YAML +* Template Diese Pakete können bei den unterschiedlichen Distributionen anders heißen. -(Debian: apache, postgresql, libdbi-perl, libdbd-pg-perl, libpgperl, libhtml-template-perl, libclass-accessor-perl, libarchive-zip-perl, libtext-iconv-perl, libyaml-perl, libtext-csv-perl, libio-stringy-perl) +(Debian: apache, postgresql, libdbi-perl, libdbd-pg-perl, libpgperl, libhtml-template-perl, libclass-accessor-perl, libarchive-zip-perl, libtext-iconv-perl, libyaml-perl, libtext-csv-perl, libio-stringy-perl, libtemplate-perl) (Fedora: httpd, postgresql-server, perl-DBI, perl-DBD-Pg) -(SuSE: apache2, postgresql-server, perl-DBI, perl-DBD-Pg, perl-Archive-Zip, perl-Class-Accessor, perl-Text-Iconv, perl-Text-CSV_XS, perl-HTML-Template, perl-IO-stringy) +(SuSE: apache2, postgresql-server, perl-DBI, perl-DBD-Pg, perl-Archive-Zip, perl-Class-Accessor, perl-Text-Iconv, perl-Text-CSV_XS, perl-HTML-Template, perl-IO-stringy, perl-Template-Toolkit) Da Perl-CGI-Ajax nicht als Paket für Distributionen bereit steht, muß es mit der CPAN-Shell installiert werden. diff --git a/doc/UPGRADE b/doc/UPGRADE index c0c53cb1b..21ea84f18 100644 --- a/doc/UPGRADE +++ b/doc/UPGRADE @@ -15,7 +15,8 @@ Installationsverzeichnis gen Bitte beachten Sie auch die Liste der benötigten Perl-Module am Anfang der Datei "doc/INSTALL". Besonders nach einem Upgrade auf 2.4.2 muss sichergestellt werden, dass das Modul "YAML" installiert ist. v2.6.0 -benötigt zusätzlich die Module "Text::CSV_XS" und "IO::Wrap". +benötigt zusätzlich die Module "Text::CSV_XS", "IO::Wrap" (aus dem +Paket "IO::Stringy") sowie "Template" (Paket "Template-Toolkit"). Das Datenbankupgrade wird automatisch gestartet, wenn sich der erste Benutzer nach dem Upgrade der Dateien an Lx-Office anmeldet. diff --git a/locale/de/locales.pl b/locale/de/locales.pl index c568467f2..5bf561091 100755 --- a/locale/de/locales.pl +++ b/locale/de/locales.pl @@ -336,7 +336,7 @@ sub scanfile { } # is this a template call? - if (/parse_html_template\s*\(\s*[\"\']([\w\/]+)/) { + if (/parse_html_template2?\s*\(\s*[\"\']([\w\/]+)/) { my $newfile = "$basedir/templates/webpages/$1_master.html"; if (-f $newfile) { # &scanhtmlfile($newfile); diff --git a/templates/webpages/report_generator/html_report_de.html b/templates/webpages/report_generator/html_report_de.html index 2230b5766..ede17f975 100644 --- a/templates/webpages/report_generator/html_report_de.html +++ b/templates/webpages/report_generator/html_report_de.html @@ -1,4 +1,4 @@ - +[% USE HTML %] - -

-
+ [% IF MESSAGE %] +

[% MESSAGE %]

+ [% END %] -
+
[% TITLE %]
- -

-
+ [% IF TOP_INFO_TEXT %] +

[% TOP_INFO_TEXT %]

+ [% END %] - + [% RAW_TOP_INFO_TEXT %]

- - - + [% FOREACH col = COLUMN_HEADERS %] + + [% END %] - - - - - - align="" valign="" class="">
-
+ [% FOREACH row = ROWS %] + [% IF row.IS_CONTROL %] + [% IF row.IS_SEPARATOR %][% END %][% IF row.IS_COLSPAN_DATA %][% END %] + [% ELSE %] + + [% FOREACH col = row.COLUMNS %][% IF col.raw_data %][% col.raw_data %][% END %][% USE iterator(col.CELL_ROWS) %][% FOREACH cell_row = iterator %][% IF cell_row.data %][% IF cell_row.link %][% END %][% cell_row.data %][% IF cell_row.link %][% END %][% END %][% UNLESS iterator.last %]
aa[% END %][% END %] + [% END %]
- - + [% END %] + [% END %] - +
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %]


[% row.data %]


- + [% RAW_BOTTOM_INFO_TEXT %] - -

-
+ [% IF BOTTOM_INFO_TEXT %] +

[% BOTTOM_INFO_TEXT %]

+ [% END %] - -
- - + [% IF SHOW_EXPORT_BUTTONS %] + + + - - + [% FOREACH var = EXPORT_VARIABLES %] + [% END %] - - + +

Listenexport
- - + [% IF ALLOW_PDF_EXPORT %][% END %] + [% IF ALLOW_CSV_EXPORT %][% END %]

-
+ [% END %] diff --git a/templates/webpages/report_generator/html_report_master.html b/templates/webpages/report_generator/html_report_master.html index 2e2ecce0b..ede17f975 100644 --- a/templates/webpages/report_generator/html_report_master.html +++ b/templates/webpages/report_generator/html_report_master.html @@ -1,4 +1,4 @@ - +[% USE HTML %] - -

-
+ [% IF MESSAGE %] +

[% MESSAGE %]

+ [% END %] -
+
[% TITLE %]
- -

-
+ [% IF TOP_INFO_TEXT %] +

[% TOP_INFO_TEXT %]

+ [% END %] - + [% RAW_TOP_INFO_TEXT %]

- - - + [% FOREACH col = COLUMN_HEADERS %] + + [% END %] - - - - - - align="" valign="" class="">
-
+ [% FOREACH row = ROWS %] + [% IF row.IS_CONTROL %] + [% IF row.IS_SEPARATOR %][% END %][% IF row.IS_COLSPAN_DATA %][% END %] + [% ELSE %] + + [% FOREACH col = row.COLUMNS %][% IF col.raw_data %][% col.raw_data %][% END %][% USE iterator(col.CELL_ROWS) %][% FOREACH cell_row = iterator %][% IF cell_row.data %][% IF cell_row.link %][% END %][% cell_row.data %][% IF cell_row.link %][% END %][% END %][% UNLESS iterator.last %]
aa[% END %][% END %] + [% END %]
- - + [% END %] + [% END %] - +
[% IF col.link %][% END %][% HTML.escape(col.text) %][% IF col.link %][% IF col.show_sort_indicator %][% END %][% ELSE %][% IF col.show_sort_indicator %][% END %][% END %]


[% row.data %]


- + [% RAW_BOTTOM_INFO_TEXT %] - -

-
+ [% IF BOTTOM_INFO_TEXT %] +

[% BOTTOM_INFO_TEXT %]

+ [% END %] - -
- - + [% IF SHOW_EXPORT_BUTTONS %] + + + - - + [% FOREACH var = EXPORT_VARIABLES %] + [% END %] - - + +

- List export
- - + Listenexport
+ [% IF ALLOW_PDF_EXPORT %][% END %] + [% IF ALLOW_CSV_EXPORT %][% END %]

-
+ [% END %] -- 2.20.1