diff options
author | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-06-01 14:13:33 +0000 |
---|---|---|
committer | tetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-06-01 14:13:33 +0000 |
commit | 5deb0455ef5b5a2ffe8cbe26a75cdd07e8788ded (patch) | |
tree | 2f1ff13c7c66bb7a4449fbe1cd0d30b24fc15187 | |
parent | 131a6de0170f0e79cc27cc77e972487ca9c5c33f (diff) |
Templating updates for output handling
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1248 4979c152-3d1c-0410-bac9-87ea11338e46
-rw-r--r-- | LedgerSMB/AM.pm | 2 | ||||
-rw-r--r-- | LedgerSMB/Mailer.pm | 2 | ||||
-rwxr-xr-x | LedgerSMB/Template.pm | 22 | ||||
-rwxr-xr-x | LedgerSMB/Template/PDF.pm | 3 | ||||
-rwxr-xr-x | LedgerSMB/Template/PS.pm | 3 | ||||
-rw-r--r-- | bin/arapprn.pl | 4 | ||||
-rw-r--r-- | bin/cp.pl | 2 | ||||
-rw-r--r-- | bin/io.pl | 2 | ||||
-rw-r--r-- | bin/jc.pl | 2 | ||||
-rw-r--r-- | bin/pos.pl | 2 | ||||
-rw-r--r-- | bin/rp.pl | 6 | ||||
-rw-r--r-- | t/04-template-handling.t | 42 | ||||
-rw-r--r-- | templates/demo/ap_transaction.tex | 3 | ||||
-rw-r--r-- | templates/demo/ar_transaction.tex | 3 | ||||
-rw-r--r-- | templates/demo/bin_list.tex | 3 | ||||
-rw-r--r-- | templates/demo/check.tex | 3 | ||||
-rw-r--r-- | templates/demo/invoice.tex | 3 | ||||
-rw-r--r-- | templates/demo/packing_list.tex | 3 | ||||
-rw-r--r-- | templates/demo/pick_list.tex | 3 | ||||
-rw-r--r-- | templates/demo/purchase_order.tex | 3 | ||||
-rw-r--r-- | templates/demo/receipt.tex | 3 | ||||
-rw-r--r-- | templates/demo/request_quotation.tex | 3 | ||||
-rw-r--r-- | templates/demo/sales_order.tex | 3 | ||||
-rw-r--r-- | templates/demo/sales_quotation.tex | 3 | ||||
-rw-r--r-- | templates/demo/statement.tex | 3 | ||||
-rw-r--r-- | templates/demo/timecard.tex | 3 | ||||
-rw-r--r-- | 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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -115,4 +116,4 @@ Tax Number: <?lsmb vendortaxnumber ?> <?lsmb END ?> \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -138,4 +139,4 @@ Tax Number: <?lsmb customertaxnumber ?> <?lsmb END ?> \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -120,4 +121,4 @@ \rule{\textwidth}{2pt} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -75,4 +76,4 @@ \vfill \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -215,4 +216,4 @@ All prices in \textbf{<?lsmb currency ?>}. \usebox{\ftr} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -140,4 +141,4 @@ returned. Returns must be shipped prepaid and properly insured. \usebox{\ftr} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -109,4 +110,4 @@ } \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -174,4 +175,4 @@ Fax: <?lsmb shiptofax ?> %\footnotetext[1]{\tiny } \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -75,4 +76,4 @@ \vfill \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -153,4 +154,4 @@ Please provide price and delivery time for the following items: } \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -183,4 +184,4 @@ Terms: <?lsmb terms ?> days \rule{\textwidth}{0.5pt} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -153,4 +154,4 @@ Terms: <?lsmb terms ?> days \usebox{\ftr} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -82,4 +83,4 @@ All amounts in \textbf{<?lsmb currency ?>} funds. Please make check payable to \textbf{<?lsmb company ?>} \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -49,4 +50,4 @@ <?lsmb notes ?> \end{document} - +<?lsmb END ?> 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 @@ +<?lsmb FILTER latex -?> \documentclass{scrartcl} \usepackage[utf8]{inputenc} \usepackage{tabularx} @@ -144,4 +145,4 @@ Fax: <?lsmb shiptofax ?> \vfill \end{document} - +<?lsmb END ?> |