[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb: [1684] trunk
- Subject: SF.net SVN: ledger-smb: [1684] trunk
- From: ..hidden..
- Date: Mon, 01 Oct 2007 19:54:28 -0700
Revision: 1684
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1684&view=rev
Author: tetragon
Date: 2007-10-01 19:54:28 -0700 (Mon, 01 Oct 2007)
Log Message:
-----------
Adding format_options and output_options template constructor arguments
Merging PDF and Postscript generation to the same file
Adding DVI support
Modified Paths:
--------------
trunk/LedgerSMB/Template/ODS.pm
trunk/LedgerSMB/Template.pm
trunk/t/01-load.t
trunk/t/04-template-handling.t
Added Paths:
-----------
trunk/LedgerSMB/Template/LaTeX.pm
Removed Paths:
-------------
trunk/LedgerSMB/Template/PDF.pm
trunk/LedgerSMB/Template/PS.pm
Copied: trunk/LedgerSMB/Template/LaTeX.pm (from rev 1675, trunk/LedgerSMB/Template/PDF.pm)
===================================================================
--- trunk/LedgerSMB/Template/LaTeX.pm (rev 0)
+++ trunk/LedgerSMB/Template/LaTeX.pm 2007-10-02 02:54:28 UTC (rev 1684)
@@ -0,0 +1,134 @@
+
+=head1 NAME
+
+LedgerSMB::Template::LaTeX Template support module for LedgerSMB
+
+=head1 SYNOPSIS
+
+Muxed LaTeX rendering support. Handles PDF, Postscript, and DVI output.
+
+=head1 DETAILS
+
+The final output format is determined by the format_option of filetype. The
+valid filetype specifiers are 'pdf', 'ps', and 'dvi'.
+
+=head1 METHODS
+
+=over
+
+=item get_template ($name)
+
+Returns the appropriate template filename for this format.
+
+=item preprocess ($vars)
+
+Currently does nothing.
+
+=item process ($parent, $cleanvars)
+
+Processes the template for the appropriate output format.
+
+=item postprocess ($parent)
+
+Currently does nothing.
+
+=back
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+
+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 details. For a full list
+including contact information of contributors, maintainers, and copyright
+holders, see the CONTRIBUTORS file.
+=cut
+
+package LedgerSMB::Template::LaTeX;
+
+use Error qw(:try);
+use Template::Latex;
+use LedgerSMB::Template::TTI18N;
+
+sub get_template {
+ my $name = shift;
+ return "${name}.tex";
+}
+
+sub preprocess {
+ my $rawvars = shift;
+ my $vars;
+ my $type = ref $rawvars;
+
+ return $rawvars if $type =~ /^LedgerSMB::Locale/;
+ if ($type eq 'ARRAY') {
+ for (@{$rawvars}) {
+ push @{$vars}, preprocess($_);
+ }
+ } elsif (!$type) {
+ #XXX Fix escaping
+ $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
+ $rawvars =~ s/"(.*)"/``$1''/gs;
+ return $rawvars;
+ } else {
+ for ( keys %{$rawvars} ) {
+ $vars->{$_} = preprocess($rawvars->{$_});
+ }
+ }
+ return $vars;
+}
+
+sub process {
+ 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::Latex::DEBUG = 1 if $parent->{debug};
+ my $format = 'ps';
+ if ($parent->{format_args}{filetype} eq 'dvi') {
+ $format = 'dvi';
+ } elsif ($parent->{format_args}{filetype} eq 'pdf') {
+ $format = 'pdf';
+ }
+ $template = Template::Latex->new({
+ LATEX_FORMAT => $format,
+ INCLUDE_PATH => $parent->{include_path},
+ START_TAG => quotemeta('<?lsmb'),
+ END_TAG => quotemeta('?>'),
+ DELIMITER => ';',
+ DEBUG => ($parent->{debug})? 'dirs': undef,
+ DEBUG_FORMAT => '',
+ }) || throw Error::Simple Template::Latex->error();
+
+ if (not $template->process(
+ $source,
+ {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+ 'escape' => \&preprocess},
+ "$parent->{outputfile}.$format", binmode => 1)) {
+ throw Error::Simple $template->error();
+ }
+ if ($format eq 'dvi') {
+ $parent->{mimetype} = 'application/x-dvi';
+ } else {
+ $parent->{mimetype} = 'application/$format';
+ }
+ $parent->{rendered} = "$parent->{outputfile}.$format";
+}
+
+sub postprocess {
+ my $parent = shift;
+ return $parent->{rendered};
+}
+
+1;
Modified: trunk/LedgerSMB/Template/ODS.pm
===================================================================
--- trunk/LedgerSMB/Template/ODS.pm 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/LedgerSMB/Template/ODS.pm 2007-10-02 02:54:28 UTC (rev 1684)
@@ -119,6 +119,26 @@
$currcol++;
}
+sub _formula_handler {
+ my $cell = $ods->getCell(-1, $rowcount, $currcol);
+
+ if (@style_stack and $celltype{$style_stack[0][0]}) {
+ $ods->cellValueType($cell, $celltype{$style_stack[0][0]}[0]);
+ } elsif ($_->{att}->{type}) {
+ my $type = $_->{att}->{type};
+ if ($type =~ /^(string|blank|url)$/i) {
+ $ods->cellValueType($cell, 'string');
+ } elsif ($type =~ /^(number|formula)$/i) {
+ $ods->cellValueType($cell, 'float');
+ }
+ }
+ $ods->cellFormula($cell, "oooc:=$_->{att}->{text}");
+ if (@style_stack) {
+ $ods->cellStyle($cell, $style_stack[0][0]);
+ }
+ $currcol++;
+}
+
sub _border_set {
my ($format, $properties, $border) = @_;
my $edge = $border;
@@ -759,7 +779,7 @@
worksheet => \&_worksheet_handler,
row => \&_row_handler,
cell => \&_cell_handler,
- formula => \&_cell_handler,
+ formula => \&_formula_handler,
format => \&_format_handler,
},
twig_handlers => {
Deleted: trunk/LedgerSMB/Template/PDF.pm
===================================================================
--- trunk/LedgerSMB/Template/PDF.pm 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/LedgerSMB/Template/PDF.pm 2007-10-02 02:54:28 UTC (rev 1684)
@@ -1,114 +0,0 @@
-
-=head1 NAME
-
-LedgerSMB::Template::PDF Template support module for LedgerSMB
-
-=head1 METHODS
-
-=over
-
-=item get_template ($name)
-
-Returns the appropriate template filename for this format.
-
-=item preprocess ($vars)
-
-Currently does nothing.
-
-=item process ($parent, $cleanvars)
-
-Processes the template for PDF.
-
-=item postprocess ($parent)
-
-Currently does nothing.
-
-=back
-
-=head1 Copyright (C) 2007, The LedgerSMB core team.
-
-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 details. For a full list
-including contact information of contributors, maintainers, and copyright
-holders, see the CONTRIBUTORS file.
-=cut
-
-package LedgerSMB::Template::PDF;
-
-use Error qw(:try);
-use Template::Latex;
-use LedgerSMB::Template::TTI18N;
-
-sub get_template {
- my $name = shift;
- return "${name}.tex";
-}
-
-sub preprocess {
- my $rawvars = shift;
- my $vars;
- my $type = ref $rawvars;
-
- return $rawvars if $type =~ /^LedgerSMB::Locale/;
- if ($type eq 'ARRAY') {
- for (@{$rawvars}) {
- push @{$vars}, preprocess($_);
- }
- } elsif (!$type) {
- #XXX Fix escaping
- $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
- $rawvars =~ s/"(.*)"/``$1''/gs;
- return $rawvars;
- } else {
- for ( keys %{$rawvars} ) {
- $vars->{$_} = preprocess($rawvars->{$_});
- }
- }
- return $vars;
-}
-
-sub process {
- 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},
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- DEBUG => ($parent->{debug})? 'dirs': undef,
- DEBUG_FORMAT => '',
- }) || throw Error::Simple Template::Latex->error();
-
- if (not $template->process(
- $source,
- {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
- 'escape' => \&preprocess},
- "$parent->{outputfile}.pdf", binmode => 1)) {
- throw Error::Simple $template->error();
- }
- $parent->{mimetype} = 'application/pdf';
-}
-
-sub postprocess {
- my $parent = shift;
- $parent->{rendered} = "$parent->{outputfile}.pdf";
- return "$parent->{outputfile}.pdf";
-}
-
-1;
Deleted: trunk/LedgerSMB/Template/PS.pm
===================================================================
--- trunk/LedgerSMB/Template/PS.pm 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/LedgerSMB/Template/PS.pm 2007-10-02 02:54:28 UTC (rev 1684)
@@ -1,114 +0,0 @@
-
-=head1 NAME
-
-LedgerSMB::Template::PS Template support module for LedgerSMB
-
-=head1 METHODS
-
-=over
-
-=item get_template ($name)
-
-Returns the appropriate template filename for this format.
-
-=item preprocess ($vars)
-
-Currently does nothing.
-
-=item process ($parent, $cleanvars)
-
-Processes the template for Postscript.
-
-=item postprocess ($parent)
-
-Currently does nothing.
-
-=back
-
-=head1 Copyright (C) 2007, The LedgerSMB core team.
-
-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 details. For a full list
-including contact information of contributors, maintainers, and copyright
-holders, see the CONTRIBUTORS file.
-=cut
-
-package LedgerSMB::Template::PS;
-
-use Error qw(:try);
-use Template::Latex;
-use LedgerSMB::Template::TTI18N;
-
-sub get_template {
- my $name = shift;
- return "${name}.tex";
-}
-
-sub preprocess {
- my $rawvars = shift;
- my $vars;
- my $type = ref $rawvars;
-
- return $rawvars if $type =~ /^LedgerSMB::Locale/;
- if ($type eq 'ARRAY') {
- for (@{$rawvars}) {
- push @{$vars}, preprocess($_);
- }
- } elsif (!$type) {
- #XXX Fix escaping
- $rawvars =~ s/([&\$\\_<>~^#\%\{\}])/\\$1/g;
- $rawvars =~ s/"(.*)"/``$1''/gs;
- return $rawvars;
- } else {
- for ( keys %{$rawvars} ) {
- $vars->{$_} = preprocess($rawvars->{$_});
- }
- }
- return $vars;
-}
-
-sub process {
- 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},
- START_TAG => quotemeta('<?lsmb'),
- END_TAG => quotemeta('?>'),
- DELIMITER => ';',
- DEBUG => ($parent->{debug})? 'dirs': undef,
- DEBUG_FORMAT => '',
- }) || throw Error::Simple Template::Latex->error();
-
- if (not $template->process(
- $source,
- {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
- 'escape' => \&preprocess},
- "$parent->{outputfile}.ps", binmode => 1)) {
- throw Error::Simple $template->error();
- }
- $parent->{mimetype} = 'application/postscript';
-}
-
-sub postprocess {
- my $parent = shift;
- $parent->{rendered} = "$parent->{outputfile}.ps";
- return "$parent->{outputfile}.ps";
-}
-
-1;
Modified: trunk/LedgerSMB/Template.pm
===================================================================
--- trunk/LedgerSMB/Template.pm 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/LedgerSMB/Template.pm 2007-10-02 02:54:28 UTC (rev 1684)
@@ -26,6 +26,16 @@
The format to be used. Currently HTML, PS, PDF, TXT and CSV are supported.
+=item format_options (optional)
+
+A hash of format-specific options. See the appropriate LSMB::T::foo for
+details.
+
+=item output_options (optional)
+
+A hash of output-specific options. See the appropriate output method for
+details.
+
=item locale (optional)
The locale object to use for regular gettext lookups. Having this option adds
@@ -122,7 +132,6 @@
$self->{myconfig} = $args{user};
$self->{template} = $args{template};
$self->{format} = $args{format};
- $self->{format} = 'PS' if lc $self->{format} eq 'postscript';
$self->{language} = $args{language};
$self->{no_escape} = $args{no_escape};
$self->{debug} = $args{debug};
@@ -134,7 +143,21 @@
$self->{noauto} = $args{no_auto_output};
$self->{method} = $args{method};
$self->{method} ||= $args{media};
+ $self->{format_args} = $args{format_options};
+ $self->{output_args} = $args{output_options};
+ # SC: Muxing pre-format_args LaTeX format specifications. Now with
+ # DVI support.
+ if (lc $self->{format} eq 'dvi') {
+ $self->{format} = 'LaTeX';
+ $self->{format_args}{filetype} = 'dvi';
+ } elsif (lc $self->{format} eq 'pdf') {
+ $self->{format} = 'LaTeX';
+ $self->{format_args}{filetype} = 'pdf';
+ } elsif (lc $self->{format} eq 'ps' or lc $self->{format} eq 'postscript') {
+ $self->{format} = 'LaTeX';
+ $self->{format_args}{filetype} = 'ps';
+ }
bless $self, $class;
if ($self->{format} !~ /^\p{IsAlnum}+$/) {
Modified: trunk/t/01-load.t
===================================================================
--- trunk/t/01-load.t 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/t/01-load.t 2007-10-02 02:54:28 UTC (rev 1684)
@@ -32,10 +32,10 @@
use_ok('LedgerSMB::Sysconfig');
use_ok('LedgerSMB::Tax');
use_ok('LedgerSMB::Template');
+use_ok('LedgerSMB::Template::Elements');
use_ok('LedgerSMB::Template::CSV');
use_ok('LedgerSMB::Template::HTML');
-use_ok('LedgerSMB::Template::PDF');
-use_ok('LedgerSMB::Template::PS');
+use_ok('LedgerSMB::Template::LaTeX');
use_ok('LedgerSMB::Template::TXT');
use_ok('LedgerSMB::User');
Modified: trunk/t/04-template-handling.t
===================================================================
--- trunk/t/04-template-handling.t 2007-10-01 22:10:17 UTC (rev 1683)
+++ trunk/t/04-template-handling.t 2007-10-02 02:54:28 UTC (rev 1684)
@@ -17,9 +17,10 @@
use LedgerSMB::Sysconfig;
use LedgerSMB::Locale;
use LedgerSMB::Template;
+use LedgerSMB::Template::Elements;
+use LedgerSMB::Template::CSV;
use LedgerSMB::Template::HTML;
-use LedgerSMB::Template::PDF;
-use LedgerSMB::Template::PS;
+use LedgerSMB::Template::LaTeX;
use LedgerSMB::Template::TXT;
$LedgerSMB::Sysconfig::tempdir = 't/var';
@@ -153,19 +154,19 @@
# Template->new
$myconfig = {'templates' => 't/data'};
-throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => 'x/0')}
+throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => 'x/0', 'format' => 'HTML')}
qr/Invalid language/, 'Template, new: Invalid language caught 1';
-throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '1\\2')}
+throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '1\\2', 'format' => 'HTML')}
qr/Invalid language/, 'Template, new: Invalid language caught 2';
-throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '1:2')}
+throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '1:2', 'format' => 'HTML')}
qr/Invalid language/, 'Template, new: Invalid language caught 3';
-throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '..')}
+throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '..', 'format' => 'HTML')}
qr/Invalid language/, 'Template, new: Invalid language caught 4';
-throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '.svn')}
+throws_ok{new LedgerSMB::Template('user' => $myconfig, 'language' => '.svn', 'format' => 'HTML')}
qr/Invalid language/,
'Template, new: Invalid language caught 5';
$template = undef;
-$template = new LedgerSMB::Template('user' => $myconfig, 'language' => 'de');
+$template = new LedgerSMB::Template('user' => $myconfig, 'language' => 'de', 'format' => 'HTML');
ok(defined $template, 'Template, new: Object creation with valid language');
isa_ok($template, 'LedgerSMB::Template',
'Template, new: Object creation with valid language');
@@ -173,7 +174,7 @@
'Template, new: Object creation with valid language has good include_path');
$template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'language' => 'de',
- 'path' => 't/data', 'output_file' => 'test');
+ 'path' => 't/data', 'output_file' => 'test', 'format' => 'HTML');
ok(defined $template,
'Template, new: Object creation with valid language and path');
isa_ok($template, 'LedgerSMB::Template',
@@ -279,6 +280,21 @@
$template = undef;
$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'HTML',
+ 'template' => \'Look at me <?lsmb login ?>.', 'no_auto_output' => 1);
+ok(defined $template,
+ 'Template, new (HTML): Object creation with string template');
+isa_ok($template, 'LedgerSMB::Template',
+ 'Template, new (HTML): Object creation with string template');
+is($template->{include_path}, 't/data',
+ 'Template, new (HTML): Object creation with string template');
+is($template->render({'login' => 'foo&bar'}),
+ undef,
+ 'Template, render (HTML): Simple HTML string template, no file');
+is($template->{output}, "Look at me foo&bar.",
+ 'Template, render (HTML): Simple HTML string template, correct output');
+
+$template = undef;
+$template = new LedgerSMB::Template('user' => $myconfig, 'format' => 'HTML',
'template' => '04-gettext', 'output_file' => '04-gettext',
'no_auto_output' => 1);
ok(defined $template,
@@ -327,3 +343,12 @@
ok(!-e "t/var/04-gettext-output-$$.pdf",
'Template, render (PDF): testfile removed');
}
+
+###################################
+## LedgerSMB::Template::Elements ##
+###################################
+
+$template = undef;
+$form = undef;
+
+$form = new Form;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.