summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-05-26 23:57:13 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-05-26 23:57:13 +0000
commitb9982a0314b74a8fb342a20568a3e15b90d625bc (patch)
tree9cfe46d004c4f776babefe0eb7fbadb7435491bc /LedgerSMB/Template
parent5f4e46ad636f986668a65aeaa7ce7ae314365378 (diff)
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
Diffstat (limited to 'LedgerSMB/Template')
-rwxr-xr-xLedgerSMB/Template/HTML.pm31
-rwxr-xr-xLedgerSMB/Template/PDF.pm82
-rwxr-xr-xLedgerSMB/Template/PS.pm83
-rwxr-xr-xLedgerSMB/Template/TXT.pm83
4 files changed, 276 insertions, 3 deletions
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('<?lsmb'),
+ END_TAG => 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('<?lsmb'),
+ END_TAG => 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('<?lsmb'),
+ END_TAG => 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('<?lsmb'),
+ END_TAG => 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;