summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/PS.pm
blob: 10a3806e28dab144d228260a8e61c9f9d5364102 (plain)
  1. =head1 NAME
  2. LedgerSMB::Template::PS Template support module for LedgerSMB
  3. =head1 METHODS
  4. =over
  5. =item get_template ($name)
  6. Returns the appropriate template filename for this format.
  7. =item preprocess ($vars)
  8. Currently does nothing.
  9. =item process ($parent, $cleanvars)
  10. Processes the template for Postscript.
  11. =item postprocess ($parent)
  12. Currently does nothing.
  13. =back
  14. =head1 Copyright (C) 2007, The LedgerSMB core team.
  15. This work contains copyrighted information from a number of sources all used
  16. with permission.
  17. It is released under the GNU General Public License Version 2 or, at your
  18. option, any later version. See COPYRIGHT file for details. For a full list
  19. including contact information of contributors, maintainers, and copyright
  20. holders, see the CONTRIBUTORS file.
  21. =cut
  22. package LedgerSMB::Template::PS;
  23. use Error qw(:try);
  24. use Template::Latex;
  25. sub get_template {
  26. my $name = shift;
  27. return "${name}.tex";
  28. }
  29. sub preprocess {
  30. my $rawvars = shift;
  31. my $vars;
  32. my $type = ref $rawvars;
  33. #XXX fix escaping
  34. return $rawvars;
  35. }
  36. sub process {
  37. my $parent = shift;
  38. my $cleanvars = shift;
  39. my $template;
  40. $template = Template::Latex->new({
  41. LATEX_FORMAT => 'ps',
  42. INCLUDE_PATH => $parent->{include_path},
  43. START_TAG => quotemeta('<?lsmb'),
  44. END_TAG => quotemeta('?>'),
  45. DELIMITER => ';',
  46. }) || throw Error::Simple Template::Latex->error();
  47. if (not $template->process(
  48. get_template($parent->{template}),
  49. $cleanvars, "$parent->{outputfile}.ps", binmode => ':utf8')) {
  50. throw Error::Simple $template->error();
  51. }
  52. $parent->{mimetype} = 'application/postscript';
  53. }
  54. sub postprocess {
  55. my $parent = shift;
  56. $parent->{rendered} = "$parent->{outputfile}.ps";
  57. return "$parent->{outputfile}.ps";
  58. }
  59. 1;