source: trunk/lib/Epoll/View/Latex.pm @ 242

Last change on this file since 242 was 242, checked in by nanardon, 15 years ago
  • rename Vote module to Epoll (#16)
  • Property svn:keywords set to Id Rev
File size: 1.6 KB
Line 
1package Epoll::View::Latex;
2
3use strict;
4use base 'Epoll::View::TT';
5use LaTeX::Driver;
6use File::Temp;
7
8__PACKAGE__->config(
9    TEMPLATE_EXTENSION => '.tt',
10    INCLUDE_PATH => Epoll->path_to( 'root', 'latex' ),
11    PRE_PROCESS => 'includes/header.tt',
12    POST_PROCESS => 'includes/footer.tt',
13    PLUGIN_BASE => 'Epoll::Template::Plugin',
14);
15
16=head1 NAME
17
18Epoll::View::Latex - Latex View for Epoll
19
20=head1 DESCRIPTION
21
22TT View for Epoll.
23
24=cut
25
26sub process {
27    my ($self, $c) = @_;
28
29    $c->stash->{format} ||= 'pdf';
30    my $output = $self->render(
31        $c, $c->stash->{template}
32    );
33   
34    if ($c->stash->{format} eq 'tex') {
35        $c->res->body($output);
36        return;
37    }
38
39    my ($fh, $filename) = File::Temp::tempfile(
40        SUFFIX => ('.' . $c->stash->{format}),
41    );
42    close($fh);
43
44    LaTeX::Driver::hack->new(
45        source  => \$output,
46        output  => $filename,
47        format  => $c->stash->{format},
48    )->run;
49    open($fh, '<', $filename);
50    unlink($filename);
51    binmode($fh);
52    $c->res->body(join('', <$fh>));
53    close($fh);
54}
55
56# This is just a hack
57# Don't ask me why, but system() return -1 instead 0
58# under catalyst...
59# This is just an ugly workaround
60
61package LaTeX::Driver::hack;
62use base qw(LaTeX::Driver);
63
64sub run_command {
65    my ($self, @args) = @_;
66    for (0 .. 2) {
67        my $res = $self->SUPER::run_command(@args);
68        if ($res > 0) { return $res }
69    }
70    0; # is ok
71} 
72
73=head1 SEE ALSO
74
75L<Epoll>
76
77=head1 AUTHOR
78
79Thauvin Olivier
80
81=head1 LICENSE
82
83This library is free software, you can redistribute it and/or modify
84it under the same terms as Perl itself or CeCILL.
85
86=cut
87
881;
Note: See TracBrowser for help on using the repository browser.