summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/PS.pm
blob: ac58204d2eab23edb4ed08ef4c6fbd48d155fe55 (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. use LedgerSMB::Template::TTI18N;
  26. sub get_template {
  27. my $name = shift;
  28. return "${name}.tex";
  29. }
  30. sub preprocess {
  31. my $rawvars = shift;
  32. my $vars;
  33. my $type = ref $rawvars;
  34. #XXX fix escaping
  35. return $rawvars;
  36. }
  37. sub process {
  38. my $parent = shift;
  39. my $cleanvars = shift;
  40. my $template;
  41. $template = Template::Latex->new({
  42. LATEX_FORMAT => 'ps',
  43. INCLUDE_PATH => $parent->{include_path},
  44. START_TAG => quotemeta('<?lsmb'),
  45. END_TAG => quotemeta('?>'),
  46. DELIMITER => ';',
  47. }) || throw Error::Simple Template::Latex->error();
  48. if (not $template->process(
  49. get_template($parent->{template}),
  50. {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
  51. 'escape' => \&preprocess},
  52. "$parent->{outputfile}.ps", binmode => 1)) {
  53. throw Error::Simple $template->error();
  54. }
  55. $parent->{mimetype} = 'application/postscript';
  56. }
  57. sub postprocess {
  58. my $parent = shift;
  59. $parent->{rendered} = "$parent->{outputfile}.ps";
  60. return "$parent->{outputfile}.ps";
  61. }
  62. 1;