summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/PS.pm
blob: f8c048d031e62626d1d2e2bedc24bffaf95f63a5 (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. return $rawvars if $type =~ /^LedgerSMB::Locale/;
  35. if ($type eq 'ARRAY') {
  36. for (@{$rawvars}) {
  37. push @{$vars}, preprocess($_);
  38. }
  39. } else (!$type) {
  40. #XXX Fix escaping
  41. $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
  42. $rawvars =~ s/"(.*)"/``$1''/gs;
  43. return $rawvars;
  44. } else {
  45. for ( keys %{$rawvars} ) {
  46. $vars->{$_} = preprocess($rawvars->{$_});
  47. }
  48. }
  49. return $vars;
  50. }
  51. sub process {
  52. my $parent = shift;
  53. my $cleanvars = shift;
  54. my $template;
  55. $template = Template::Latex->new({
  56. LATEX_FORMAT => 'ps',
  57. INCLUDE_PATH => $parent->{include_path},
  58. START_TAG => quotemeta('<?lsmb'),
  59. END_TAG => quotemeta('?>'),
  60. DELIMITER => ';',
  61. }) || throw Error::Simple Template::Latex->error();
  62. if (not $template->process(
  63. get_template($parent->{template}),
  64. {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
  65. 'escape' => \&preprocess},
  66. "$parent->{outputfile}.ps", binmode => 1)) {
  67. throw Error::Simple $template->error();
  68. }
  69. $parent->{mimetype} = 'application/postscript';
  70. }
  71. sub postprocess {
  72. my $parent = shift;
  73. $parent->{rendered} = "$parent->{outputfile}.ps";
  74. return "$parent->{outputfile}.ps";
  75. }
  76. 1;