diff options
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-x | LedgerSMB/Template.pm | 14 | ||||
-rwxr-xr-x | LedgerSMB/Template/HTML.pm | 14 |
2 files changed, 19 insertions, 9 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 938b8254..f302f3fc 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -39,12 +39,13 @@ option any later version. A copy of the license should have been included with your software. =cut + +package LedgerSMB::Template; + use Error qw(:try); use Template; use LedgerSMB::Sysconfig; -package LedgerSMB::Template; - sub new { my $class = shift; my $self = {}; @@ -89,6 +90,7 @@ sub render { my $self = shift; my $vars = shift; my $template; + my $format = "LedgerSMB::Template::$self->{format}"; $template = Template->new({ INCLUDE_PATH => $self->{include_path}, @@ -97,22 +99,22 @@ sub render { DELIMITER => ';', }) || throw Error::Simple Template->error(); - eval "require LedgerSMB::Template::$self->{format}"; + eval "require $format"; if ($@) { throw Error::Simple $@; } - my $cleanvars = &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars); + my $cleanvars = $format->can('preprocess')->($vars); if (UNIVERSAL::isa($self->{locale}, 'LedgerSMB::Locale')){ $cleanvars->{text} = \&$self->{locale}->text(); } if (not $template->process( - &{"LedgerSMB::Template::$self->{format}::get_template"}($self->{template}), + $format->can('get_template')->($self->{template}), $cleanvars, \$self->{output}, binmode => ':utf8')) { throw Error::Simple $template->error(); } - &{"LedgerSMB::Template::$self->{format}::postprocess"}($self); + $format->can('postprocess')->($self); return $self->{output}; } diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm index 9f1ae252..d052319d 100755 --- a/LedgerSMB/Template/HTML.pm +++ b/LedgerSMB/Template/HTML.pm @@ -9,6 +9,8 @@ LedgerSMB::Template::HTML Template support module for LedgerSMB =item get_template () +Returns the appropriate template filename for this format. + =item preprocess ($vars) This method returns a reference to a hash that contains a copy of the passed @@ -16,6 +18,8 @@ hashref's data with HTML entities converted to escapes. =item postprocess () +Currently does nothing. + =back =head1 Copyright (C) 2007, The LedgerSMB core team. @@ -29,11 +33,11 @@ including contact information of contributors, maintainers, and copyright holders, see the CONTRIBUTORS file. =cut +package LedgerSMB::Template::HTML; + use Error qw(:try); use CGI; -package LedgerSMB::Template::HTML; - sub get_template { my $name = shift; return "${name}.html"; @@ -46,15 +50,19 @@ sub preprocess { #XXX fix escaping function if ( $type eq 'ARRAY' ) { + for (@{$rawvars}) { + push @{$vars}, preprocess( $_ ); + } } elsif ( $type eq 'HASH' ) { for ( keys %{$rawvars} ) { - $vars->{$_} = preprocess( $rawvars[$_] ); + $vars->{$_} = preprocess( $rawvars->{$_} ); } } else { return CGI::escapeHTML($rawvars); } + return $vars; } sub postprocess { |