[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1788] trunk/LedgerSMB



Revision: 1788
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1788&view=rev
Author:   tetragon
Date:     2007-10-18 16:00:16 -0700 (Thu, 18 Oct 2007)

Log Message:
-----------
Some template handling tweaking to allow for escaping scalar references

Modified Paths:
--------------
    trunk/LedgerSMB/Template/CSV.pm
    trunk/LedgerSMB/Template/HTML.pm
    trunk/LedgerSMB/Template/LaTeX.pm
    trunk/LedgerSMB/Template/ODS.pm
    trunk/LedgerSMB/Template/TXT.pm
    trunk/LedgerSMB/Template/XLS.pm
    trunk/LedgerSMB/Template.pm

Modified: trunk/LedgerSMB/Template/CSV.pm
===================================================================
--- trunk/LedgerSMB/Template/CSV.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/CSV.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -38,6 +38,9 @@
 
 package LedgerSMB::Template::CSV;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use Template;
 use LedgerSMB::Template::TTI18N;
@@ -54,12 +57,17 @@
 
 	#XXX fix escaping function
 	return $rawvars if $type =~ /^LedgerSMB::Locale/;
+	return unless defined $rawvars;
 	if ( $type eq 'ARRAY' ) {
 		for (@{$rawvars}) {
 			push @{$vars}, preprocess( $_ );
 		}
-	} elsif ( !$type ) { # Scalar
-		$vars = $rawvars;
+	} elsif ( !$type or $type eq 'SCALAR' ) { # Scalar
+		if ($type eq 'SCALAR' ) {
+			$vars = $$rawvars;
+		} else {
+			$vars = $rawvars;
+		}
 		$vars =~ s/(^ +| +$)//g;
 		$vars =~ s/"/""/g;
 		$vars = qq|"$vars"| if $vars !~ /^\w*$/;

Modified: trunk/LedgerSMB/Template/HTML.pm
===================================================================
--- trunk/LedgerSMB/Template/HTML.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/HTML.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -39,6 +39,9 @@
 
 package LedgerSMB::Template::HTML;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use CGI::Simple::Standard qw(:html);
 use Template;
@@ -56,12 +59,15 @@
 
     #XXX fix escaping function
     return $rawvars if $type =~ /^LedgerSMB::Locale/;
+    return unless defined $rawvars;
     if ( $type eq 'ARRAY' ) {
         for (@{$rawvars}) {
             push @{$vars}, preprocess( $_ );
         }
     } elsif (!$type) {
         return escapeHTML($rawvars);
+    } elsif ($type eq 'SCALAR') {
+        return escapeHTML($$rawvars);
     } else { # Hashes and objects
         for ( keys %{$rawvars} ) {
             $vars->{preprocess($_)} = preprocess( $rawvars->{$_} );

Modified: trunk/LedgerSMB/Template/LaTeX.pm
===================================================================
--- trunk/LedgerSMB/Template/LaTeX.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/LaTeX.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -47,6 +47,9 @@
 
 package LedgerSMB::Template::LaTeX;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use Template::Latex;
 use LedgerSMB::Template::TTI18N;
@@ -62,15 +65,20 @@
 	my $type = ref $rawvars;
 
 	return $rawvars if $type =~ /^LedgerSMB::Locale/;
+	return unless defined $type;
 	if ($type eq 'ARRAY') {
 		for (@{$rawvars}) {
 			push @{$vars}, preprocess($_);
 		}
-	} elsif (!$type) {
+	} elsif (!$type or $type eq 'SCALAR') {
+		if ($type eq 'SCALAR') {
+			$vars = $$rawvars;
+		} else {
+			$vars = $rawvars;
+		}
 		#XXX Fix escaping
-		$rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
-		$rawvars =~ s/"(.*)"/``$1''/gs;
-		return $rawvars;
+		$vars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
+		$vars =~ s/"(.*)"/``$1''/gs;
 	} else {
 		for ( keys %{$rawvars} ) {
 			$vars->{$_} = preprocess($rawvars->{$_});

Modified: trunk/LedgerSMB/Template/ODS.pm
===================================================================
--- trunk/LedgerSMB/Template/ODS.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/ODS.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -800,12 +800,15 @@
 
     #XXX fix escaping function
     return $rawvars if $type =~ /^LedgerSMB::Locale/;
+    return unless defined $rawvars;
     if ( $type eq 'ARRAY' ) {
         for (@{$rawvars}) {
             push @{$vars}, preprocess( $_ );
         }
     } elsif (!$type) {
         return escapeHTML($rawvars);
+    } elsif ($type eq 'SCALAR') {
+        return escapeHTML($$rawvars);
     } else { # Hashes and objects
         for ( keys %{$rawvars} ) {
             $vars->{preprocess($_)} = preprocess( $rawvars->{$_} );

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/TXT.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -38,6 +38,9 @@
 
 package LedgerSMB::Template::TXT;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use Template;
 use LedgerSMB::Template::TTI18N;

Modified: trunk/LedgerSMB/Template/XLS.pm
===================================================================
--- trunk/LedgerSMB/Template/XLS.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template/XLS.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -48,6 +48,9 @@
 
 package LedgerSMB::Template::XLS;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use CGI::Simple::Standard qw(:html);
 use Excel::Template::Plus;
@@ -65,12 +68,15 @@
 
     #XXX fix escaping function
     return $rawvars if $type =~ /^LedgerSMB::Locale/;
+    return $rawvars unless defined $rawvars;
     if ( $type eq 'ARRAY' ) {
         for (@{$rawvars}) {
             push @{$vars}, preprocess( $_ );
         }
     } elsif (!$type) {
         return escapeHTML($rawvars);
+    } elsif ($type eq 'SCALAR') {
+        return escapeHTML($$rawvars);
     } else { # Hashes and objects
         for ( keys %{$rawvars} ) {
             $vars->{preprocess($_)} = preprocess( $rawvars->{$_} );
@@ -110,7 +116,7 @@
 	);
 	$template->write_file("$parent->{outputfile}.xls");
 
-	parent->{mimetype} = 'application/vnd.ms-excel';
+	$parent->{mimetype} = 'application/vnd.ms-excel';
 }
 
 sub postprocess {

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2007-10-18 20:16:13 UTC (rev 1787)
+++ trunk/LedgerSMB/Template.pm	2007-10-18 23:00:16 UTC (rev 1788)
@@ -120,6 +120,9 @@
 
 package LedgerSMB::Template;
 
+use warnings;
+use strict;
+
 use Error qw(:try);
 use LedgerSMB::Sysconfig;
 use LedgerSMB::Mailer;
@@ -164,9 +167,9 @@
 		throw Error::Simple "Invalid format";
 	}
 	if (!$self->{include_path}){
-## SC: hardcoding due to config migration
-##		$self->{include_path} = $self->{'myconfig'}->{'templates'};
-		$self->{include_path} = 'templates/demo';
+## SC: XXX hardcoding due to config migration, will need adjustment
+		$self->{include_path} = $self->{'myconfig'}->{'templates'};
+		$self->{include_path} ||= 'templates/demo';
 		if (defined $self->{language}){
 			if (!$self->_valid_language){
 				throw Error::Simple 'Invalid language';


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.