[Catalyst-commits] r11259 - in trunk/misc: .
Catalyst-View-PDF-API2-0.01 Catalyst-View-PDF-API2-0.01/lib
Catalyst-View-PDF-API2-0.01/lib/Catalyst
Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper
Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View
Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF
Catalyst-View-PDF-API2-0.01/lib/Catalyst/View
Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF
Catalyst-View-PDF-API2-0.01/lib/Template
Catalyst-View-PDF-API2-0.01/lib/Template/Plugin
Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst
Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View
Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF
ferz at dev.catalyst.perl.org
ferz at dev.catalyst.perl.org
Thu Aug 27 22:17:30 GMT 2009
Author: ferz
Date: 2009-08-27 22:17:29 +0000 (Thu, 27 Aug 2009)
New Revision: 11259
Added:
trunk/misc/Catalyst-View-PDF-API2-0.01/
trunk/misc/Catalyst-View-PDF-API2-0.01/Changes
trunk/misc/Catalyst-View-PDF-API2-0.01/MANIFEST
trunk/misc/Catalyst-View-PDF-API2-0.01/META.yml
trunk/misc/Catalyst-View-PDF-API2-0.01/Makefile.PL
trunk/misc/Catalyst-View-PDF-API2-0.01/README
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF/API2.pm
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF/API2.pm
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF/
trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF/API2.pm
trunk/misc/Catalyst-View-PDF-API2-0.01/t/
Log:
I've tried to create my first View using PDF::Reuse as basic and try to use PDF::API2 instead.
Actually it doesn't work;
I've put it here to look for help.
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/Changes
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/Changes (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/Changes 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,5 @@
+Revision history for Catalyst-View-PDF-API2
+
+0.01 2009-08-27
+ First version, to be release.
+
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/MANIFEST
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/MANIFEST (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/MANIFEST 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,11 @@
+Changes
+MANIFEST
+Makefile.PL
+README
+lib/Catalyst/View/PDF/API2.pm
+lib/Catalyst/Helper/View/PDF/API2.pm
+#lib/Template/Plugin/Catalyst/View/PDF/API2.pm
+t/00-load.t
+t/pod-coverage.t
+t/pod.t
+META.yml Module meta-data (added by MakeMaker)
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/META.yml
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/META.yml (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/META.yml 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,19 @@
+--- #YAML:1.0
+name: Catalyst-View-PDF-API2
+version: 0.01
+abstract: Create PDF files from Catalyst using Template Toolkit templates
+license: ~
+author:
+ - Ferruccio Zamuner <nonsolosoft at diff.org>
+generated_by: ExtUtils::MakeMaker version 6.44
+distribution_type: module
+requires:
+ Catalyst::View::TT: 0
+ File::chdir: 0
+ parent: 0
+ PDF::API2: 0
+ Template::Plugin::Procedural: 0
+ Test::More: 0
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.3.html
+ version: 1.3
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/Makefile.PL
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/Makefile.PL (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/Makefile.PL 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,21 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+ NAME => 'Catalyst::View::PDF::API2',
+ AUTHOR => 'Ferruccio Zamuner <nonsolosoft at diff.org>',
+ VERSION_FROM => 'lib/Catalyst/View/PDF/API2.pm',
+ ABSTRACT_FROM => 'lib/Catalyst/View/PDF/API2.pm',
+ PL_FILES => {},
+ PREREQ_PM => {
+ 'Test::More' => 0,
+ 'Catalyst::View::TT' => 0,
+ 'PDF::API2' => 0,
+ 'File::chdir' => 0,
+ 'Template::Plugin::Procedural' => 0,
+ 'parent' => 0,
+ },
+ dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ clean => { FILES => 'Catalyst-View-PDF-API2-*' },
+);
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/README
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/README (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/README 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,36 @@
+NAME
+ Catalyst::View::PDF::API2 - Create PDF files from Catalyst using
+ Template Toolkit templates
+
+VERSION
+ Version 0.01
+
+SYNOPSIS
+
+ Cloned by Catalyst::View::PDF::Reuse
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+SUPPORT AND DOCUMENTATION
+
+SEE ALSO
+
+Catalyst::View::PDF::Reuse
+
+NonSoLoSoft - http://www.nonsolosoft.com/
+
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2009 NonSoLoSoft
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF/API2.pm
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF/API2.pm (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/Helper/View/PDF/API2.pm 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,88 @@
+package Catalyst::Helper::View::PDF::API2;
+
+use strict;
+
+=head1 NAME
+
+Catalyst::Helper::View::PDF::API2 - Helper for PDF::API2 Views
+
+=head1 SYNOPSIS
+
+To create a PDF::API2 view in your Catalyst application, enter the following command:
+
+ script/myapp_create.pl view PDF::API2 PDF::API2
+
+Then in MyApp.pm, add a configuration item for the View::PDF::API2 include path:
+
+ __PACKAGE__->config('View::PDF::API2' => {
+ INCLUDE_PATH => __PACKAGE__->path_to('root','templates')
+ });
+
+=head1 DESCRIPTION
+
+Helper for PDF::API2 Views.
+
+=head2 METHODS
+
+=head3 mk_compclass
+
+=cut
+
+sub mk_compclass {
+ my ( $self, $helper ) = @_;
+ my $file = $helper->{file};
+ $helper->render_file( 'compclass', $file );
+}
+
+=head1 AUTHOR
+
+Jon Allen, L<jj at jonallen.info>
+
+=head1 SEE ALSO
+
+L<Catalyst::View::PDF::API2>
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 NonSoLoSoft, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
+
+__DATA__
+
+__compclass__
+package [% class %];
+
+use strict;
+use base 'Catalyst::View::PDF::API2';
+
+=head1 NAME
+
+[% class %] - PDF::API2 View for [% app %]
+
+=head1 DESCRIPTION
+
+PDF::API2 View for [% app %].
+
+=head1 AUTHOR
+
+[% author %]
+
+=head1 SEE ALSO
+
+L<[% app %]>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+
+1;
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF/API2.pm
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF/API2.pm (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Catalyst/View/PDF/API2.pm 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,242 @@
+package Catalyst::View::PDF::API2;
+
+use warnings;
+use strict;
+use parent 'Catalyst::View::TT';
+use File::chdir;
+use File::Spec::Functions qw/catfile/;
+use File::Temp qw/tmpnam/;
+use PDF::API2;
+
+=head1 NAME
+
+Catalyst::View::PDF::API2 - Create PDF files from Catalyst using Template Toolkit templates
+
+=head1 VERSION
+
+Version 0.02
+
+=cut
+
+our $VERSION = '0.03';
+
+=head1 SYNOPSIS
+
+Create a PDF::API2 view:
+
+ script/myapp_create.pl view PDF::API2 PDF::API2
+
+In MyApp.pm, add a configuration item for the template include path:
+
+ __PACKAGE__->config('View::PDF::API2' => {
+ INCLUDE_PATH => __PACKAGE__->path_to('root','templates')
+ });
+
+In your controller:
+
+ $c->stash->{pdf_template} = 'hello_pdf.tt';
+ $c->forward('View::PDF::API2');
+
+In F<root/templates/hello_pdf.tt>:
+
+ [% pdf.prFont('Helvetica-Bold') %]
+ [% pdf.prFontSize(20) %]
+ [% pdf.prText(100,100,'Hello, World!') %]
+
+
+=head1 DESCRIPTION
+
+Catalyst::View::PDF::API2 provides the facility to generate PDF files from
+a Catalyst application by embedding L<PDF::API2> commands within a Template
+Toolkit template.
+
+=head2 Template Syntax
+
+Within your template you will have access to a C<pdf> object which has
+methods corresponding to all of L<PDF::API2>'s functions.
+
+For example, to print the text I<Hello, World> at PDF coordinates 100,100,
+use the following directive in your template:
+
+ [% pdf.prText(100,100,'Hello, World') %]
+
+Data held in the stash can be printed as follows:
+
+ $c->stash->{list} = ['one', 'two', 'three', 'four'];
+
+ [% y = 500 %]
+ [% FOREACH item IN list %]
+ [% pdf.prText(100,y,item) %]
+ [% y = y - 13 %]
+ [% END %]
+
+Formatting can be defined using the Template Toolkit format plugin:
+
+ [% USE format %]
+ [% currency = format('£%.2f') %]
+ [% pdf.prText(100,100,currency(10)) %]
+
+=head2 Using existing PDF documents
+
+The key benefit of L<PDF::API2> is the ability to load an existing PDF
+file and use this as the basis for a new document.
+
+For example, to produce receipts or shipping labels you could create a
+blank receipt in Microsoft Word, convert this to PDF, then use PDF::API2
+to add in details such as the order number and customer address.
+
+ [% pdf.prForm('customer_receipt.pdf') %]
+ [% pdf.prText(123,643,order.number) %]
+ [% pdf.prText(299,643,order.date) %]
+
+Note that the PDF document loaded by C<pdf.prForm> must be in the same
+directory as your Template Toolkit template.
+
+=head1 FUNCTIONS
+
+=head2 process
+
+Render the PDF file, places the contents in C<< $c->response->body >> and
+sets appropriate HTTP headers.
+
+You should normally not need to use this method directly, instead forward
+to the PDF::API2 view from your controller:
+
+ $c->forward('View::PDF::API2');
+
+The filename and content disposition (inline or attachment) can be controlled
+by putting the following values in the stash:
+
+ $c->stash->{pdf_disposition} = 'attachment'; # Default is 'inline'
+ $c->stash->{pdf_filename} = 'myfile.pdf';
+
+If the PDF filename is not specified, it will be set to the last component
+of the URL path, appended with '.pdf'. For example, with a URL of
+L<http://localhost/view/order/pdf/1234> the PDF filename would be set to
+F<1234.pdf>.
+
+=cut
+
+sub process {
+ my ($self, $c) = @_;
+
+ my $pdf_filename = $c->stash->{pdf_filename} || (split '/',$c->req->path)[-1] || 'index.pdf';
+ $pdf_filename .= '.pdf' unless ($pdf_filename =~ /\.pdf$/i);
+
+ my $pdf_disposition = $c->stash->{pdf_disposition} || 'inline';
+
+ $c->response->content_type('application/pdf');
+ $c->response->headers->header("Content-Disposition" => qq{$pdf_disposition; filename="$pdf_filename"});
+
+ $c->response->body($self->render_pdf($c));
+}
+
+
+=head2 render_pdf
+
+Renders the PDF file and returns the raw PDF data.
+
+If you need to capture the PDF data, e.g. to store in a database or for
+emailing, call C<render_pdf> as follows:
+
+ my $pdf = $c->view("PDF::API2")->render_pdf($c);
+
+=cut
+
+sub render_pdf {
+ my ($self, $c) = @_;
+
+ my $template = <<'EOT';
+ [% USE pdf = Catalyst::View::PDF::API2 %]
+ [% PROCESS $pdf_template %]
+EOT
+
+ my $tempfile = tmpnam();
+ #
+ # $pdf = PDF::API2->new;
+ # $pdf = PDF::API2->open('some.pdf');
+
+ # prInitVars();
+ # prFile($tempfile);
+
+ SEARCH: foreach my $path (@{$self->config->{INCLUDE_PATH}}) {
+ if (-e catfile($path,$c->stash->{pdf_template})) {
+ local $CWD = $path;
+ my $output = $self->render($c,\$template);
+ last SEARCH;
+ }
+ }
+
+ prEnd();
+
+ my $pdf;
+ local $/ = undef;
+ open PDF,'<',$tempfile;
+ $pdf = (<PDF>);
+ close PDF;
+ unlink $tempfile;
+
+ return $pdf;
+}
+
+=head1 AUTHOR
+
+Jon Allen, L<jj at jonallen.info>
+
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-catalyst-view-pdf-reuse at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-PDF-Reuse>. I will be notified, and then you'll
+automatically be notified of progress on your bug as I make changes.
+
+
+=head1 SUPPORT
+
+You can find documentation for this module with the perldoc command.
+
+ perldoc Catalyst::View::PDF::API2
+
+Commercial support for this module is available from Penny's Arcade Limited,
+see L<http://www.pennysarcade.co.uk/contact> for contact details.
+
+You can also look for information at:
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-View-PDF-Reuse>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Catalyst-View-PDF-Reuse>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Catalyst-View-PDF-Reuse>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Catalyst-View-PDF-Reuse>
+
+=back
+
+
+=head1 SEE ALSO
+
+L<PDF::API2>
+
+Penny's Arcade Open Source - L<http://www.pennysarcade.co.uk/opensource>
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright (C) 2009 Penny's Arcade Limited
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1; # End of Catalyst::View::PDF::API2
Added: trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF/API2.pm
===================================================================
--- trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF/API2.pm (rev 0)
+++ trunk/misc/Catalyst-View-PDF-API2-0.01/lib/Template/Plugin/Catalyst/View/PDF/API2.pm 2009-08-27 22:17:29 UTC (rev 11259)
@@ -0,0 +1,31 @@
+package Template::Plugin::Catalyst::View::PDF::API2;
+
+use base qw(Template::Plugin::Procedural);
+use PDF::API2;
+
+=head1 NAME
+
+Template::Plugin::Catalyst::View::PDF::Reuse
+
+=head1 SYNOPSYS
+
+Template Toolkit plugin for PDF::Reuse
+
+=head1 AUTHOR
+
+Jon Allen, L<jj at jonallen.info>
+
+=head1 SEE ALSO
+
+Penny's Arcade Open Source - L<http://www.pennysarcade.co.uk/opensource>
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 Penny's Arcade Limited, all rights reserved.
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+
+=cut
+
+1;
More information about the Catalyst-commits
mailing list