From 08e1b04d20e4f328638fbde9f7a2ae54a3dca966 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Thu, 22 Nov 2007 06:19:05 +0000 Subject: First (unsuccessful) attempt to automatically handle number formatting in the template engine.. Customer screen enhancements as well. git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1890 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Template.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'LedgerSMB/Template.pm') diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 28c1f40e..aff967a0 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -198,6 +198,35 @@ sub _valid_language { return 1; } +sub _preprocess { + my ($self, $vars) = @_; + return unless $self->{myconfig}; + use LedgerSMB; + if (UNIVERSAL::isa($vars, 'Math::BigFloat')){ + $vars = + LedgerSMB::format_amount('LedgerSMB', + {amount => $vars. + user => $self->{myconfig} }); + } + my $type = ref($vars); + + if ($type eq 'SCALAR' || !$type){ + return; + } + if ($type eq 'ARRAY'){ + for (@$vars){ + if (ref($_)){ + $self->_preprocess($_); + } + } + } + else { + for my $key (keys %$vars){ + $self->_preprocess($vars->{$key}); + } + } +} + sub render { my $self = shift; my $vars = shift; @@ -205,7 +234,9 @@ sub render { throw Error::Simple "Invalid format"; } my $format = "LedgerSMB::Template::$self->{format}"; - +# if ($self->{myconfig}){ +# $self->_preprocess($vars); +# } eval "require $format"; if ($@) { throw Error::Simple $@; -- cgit v1.2.3