From b9982a0314b74a8fb342a20568a3e15b90d625bc Mon Sep 17 00:00:00 2001 From: tetragon Date: Sat, 26 May 2007 23:57:13 +0000 Subject: 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 --- LedgerSMB/Template.pm | 67 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 19 deletions(-) (limited to 'LedgerSMB/Template.pm') diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 77c7a78a..0a822f7d 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -3,10 +3,9 @@ LedgerSMB::Template - Template support module for LedgerSMB -=head1 SYOPSIS +=head1 SYNOPSIS -This module renders templates to provide HTML interfaces. LaTeX support -forthcoming. +This module renders templates. =head1 METHODS @@ -25,6 +24,10 @@ include_path allows one to override the template directory and use this with use This command renders the template and writes the result to standard output. Currently email and server-side printing are not supported. +=item output + +This function outputs the rendered file in an appropriate manner. + =item my $bool = _valid_language() This command checks for valid langages. Returns 1 if the language is valid, @@ -43,7 +46,6 @@ your software. package LedgerSMB::Template; use Error qw(:try); -use Template; use LedgerSMB::Sysconfig; sub new { @@ -55,7 +57,13 @@ sub new { $self->{template} = $args{template}; $self->{format} = $args{format}; $self->{language} = $args{language}; - $self->{output} = ''; + if ($args{outputfile}) { + $self->{outputfile} = + "${LedgerSMB::Sysconfig::tempdir}/$args{outputfile}"; + } else { + $self->{outputfile} = + "${LedgerSMB::Sysconfig::tempdir}/$args{template}-output"; + } $self->{include_path} = $args{path}; $self->{locale} = $args{locale}; @@ -89,16 +97,8 @@ sub _valid_language { sub render { my $self = shift; my $vars = shift; - my $template; my $format = "LedgerSMB::Template::$self->{format}"; - $template = Template->new({ - INCLUDE_PATH => $self->{include_path}, - START_TAG => quotemeta(' quotemeta('?>'), - DELIMITER => ';', - }) || throw Error::Simple Template->error(); - eval "require $format"; if ($@) { throw Error::Simple $@; @@ -108,15 +108,44 @@ sub render { if (UNIVERSAL::isa($self->{locale}, 'LedgerSMB::Locale')){ $cleanvars->{text} = $self->{locale}->text(); } - if (not $template->process( - $format->can('get_template')->($self->{template}), - $cleanvars, \$self->{output}, binmode => ':utf8')) { - throw Error::Simple $template->error(); + + $format->can('process')->($self, $cleanvars); + return $format->can('postprocess')->($self); +} + +sub output { + my $self = shift; + my $method = shift; + + if ('mail' eq lc $method) { + #XXX do something + $self->_http_output; + } elsif ('print' eq lc $method) { + #XXX do something + $self->_http_output; + } else { + $self->_http_output; } +} - $format->can('postprocess')->($self); +sub _http_output { + my $self = shift; + my $FH; - return $self->{output}; + if ($self->{mimetype} =~ /^text/) { + print "Content-Type: $self->{mimetype}; charset=utf-8\n\n"; + } else { + print "Content-Type: $self->{mimetype}\n\n"; + } + open($FH, '<', $self->{rendered}) or + throw Error::Simple 'Unable to open rendered file'; + while (<$FH>) { + print $_; + } + close($FH); + unlink($self->{rendered}) or + throw Error::Simple 'Unable to delete output file'; + exit; } 1; -- cgit v1.2.3