diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-09-16 15:56:12 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-09-16 15:56:12 +0000 |
commit | 1781468582b9eac650f45c874134ed8a671bfdfe (patch) | |
tree | 1e6e595e08f444cfac18552f62eadfb2b2a8e473 /LedgerSMB/Template | |
parent | c24b6d1d47bf5d0bb2771067ba03955a5877201f (diff) |
Add support for templates in string form
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1618 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Template')
-rwxr-xr-x | LedgerSMB/Template/CSV.pm | 10 | ||||
-rwxr-xr-x | LedgerSMB/Template/HTML.pm | 10 | ||||
-rwxr-xr-x | LedgerSMB/Template/PDF.pm | 10 | ||||
-rwxr-xr-x | LedgerSMB/Template/PS.pm | 10 | ||||
-rwxr-xr-x | LedgerSMB/Template/TXT.pm | 10 |
5 files changed, 45 insertions, 5 deletions
diff --git a/LedgerSMB/Template/CSV.pm b/LedgerSMB/Template/CSV.pm index bd06e478..9700a18a 100755 --- a/LedgerSMB/Template/CSV.pm +++ b/LedgerSMB/Template/CSV.pm @@ -75,6 +75,7 @@ sub process { my $parent = shift; my $cleanvars = shift; my $template; + my $source; my $output; if ($parent->{outputfile}) { @@ -82,6 +83,13 @@ sub process { } else { $output = \$parent->{output}; } + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } $template = Template->new({ INCLUDE_PATH => $parent->{include_path}, START_TAG => quotemeta('<?lsmb'), @@ -92,7 +100,7 @@ sub process { }) || throw Error::Simple Template->error(); if (not $template->process( - get_template($parent->{template}), + $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, $output, binmode => ':utf8')) { diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index da9d2e00..cb9bd2fe 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -76,12 +76,20 @@ sub process { my $cleanvars = shift; my $template; my $output; + my $source; if ($parent->{outputfile}) { $output = "$parent->{outputfile}.html"; } else { $output = \$parent->{output}; } + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } $template = Template->new({ INCLUDE_PATH => $parent->{include_path}, START_TAG => quotemeta('<?lsmb'), @@ -92,7 +100,7 @@ sub process { DEBUG_FORMAT => '', }) || throw Error::Simple Template->error(); if (not $template->process( - get_template($parent->{template}), + $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, $output, binmode => ':utf8')) { diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm index 617ca41f..ef7ca519 100755 --- a/LedgerSMB/Template/PDF.pm +++ b/LedgerSMB/Template/PDF.pm @@ -74,9 +74,17 @@ sub process { my $parent = shift; my $cleanvars = shift; my $template; + my $source; $parent->{outputfile} ||= "${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$"; + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } $template = Template::Latex->new({ LATEX_FORMAT => 'pdf', INCLUDE_PATH => $parent->{include_path}, @@ -88,7 +96,7 @@ sub process { }) || throw Error::Simple Template::Latex->error(); if (not $template->process( - get_template($parent->{template}), + $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, "$parent->{outputfile}.pdf", binmode => 1)) { diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm index 7ab41dc2..fc732590 100755 --- a/LedgerSMB/Template/PS.pm +++ b/LedgerSMB/Template/PS.pm @@ -74,9 +74,17 @@ sub process { my $parent = shift; my $cleanvars = shift; my $template; + my $source; $parent->{outputfile} ||= "${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$"; + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } $template = Template::Latex->new({ LATEX_FORMAT => 'ps', INCLUDE_PATH => $parent->{include_path}, @@ -88,7 +96,7 @@ sub process { }) || throw Error::Simple Template::Latex->error(); if (not $template->process( - get_template($parent->{template}), + $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, "$parent->{outputfile}.ps", binmode => 1)) { diff --git a/LedgerSMB/Template/TXT.pm b/LedgerSMB/Template/TXT.pm index 2d902a39..d6fa3e4b 100755 --- a/LedgerSMB/Template/TXT.pm +++ b/LedgerSMB/Template/TXT.pm @@ -56,6 +56,7 @@ sub process { my $parent = shift; my $cleanvars = shift; my $template; + my $source; my $output; if ($parent->{outputfile}) { @@ -63,6 +64,13 @@ sub process { } else { $output = \$parent->{output}; } + if (ref $parent->{template} eq 'SCALAR') { + $source = $parent->{template}; + } elsif (ref $parent->{template} eq 'ARRAY') { + $source = join "\n", @{$parent->{template}}; + } else { + $source = get_template($parent->{template}); + } $template = Template->new({ INCLUDE_PATH => $parent->{include_path}, START_TAG => quotemeta('<?lsmb'), @@ -73,7 +81,7 @@ sub process { }) || throw Error::Simple Template->error(); if (not $template->process( - get_template($parent->{template}), + $source, {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs, 'escape' => \&preprocess}, $output, binmode => ':utf8')) { |