summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template.pm
diff options
context:
space:
mode:
Diffstat (limited to 'LedgerSMB/Template.pm')
-rwxr-xr-xLedgerSMB/Template.pm112
1 files changed, 64 insertions, 48 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm
index 2c1a9d8f..93254df1 100755
--- a/LedgerSMB/Template.pm
+++ b/LedgerSMB/Template.pm
@@ -3,15 +3,15 @@
# Template support module for LedgerSMB
# LedgerSMB::Template
#
-# LedgerSMB
+# LedgerSMB
# Small Medium Business Accounting software
# http://www.ledgersmb.org/
-#
+#
#
# Copyright (C) 2007
# This work contains copyrighted information from a number of sources all used
-# with permission. It is released under the GNU General Public License
-# Version 2 or, at your option, any later version. See COPYRIGHT file for
+# with permission. It is released under the GNU General Public License
+# Version 2 or, at your option, any later version. See COPYRIGHT file for
# details.
#
#
@@ -27,61 +27,77 @@ use LedgerSMB::Sysconfig;
package LedgerSMB::Template;
sub new {
- my $class = shift;
- my $self = {};
- $self->{myconfig} = shift;
- $self->{template} = shift;
- $self->{format} = shift;
- $self->{language} = shift;
- $self->{output} = '';
- bless $self, $class;
- return $self;
+ my $class = shift;
+ my $self = {};
+ $self->{myconfig} = shift;
+ $self->{template} = shift;
+ $self->{format} = shift;
+ $self->{language} = shift;
+ $self->{output} = '';
+ bless $self, $class;
+ return $self;
}
sub valid_language {
- my $self = shift;
- # XXX Actually perform validity checks
- return 1;
+ my $self = shift;
+
+ # XXX Actually perform validity checks
+ return 1;
}
sub render {
- my $self = shift;
- my $vars = shift;
- my $template;
+ my $self = shift;
+ my $vars = shift;
+ my $template;
- if (not defined $self->{language}) {
- $template = Template->new({
- INCLUDE_PATH => $self->{'myconfig'}->{'templates'},
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- }) || throw Error::Simple Template->error();
- } elsif ($self->valid_language()) {
- $template = Template->new({
- INCLUDE_PATH => "$self->{'myconfig'}->{'templates'}/$self->{language};$self->{'myconfig'}->{'templates'}",
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- }) || throw Error::Simple Template->error();
- } else {
- throw Error::Simple 'Invalid language';
- }
+ if ( not defined $self->{language} ) {
+ $template = Template->new(
+ {
+ INCLUDE_PATH => $self->{'myconfig'}->{'templates'},
+ START_TAG => quotemeta('<?lsmb'),
+ END_TAG => quotemeta('?>'),
+ DELIMITER => ';',
+ }
+ ) || throw Error::Simple Template->error();
+ }
+ elsif ( $self->valid_language() ) {
+ $template = Template->new(
+ {
+ INCLUDE_PATH =>
+"$self->{'myconfig'}->{'templates'}/$self->{language};$self->{'myconfig'}->{'templates'}",
+ START_TAG => quotemeta('<?lsmb'),
+ END_TAG => quotemeta('?>'),
+ DELIMITER => ';',
+ }
+ ) || throw Error::Simple Template->error();
+ }
+ else {
+ throw Error::Simple 'Invalid language';
+ }
- eval "require LedgerSMB::Template::$self->{format}";
- if ($@) {
- throw Error::Simple $@;
- }
+ eval "require LedgerSMB::Template::$self->{format}";
+ if ($@) {
+ throw Error::Simple $@;
+ }
- my $cleanvars = &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars);
- if (not $template->process(
- &{"LedgerSMB::Template::$self->{format}::get_template"}($self->{template}),
- $cleanvars, \$self->{output}, binmode => ':utf8')) {
- throw Error::Simple $template->error();
- }
+ my $cleanvars =
+ &{"LedgerSMB::Template::$self->{format}::preprocess"}($vars);
+ if (
+ not $template->process(
+ &{"LedgerSMB::Template::$self->{format}::get_template"}(
+ $self->{template} ),
+ $cleanvars,
+ \$self->{output},
+ binmode => ':utf8'
+ )
+ )
+ {
+ throw Error::Simple $template->error();
+ }
- &{"LedgerSMB::Template::$self->{format}::postprocess"}($self);
+ &{"LedgerSMB::Template::$self->{format}::postprocess"}($self);
- return $self->{output};
+ return $self->{output};
}
1;