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

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



Revision: 1618
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1618&view=rev
Author:   tetragon
Date:     2007-09-16 08:56:12 -0700 (Sun, 16 Sep 2007)

Log Message:
-----------
Add support for templates in string form

Modified Paths:
--------------
    trunk/LedgerSMB/Template/CSV.pm
    trunk/LedgerSMB/Template/HTML.pm
    trunk/LedgerSMB/Template/PDF.pm
    trunk/LedgerSMB/Template/PS.pm
    trunk/LedgerSMB/Template/TXT.pm
    trunk/LedgerSMB/Template.pm

Modified: trunk/LedgerSMB/Template/CSV.pm
===================================================================
--- trunk/LedgerSMB/Template/CSV.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template/CSV.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -75,6 +75,7 @@
 	my $parent = shift;
 	my $cleanvars = shift;
 	my $template;
+	my $source;
 	my $output;
 
 	if ($parent->{outputfile}) {
@@ -82,6 +83,13 @@
 	} else {
 		$output = \$parent->{output};
 	}
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template});
+	}
 	$template = Template->new({
 		INCLUDE_PATH => $parent->{include_path},
 		START_TAG => quotemeta('<?lsmb'),
@@ -92,7 +100,7 @@
 		}) || throw Error::Simple Template->error(); 
 
 	if (not $template->process(
-		get_template($parent->{template}), 
+		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
 		$output, binmode => ':utf8')) {

Modified: trunk/LedgerSMB/Template/HTML.pm
===================================================================
--- trunk/LedgerSMB/Template/HTML.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template/HTML.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -76,12 +76,20 @@
 	my $cleanvars = shift;
 	my $template;
 	my $output;
+	my $source;
 	
 	if ($parent->{outputfile}) {
 		$output = "$parent->{outputfile}.html";
 	} else {
 		$output = \$parent->{output};
 	}
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template});
+	}
 	$template = Template->new({
 		INCLUDE_PATH => $parent->{include_path},
 		START_TAG => quotemeta('<?lsmb'),
@@ -92,7 +100,7 @@
 		DEBUG_FORMAT => '',
 		}) || throw Error::Simple Template->error(); 
 	if (not $template->process(
-		get_template($parent->{template}), 
+		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
 		$output, binmode => ':utf8')) {

Modified: trunk/LedgerSMB/Template/PDF.pm
===================================================================
--- trunk/LedgerSMB/Template/PDF.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template/PDF.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -74,9 +74,17 @@
 	my $parent = shift;
 	my $cleanvars = shift;
 	my $template;
+	my $source;
 	$parent->{outputfile} ||=
 		"${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$";
 
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template});
+	}
 	$template = Template::Latex->new({
 		LATEX_FORMAT => 'pdf',
 		INCLUDE_PATH => $parent->{include_path},
@@ -88,7 +96,7 @@
 		}) || throw Error::Simple Template::Latex->error(); 
 
 	if (not $template->process(
-		get_template($parent->{template}), 
+		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
 		"$parent->{outputfile}.pdf", binmode => 1)) {

Modified: trunk/LedgerSMB/Template/PS.pm
===================================================================
--- trunk/LedgerSMB/Template/PS.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template/PS.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -74,9 +74,17 @@
 	my $parent = shift;
 	my $cleanvars = shift;
 	my $template;
+	my $source;
 	$parent->{outputfile} ||=
 		"${LedgerSMB::Sysconfig::tempdir}/$parent->{template}-output-$$";
 
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template});
+	}
 	$template = Template::Latex->new({
 		LATEX_FORMAT => 'ps',
 		INCLUDE_PATH => $parent->{include_path},
@@ -88,7 +96,7 @@
 		}) || throw Error::Simple Template::Latex->error(); 
 
 	if (not $template->process(
-		get_template($parent->{template}), 
+		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
 		"$parent->{outputfile}.ps", binmode => 1)) {

Modified: trunk/LedgerSMB/Template/TXT.pm
===================================================================
--- trunk/LedgerSMB/Template/TXT.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template/TXT.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -56,6 +56,7 @@
 	my $parent = shift;
 	my $cleanvars = shift;
 	my $template;
+	my $source;
 	my $output;
 
 	if ($parent->{outputfile}) {
@@ -63,6 +64,13 @@
 	} else {
 		$output = \$parent->{output};
 	}
+	if (ref $parent->{template} eq 'SCALAR') {
+		$source = $parent->{template};
+	} elsif (ref $parent->{template} eq 'ARRAY') {
+		$source = join "\n", @{$parent->{template}};
+	} else {
+		$source = get_template($parent->{template});
+	}
 	$template = Template->new({
 		INCLUDE_PATH => $parent->{include_path},
 		START_TAG => quotemeta('<?lsmb'),
@@ -73,7 +81,7 @@
 		}) || throw Error::Simple Template->error(); 
 
 	if (not $template->process(
-		get_template($parent->{template}), 
+		$source, 
 		{%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
 			'escape' => \&preprocess},
 		$output, binmode => ':utf8')) {

Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm	2007-09-16 04:49:45 UTC (rev 1617)
+++ trunk/LedgerSMB/Template.pm	2007-09-16 15:56:12 UTC (rev 1618)
@@ -19,7 +19,8 @@
 
 =item template
 
-The name of the template file to be processed.
+The template to be processed.  This can either be a reference to the template
+in string form or the name of the file that is the template to be processed.
 
 =item format
 


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