summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/TXT.pm
blob: d7a76430e8c67128bc0f74c6eee0f88ba8404a28 (plain)
  1. =head1 NAME
  2. LedgerSMB::Template::TXT 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 text.
  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::TXT;
  23. use Error qw(:try);
  24. use Template;
  25. sub get_template {
  26. my $name = shift;
  27. return "${name}.txt";
  28. }
  29. sub preprocess {
  30. my $rawvars = shift;
  31. my $vars;
  32. my $type = ref $rawvars;
  33. return $vars;
  34. }
  35. sub process {
  36. my $parent = shift;
  37. my $cleanvars = shift;
  38. my $template;
  39. $template = Template->new({
  40. INCLUDE_PATH => $parent->{include_path},
  41. START_TAG => quotemeta('<?lsmb'),
  42. END_TAG => quotemeta('?>'),
  43. DELIMITER => ';',
  44. }) || throw Error::Simple Template->error();
  45. if (not $template->process(
  46. get_template($parent->{template}),
  47. $cleanvars, "$parent->{outputfile}.txt", binmode => ':utf8')) {
  48. throw Error::Simple $template->error();
  49. }
  50. $parent->{mimetype} = 'text/plain';
  51. }
  52. sub postprocess {
  53. my $parent = shift;
  54. $parent->{rendered} = "$parent->{outputfile}.txt";
  55. return "$parent->{outputfile}.txt";
  56. }
  57. 1;