From b9982a0314b74a8fb342a20568a3e15b90d625bc Mon Sep 17 00:00:00 2001 From: tetragon Date: Sat, 26 May 2007 23:57:13 +0000 Subject: Adding PDF and Postscript support to LedgerSMB::Template Removing all calls to $form->parse_template git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1241 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template/HTML.pm | 31 +++++++++++++++-- LedgerSMB/Template/PDF.pm | 82 +++++++++++++++++++++++++++++++++++++++++++++ LedgerSMB/Template/PS.pm | 83 ++++++++++++++++++++++++++++++++++++++++++++++ LedgerSMB/Template/TXT.pm | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 276 insertions(+), 3 deletions(-) create mode 100755 LedgerSMB/Template/PDF.pm create mode 100755 LedgerSMB/Template/PS.pm create mode 100755 LedgerSMB/Template/TXT.pm (limited to 'LedgerSMB/Template') diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index d052319d..d02000a9 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -7,7 +7,7 @@ LedgerSMB::Template::HTML Template support module for LedgerSMB =over -=item get_template () +=item get_template ($name) Returns the appropriate template filename for this format. @@ -16,7 +16,11 @@ Returns the appropriate template filename for this format. This method returns a reference to a hash that contains a copy of the passed hashref's data with HTML entities converted to escapes. -=item postprocess () +=item process ($parent, $cleanvars) + +Processes the template for HTML. + +=item postprocess ($parent) Currently does nothing. @@ -37,6 +41,7 @@ package LedgerSMB::Template::HTML; use Error qw(:try); use CGI; +use Template; sub get_template { my $name = shift; @@ -65,9 +70,29 @@ sub preprocess { return $vars; } +sub process { + my $parent = shift; + my $cleanvars = shift; + my $template; + + $template = Template->new({ + INCLUDE_PATH => $parent->{include_path}, + START_TAG => quotemeta(' quotemeta('?>'), + DELIMITER => ';', + }) || throw Error::Simple Template->error(); + if (not $template->process( + get_template($parent->{template}), + $cleanvars, "$parent->{outputfile}.html", binmode => ':utf8')) { + throw Error::Simple $template->error(); + } + $parent->{mimetype} = 'text/html'; +} + sub postprocess { my $parent = shift; - return; + $parent->{rendered} = "$parent->{outputfile}.html"; + return "$parent->{outputfile}.html"; } 1; diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm new file mode 100755 index 00000000..72c080c6 --- /dev/null +++ b/LedgerSMB/Template/PDF.pm @@ -0,0 +1,82 @@ + +=head1 NAME + +LedgerSMB::Template::PDF Template support module for LedgerSMB + +=head1 METHODS + +=over + +=item get_template ($name) + +Returns the appropriate template filename for this format. + +=item preprocess ($vars) + +Currently does nothing. + +=item process ($parent, $cleanvars) + +Processes the template for PDF. + +=item postprocess ($parent) + +Currently does nothing. + +=back + +=head1 Copyright (C) 2007, The LedgerSMB core team. + +This work contains copyrighted information from a number of sources all used +with permission. + +It is released under the GNU General Public License Version 2 or, at your +option, any later version. See COPYRIGHT file for details. For a full list +including contact information of contributors, maintainers, and copyright +holders, see the CONTRIBUTORS file. +=cut + +package LedgerSMB::Template::PDF; + +use Error qw(:try); +use Template::Latex; + +sub get_template { + my $name = shift; + return "${name}.tex"; +} +sub preprocess { + my $rawvars = shift; + my $vars; + my $type = ref $rawvars; + return $vars; +} + +sub process { + my $parent = shift; + my $cleanvars = shift; + my $template; + + $template = Template::Latex->new({ + LATEX_FORMAT => 'pdf', + INCLUDE_PATH => $parent->{include_path}, + START_TAG => quotemeta(' quotemeta('?>'), + DELIMITER => ';', + }) || throw Error::Simple Template::Latex->error(); + + if (not $template->process( + get_template($parent->{template}), + $cleanvars, "$parent->{outputfile}.pdf", binmode => ':utf8')) { + throw Error::Simple $template->error(); + } + $parent->{mimetype} = 'application/pdf'; +} + +sub postprocess { + my $parent = shift; + $parent->{rendered} = "$parent->{outputfile}.pdf"; + return "$parent->{outputfile}.pdf"; +} + +1; diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm new file mode 100755 index 00000000..55349113 --- /dev/null +++ b/LedgerSMB/Template/PS.pm @@ -0,0 +1,83 @@ + +=head1 NAME + +LedgerSMB::Template::PS Template support module for LedgerSMB + +=head1 METHODS + +=over + +=item get_template ($name) + +Returns the appropriate template filename for this format. + +=item preprocess ($vars) + +Currently does nothing. + +=item process ($parent, $cleanvars) + +Processes the template for Postscript. + +=item postprocess ($parent) + +Currently does nothing. + +=back + +=head1 Copyright (C) 2007, The LedgerSMB core team. + +This work contains copyrighted information from a number of sources all used +with permission. + +It is released under the GNU General Public License Version 2 or, at your +option, any later version. See COPYRIGHT file for details. For a full list +including contact information of contributors, maintainers, and copyright +holders, see the CONTRIBUTORS file. +=cut + +package LedgerSMB::Template::PS; + +use Error qw(:try); +use Template::Latex; + +sub get_template { + my $name = shift; + return "${name}.tex"; +} + +sub preprocess { + my $rawvars = shift; + my $vars; + my $type = ref $rawvars; + return $vars; +} + +sub process { + my $parent = shift; + my $cleanvars = shift; + my $template; + + $template = Template::Latex->new({ + LATEX_FORMAT => 'ps', + INCLUDE_PATH => $parent->{include_path}, + START_TAG => quotemeta(' quotemeta('?>'), + DELIMITER => ';', + }) || throw Error::Simple Template::Latex->error(); + + if (not $template->process( + get_template($parent->{template}), + $cleanvars, "$parent->{outputfile}.ps", binmode => ':utf8')) { + throw Error::Simple $template->error(); + } + $parent->{mimetype} = 'application/postscript'; +} + +sub postprocess { + my $parent = shift; + $parent->{rendered} = "$parent->{outputfile}.ps"; + return "$parent->{outputfile}.ps"; +} + +1; diff --git a/LedgerSMB/Template/TXT.pm b/LedgerSMB/Template/TXT.pm new file mode 100755 index 00000000..d7a76430 --- /dev/null +++ b/LedgerSMB/Template/TXT.pm @@ -0,0 +1,83 @@ + +=head1 NAME + +LedgerSMB::Template::TXT Template support module for LedgerSMB + +=head1 METHODS + +=over + +=item get_template ($name) + +Returns the appropriate template filename for this format. + +=item preprocess ($vars) + +Currently does nothing. + +=item process ($parent, $cleanvars) + +Processes the template for text. + +=item postprocess ($parent) + +Currently does nothing. + +=back + +=head1 Copyright (C) 2007, The LedgerSMB core team. + +This work contains copyrighted information from a number of sources all used +with permission. + +It is released under the GNU General Public License Version 2 or, at your +option, any later version. See COPYRIGHT file for details. For a full list +including contact information of contributors, maintainers, and copyright +holders, see the CONTRIBUTORS file. +=cut + +package LedgerSMB::Template::TXT; + +use Error qw(:try); +use Template; + +sub get_template { + my $name = shift; + return "${name}.txt"; +} + +sub preprocess { + my $rawvars = shift; + my $vars; + my $type = ref $rawvars; + + return $vars; +} + +sub process { + my $parent = shift; + my $cleanvars = shift; + my $template; + + $template = Template->new({ + INCLUDE_PATH => $parent->{include_path}, + START_TAG => quotemeta(' quotemeta('?>'), + DELIMITER => ';', + }) || throw Error::Simple Template->error(); + + if (not $template->process( + get_template($parent->{template}), + $cleanvars, "$parent->{outputfile}.txt", binmode => ':utf8')) { + throw Error::Simple $template->error(); + } + $parent->{mimetype} = 'text/plain'; +} + +sub postprocess { + my $parent = shift; + $parent->{rendered} = "$parent->{outputfile}.txt"; + return "$parent->{outputfile}.txt"; +} + +1; -- cgit v1.2.3