Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision bf3cc4b6

Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt

  • ID bf3cc4b6658497e7f7d15bbe16d1795fefb7cf05
  • Vorgänger 18da4a96
  • Nachfolger 1663bada

Einführung des Modules "Template" als schnellere Alternative (Faktor 9) zu "HTML::Template". Wird via $form->parse_html_template2() aufgerufen. Umstellung der von ReportGenerator verwendeten Vorlage auf die Verwendung von "Template".

Unterschiede anzeigen:

SL/Form.pm
40 40

  
41 41
use Cwd;
42 42
use HTML::Template;
43
use Template;
43 44
use SL::Template;
44 45
use CGI::Ajax;
45 46
use SL::DBUtils;
......
474 475
  $main::lxdebug->leave_sub();
475 476
}
476 477

  
477
sub parse_html_template {
478
sub _prepare_html_template {
478 479
  $main::lxdebug->enter_sub();
479 480

  
480 481
  my ($self, $file, $additional_params) = @_;
......
508 509
    die($info);
509 510
  }
510 511

  
511
  my $template = HTML::Template->new("filename" => $file,
512
                                     "die_on_bad_params" => 0,
513
                                     "strict" => 0,
514
                                     "case_sensitive" => 1,
515
                                     "loop_context_vars" => 1,
516
                                     "global_vars" => 1);
517

  
518
  $additional_params = {} unless ($additional_params);
519 512
  if ($self->{"DEBUG"}) {
520 513
    $additional_params->{"DEBUG"} = $self->{"DEBUG"};
521 514
  }
......
539 532
  $additional_params->{"conf_latex_templates"}        = $main::latex;
540 533
  $additional_params->{"conf_opendocument_templates"} = $main::opendocument_templates;
541 534

  
542
  my @additional_param_names = keys(%{$additional_params});
535
  $main::lxdebug->leave_sub();
536

  
537
  return $file;
538
}
539

  
540
sub parse_html_template {
541
  $main::lxdebug->enter_sub();
542

  
543
  my ($self, $file, $additional_params) = @_;
544

  
545
  $additional_params ||= { };
546

  
547
  $file = $self->_prepare_html_template($file, $additional_params);
548

  
549
  my $template = HTML::Template->new("filename" => $file,
550
                                     "die_on_bad_params" => 0,
551
                                     "strict" => 0,
552
                                     "case_sensitive" => 1,
553
                                     "loop_context_vars" => 1,
554
                                     "global_vars" => 1);
555

  
543 556
  foreach my $key ($template->param()) {
544
    my $param = $self->{$key};
545
    $param = $additional_params->{$key} if (grep(/^${key}$/, @additional_param_names));
557
    my $param = $additional_params->{$key} || $self->{$key};
546 558
    $param = [] if (($template->query("name" => $key) eq "LOOP") && (ref($param) ne "ARRAY"));
547 559
    $template->param($key => $param);
548 560
  }
......
556 568
  return $output;
557 569
}
558 570

  
571
sub parse_html_template2 {
572
  $main::lxdebug->enter_sub();
573

  
574
  my ($self, $file, $additional_params) = @_;
575

  
576
  $additional_params ||= { };
577

  
578
  $file = $self->_prepare_html_template($file, $additional_params);
579

  
580
  my $template = Template->new({ 'INTERPOLATE' => 0,
581
                                 'PRE_CHOMP'   => Template::Constants::CHOMP_COLLAPSE,
582
                                 'POST_CHOMP'  => Template::Constants::CHOMP_COLLAPSE,
583
                                 'EVAL_PERL'   => 0,
584
                                 'ABSOLUTE'    => 1,
585
                                 'CACHE_SIZE'  => 0,
586
                               }) || die;
587

  
588
  map { $additional_params->{$_} ||= $self->{$_} } keys %{ $self };
589

  
590
  my $output;
591
  $template->process($file, $additional_params, \$output);
592
  $main::lxdebug->message(0, $output);
593

  
594
  $output = $main::locale->{iconv}->convert($output) if ($main::locale);
595

  
596
  $main::lxdebug->leave_sub();
597

  
598
  return $output;
599
}
600

  
559 601
sub show_generic_error {
560 602
  my ($self, $error, $title, $action) = @_;
561 603

  

Auch abrufbar als: Unified diff