From 5deb0455ef5b5a2ffe8cbe26a75cdd07e8788ded Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 1 Jun 2007 14:13:33 +0000 Subject: Templating updates for output handling git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1248 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/AM.pm | 2 +- LedgerSMB/Mailer.pm | 2 +- LedgerSMB/Template.pm | 22 +++++++++++++------ LedgerSMB/Template/PDF.pm | 3 ++- LedgerSMB/Template/PS.pm | 3 ++- bin/arapprn.pl | 4 ++-- bin/cp.pl | 2 +- bin/io.pl | 2 +- bin/jc.pl | 2 +- bin/pos.pl | 2 +- bin/rp.pl | 6 +++--- t/04-template-handling.t | 42 ++++++++++++++++++++++++++++++++++-- templates/demo/ap_transaction.tex | 3 ++- templates/demo/ar_transaction.tex | 3 ++- templates/demo/bin_list.tex | 3 ++- templates/demo/check.tex | 3 ++- templates/demo/invoice.tex | 3 ++- templates/demo/packing_list.tex | 3 ++- templates/demo/pick_list.tex | 3 ++- templates/demo/purchase_order.tex | 3 ++- templates/demo/receipt.tex | 3 ++- templates/demo/request_quotation.tex | 3 ++- templates/demo/sales_order.tex | 3 ++- templates/demo/sales_quotation.tex | 3 ++- templates/demo/statement.tex | 3 ++- templates/demo/timecard.tex | 3 ++- templates/demo/work_order.tex | 3 ++- 27 files changed, 101 insertions(+), 36 deletions(-) diff --git a/LedgerSMB/AM.pm b/LedgerSMB/AM.pm index 4ff9f3ed..74034fd3 100644 --- a/LedgerSMB/AM.pm +++ b/LedgerSMB/AM.pm @@ -1628,7 +1628,7 @@ sub backup { qx(PGPASSWORD="$myconfig->{dbpasswd}" pg_dump -U $myconfig->{dbuser} -h $myconfig->{dbhost} -Fc -p $myconfig->{dbport} $myconfig->{dbname}); close OUT; use LedgerSMB::Mailer; - $mail = new Mailer; + $mail = new LedgerSMB::Mailer; $mail->{to} = qq|"$myconfig->{name}" <$myconfig->{email}>|; $mail->{from} = qq|"$myconfig->{name}" <$myconfig->{email}>|; diff --git a/LedgerSMB/Mailer.pm b/LedgerSMB/Mailer.pm index eb1d4a9b..7fd7f1fb 100644 --- a/LedgerSMB/Mailer.pm +++ b/LedgerSMB/Mailer.pm @@ -33,7 +33,7 @@ # #====================================================================== -package Mailer; +package LedgerSMB::Mailer; use MIME::Lite; use MIME::Base64; diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 0a822f7d..9d08d201 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -47,6 +47,7 @@ package LedgerSMB::Template; use Error qw(:try); use LedgerSMB::Sysconfig; +use LedgerSMB::Mailer; sub new { my $class = shift; @@ -115,14 +116,13 @@ sub render { sub output { my $self = shift; - my $method = shift; + my %args = @_; + my $method = $args{method} || $args{media}; - if ('mail' eq lc $method) { - #XXX do something - $self->_http_output; + if ('email' eq lc $method) { + $self->_email_output; } elsif ('print' eq lc $method) { - #XXX do something - $self->_http_output; + $self->_lpr_output; } else { $self->_http_output; } @@ -148,4 +148,14 @@ sub _http_output { exit; } +sub _email_output { + my $self = shift; + my $mail = new LedgerSMB::Mailer; + #TODO stub +} + +sub _lpr_output { + my $self = shift; + #TODO stub +} 1; diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm index 72c080c6..7286b917 100755 --- a/LedgerSMB/Template/PDF.pm +++ b/LedgerSMB/Template/PDF.pm @@ -49,7 +49,8 @@ sub preprocess { my $rawvars = shift; my $vars; my $type = ref $rawvars; - return $vars; + #XXX Fix escaping + return $rawvars; } sub process { diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm index 55349113..10a3806e 100755 --- a/LedgerSMB/Template/PS.pm +++ b/LedgerSMB/Template/PS.pm @@ -50,7 +50,8 @@ sub preprocess { my $rawvars = shift; my $vars; my $type = ref $rawvars; - return $vars; + #XXX fix escaping + return $rawvars; } sub process { diff --git a/bin/arapprn.pl b/bin/arapprn.pl index 845d829a..b1885e66 100644 --- a/bin/arapprn.pl +++ b/bin/arapprn.pl @@ -290,7 +290,7 @@ sub print_check { format => uc $form->{'format'} ); try { $template->render($form); - $template->output($form->{'media'}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; @@ -558,7 +558,7 @@ sub print_transaction { format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/bin/cp.pl b/bin/cp.pl index d9316fea..15552a37 100644 --- a/bin/cp.pl +++ b/bin/cp.pl @@ -1477,7 +1477,7 @@ sub print_form { template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/bin/io.pl b/bin/io.pl index 6b21c95a..13b646ef 100644 --- a/bin/io.pl +++ b/bin/io.pl @@ -1771,7 +1771,7 @@ sub print_form { template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/bin/jc.pl b/bin/jc.pl index 9f6c0015..fe6900a4 100644 --- a/bin/jc.pl +++ b/bin/jc.pl @@ -2209,7 +2209,7 @@ qq|$form->{"${item}hour"}:$form->{"${item}min"}:$form->{"${item}sec"}|; template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/bin/pos.pl b/bin/pos.pl index 3071bf33..cb37f7d3 100644 --- a/bin/pos.pl +++ b/bin/pos.pl @@ -1005,7 +1005,7 @@ sub print_form { template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/bin/rp.pl b/bin/rp.pl index 5886c2da..242f69de 100644 --- a/bin/rp.pl +++ b/bin/rp.pl @@ -1084,7 +1084,7 @@ sub generate_income_statement { template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; @@ -1134,7 +1134,7 @@ sub generate_balance_sheet { template => $form->{'formname'}, format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; @@ -2282,7 +2282,7 @@ sub print_form { format => uc $form->{format} ); try { $template->render($form); - $template->output($form->{media}); + $template->output(%{$form}); } catch Error::Simple with { my $E = shift; diff --git a/t/04-template-handling.t b/t/04-template-handling.t index 04048b10..0e2f52bb 100644 --- a/t/04-template-handling.t +++ b/t/04-template-handling.t @@ -3,13 +3,14 @@ use strict; use warnings; -$ENV{TMPDIR} = 't/var'; +#$ENV{TMPDIR} = 't/var'; +$ENV{TMPDIR} = '/Users/seneca/sourceforge-svn/ledger-smb/trunk/t/var'; use Test::More 'no_plan'; use Test::Trap qw(trap $trap); use Test::Exception; -use Error qw(:try); +use Error qw(:try :warndie); use LedgerSMB::AM; use LedgerSMB::Form; @@ -212,3 +213,40 @@ ok(defined $template, 'Template, new: Object creation with non-existent format'); throws_ok{$template->render({'login' => 'foo'})} qr/Can't locate/, 'Template, render: Invalid format caught'; + +$template = undef; +$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'PDF', + 'template' => '04-template'); +ok(defined $template, + 'Template, new: Object creation with format and template'); +isa_ok($template, 'LedgerSMB::Template', + 'Template, new: Object creation with format and template'); +is($template->{include_path}, 't/data', + 'Template, new: Object creation with format and template'); +is($template->render({'login' => 'foo\&bar'}), 't/var/04-template-output.pdf', + 'Template, render: Simple PDF template, default filename'); +ok(-e 't/var/04-template-output.pdf', 'Template, render (PDF): File created'); + +$template = undef; +$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'PS', + 'template' => '04-template'); +ok(defined $template, + 'Template, new: Object creation with format and template'); +isa_ok($template, 'LedgerSMB::Template', + 'Template, new: Object creation with format and template'); +is($template->{include_path}, 't/data', + 'Template, new: Object creation with format and template'); +is($template->render({'login' => 'foo\&bar'}), 't/var/04-template-output.ps', + 'Template, render: Simple Postscript template, default filename'); +ok(-e 't/var/04-template-output.ps', 'Template, render (PS): File created'); +##open($FH, '<', 't/var/04-template-output.html'); +##@r = <$FH>; +##close($FH); +##chomp(@r); +##is(join("\n", @r), "I am a template.\nLook at me foo&bar.", +## 'Template, render (HTML): Simple HTML template, correct output'); +##is(unlink('t/var/04-template-output.html'), 1, +## 'Template, render: removing testfile'); +##ok(!-e 't/var/04-template-output.html', +## 'Template, render (HTML): testfile removed'); + diff --git a/templates/demo/ap_transaction.tex b/templates/demo/ap_transaction.tex index c8edaf4c..371d26df 100644 --- a/templates/demo/ap_transaction.tex +++ b/templates/demo/ap_transaction.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -115,4 +116,4 @@ Tax Number: \end{document} - + diff --git a/templates/demo/ar_transaction.tex b/templates/demo/ar_transaction.tex index 19834aaf..b2f47dd2 100644 --- a/templates/demo/ar_transaction.tex +++ b/templates/demo/ar_transaction.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -138,4 +139,4 @@ Tax Number: \end{document} - + diff --git a/templates/demo/bin_list.tex b/templates/demo/bin_list.tex index 8b96825c..fb7d2458 100644 --- a/templates/demo/bin_list.tex +++ b/templates/demo/bin_list.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -120,4 +121,4 @@ \rule{\textwidth}{2pt} \end{document} - + diff --git a/templates/demo/check.tex b/templates/demo/check.tex index b5c8a31c..34da77c1 100644 --- a/templates/demo/check.tex +++ b/templates/demo/check.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -75,4 +76,4 @@ \vfill \end{document} - + diff --git a/templates/demo/invoice.tex b/templates/demo/invoice.tex index 36af8d88..89a416bf 100644 --- a/templates/demo/invoice.tex +++ b/templates/demo/invoice.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -215,4 +216,4 @@ All prices in \textbf{}. \usebox{\ftr} \end{document} - + diff --git a/templates/demo/packing_list.tex b/templates/demo/packing_list.tex index a1b638ec..0bda54b5 100644 --- a/templates/demo/packing_list.tex +++ b/templates/demo/packing_list.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -140,4 +141,4 @@ returned. Returns must be shipped prepaid and properly insured. \usebox{\ftr} \end{document} - + diff --git a/templates/demo/pick_list.tex b/templates/demo/pick_list.tex index cc7f67fd..1dd612ce 100644 --- a/templates/demo/pick_list.tex +++ b/templates/demo/pick_list.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -109,4 +110,4 @@ } \end{document} - + diff --git a/templates/demo/purchase_order.tex b/templates/demo/purchase_order.tex index c60073a6..99582f41 100644 --- a/templates/demo/purchase_order.tex +++ b/templates/demo/purchase_order.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -174,4 +175,4 @@ Fax: %\footnotetext[1]{\tiny } \end{document} - + diff --git a/templates/demo/receipt.tex b/templates/demo/receipt.tex index 16e88ed0..e3e04c91 100644 --- a/templates/demo/receipt.tex +++ b/templates/demo/receipt.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -75,4 +76,4 @@ \vfill \end{document} - + diff --git a/templates/demo/request_quotation.tex b/templates/demo/request_quotation.tex index feccc631..d95e5323 100644 --- a/templates/demo/request_quotation.tex +++ b/templates/demo/request_quotation.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -153,4 +154,4 @@ Please provide price and delivery time for the following items: } \end{document} - + diff --git a/templates/demo/sales_order.tex b/templates/demo/sales_order.tex index 2d382cb2..a2dddb14 100644 --- a/templates/demo/sales_order.tex +++ b/templates/demo/sales_order.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -183,4 +184,4 @@ Terms: days \rule{\textwidth}{0.5pt} \end{document} - + diff --git a/templates/demo/sales_quotation.tex b/templates/demo/sales_quotation.tex index 43a9fdfc..04bd971b 100644 --- a/templates/demo/sales_quotation.tex +++ b/templates/demo/sales_quotation.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -153,4 +154,4 @@ Terms: days \usebox{\ftr} \end{document} - + diff --git a/templates/demo/statement.tex b/templates/demo/statement.tex index 8fedc55f..b6580af6 100644 --- a/templates/demo/statement.tex +++ b/templates/demo/statement.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -82,4 +83,4 @@ All amounts in \textbf{} funds. Please make check payable to \textbf{} \end{document} - + diff --git a/templates/demo/timecard.tex b/templates/demo/timecard.tex index e303ac10..8e0cb7c2 100644 --- a/templates/demo/timecard.tex +++ b/templates/demo/timecard.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -49,4 +50,4 @@ \end{document} - + diff --git a/templates/demo/work_order.tex b/templates/demo/work_order.tex index c08a2da5..aaa95c65 100644 --- a/templates/demo/work_order.tex +++ b/templates/demo/work_order.tex @@ -1,3 +1,4 @@ + \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -144,4 +145,4 @@ Fax: \vfill \end{document} - + -- cgit v1.2.3