From 1b9d0f70b5e58c510ed2ab4337eb0f6512d779ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 10 Apr 2013 14:26:21 +0200 Subject: [PATCH] Erste Version Template Toolkit Druck --- SL/Template/LaTeX.pm | 13 +++++++++++-- SL/Template/OpenDocument.pm | 9 ++++++++- SL/Template/Plugin/LxLatex.pm | 27 +++++++++++++++++++++++++++ SL/Template/Simple.pm | 7 +++++++ 4 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 SL/Template/Plugin/LxLatex.pm diff --git a/SL/Template/LaTeX.pm b/SL/Template/LaTeX.pm index a862431d8..5d5008c1f 100644 --- a/SL/Template/LaTeX.pm +++ b/SL/Template/LaTeX.pm @@ -17,7 +17,6 @@ sub new { sub format_string { my ($self, $variable) = @_; - my $form = $self->{"form"}; $variable = $main::locale->quote_special_chars('Template/LaTeX', $variable); @@ -257,6 +256,9 @@ sub _parse_config_option { if ($key eq 'tag-style') { $self->set_tag_style(split(m/\s+/, $value, 2)); } + if ($key eq 'use-template-toolkit') { + $self->set_use_template_toolkit($value); + } } sub _parse_config_lines { @@ -350,7 +352,14 @@ sub parse { $self->{"forced_pagebreaks"} = []; - my $new_contents = $self->parse_block($contents); + my $new_contents; + if ($self->{use_template_toolkit}) { + my $additional_params = $::form; + + $::form->init_template->process(\$contents, $additional_params, \$new_contents) || die $::form->template->error; + } else { + $new_contents = $self->parse_block($contents); + } if (!defined($new_contents)) { $main::lxdebug->leave_sub(); return 0; diff --git a/SL/Template/OpenDocument.pm b/SL/Template/OpenDocument.pm index f9507f9ba..4eed5eae2 100644 --- a/SL/Template/OpenDocument.pm +++ b/SL/Template/OpenDocument.pm @@ -260,7 +260,14 @@ sub parse { $contents =~ s||${new_styles}|; $contents =~ s|[\n\r]||gm; - my $new_contents = $self->parse_block($contents); + my $new_contents; + if ($self->{use_template_toolkit}) { + my $additional_params = $::form; + + $::form->init_template->process(\$contents, $additional_params, \$new_contents) || die $::form->template->error; + } else { + $new_contents = $self->parse_block($contents); + } if (!defined($new_contents)) { $main::lxdebug->leave_sub(); return 0; diff --git a/SL/Template/Plugin/LxLatex.pm b/SL/Template/Plugin/LxLatex.pm new file mode 100644 index 000000000..6a539bdb4 --- /dev/null +++ b/SL/Template/Plugin/LxLatex.pm @@ -0,0 +1,27 @@ +package SL::Template::Plugin::LxLatex; + +use strict; +use parent qw( Template::Plugin ); + +my $cached_instance; + +sub new { + my $class = shift; + + return $cached_instance ||= $class->SUPER::new(@_); +} + +sub init { + my $self = shift; + + $self->install_filter($self->{ _ARGS }->[0] || 'T8'); + + return $self; +} + +sub filter { + my ($self, $text, $args) = @_; + return $::locale->quote_special_chars('Template/LaTeX', $text); +} + +return 'SL::Template::Plugin::LxLatex'; diff --git a/SL/Template/Simple.pm b/SL/Template/Simple.pm index 926ef1f7f..b1f155bf5 100644 --- a/SL/Template/Simple.pm +++ b/SL/Template/Simple.pm @@ -56,6 +56,13 @@ sub set_tag_style { $self->{substitute_vars_re} = "$self->{tag_start_qm}(.+?)$self->{tag_end_qm}"; } +sub set_use_template_toolkit { + my $self = shift; + my $value = shift; + + $self->{use_template_toolkit} = $value; +} + sub cleanup { my ($self) = @_; } -- 2.20.1