Permalink
Browse files

first commit of this thing

  • Loading branch information...
0 parents commit 2d967ef0a853d09f55d2913c65d48b7eb938f1a0 Stevan Little committed Jun 28, 2007
@@ -0,0 +1,26 @@
+use Module::Build;
+
+use strict;
+
+my $build = Module::Build->new(
+ module_name => 'Catalyst::View::Excel::Template::Plus',
+ license => 'perl',
+ requires => {
+ 'Catalyst::Runtime' => '0',
+ 'Excel::Template::Plus' => '0',
+ },
+ optional => {
+ },
+ build_requires => {
+ 'Test::More' => '0.62',
+ 'Test::Exception' => '0.21',
+ },
+ create_makefile_pl => 'traditional',
+ recursive_test_files => 1,
+ add_to_cleanup => [
+ 'META.yml', '*.bak', '*.gz', 'Makefile.PL',
+ ],
+);
+
+$build->create_build_script;
+
@@ -0,0 +1,4 @@
+Changes for Catalyst::View::Excel::Template::Plus
+
+0.01
+ - initial release
No changes.
No changes.
30 README
@@ -0,0 +1,30 @@
+Catalyst::View::Excel::Template::Plus version 0.01
+===========================
+
+See the individual module documentation for more information
+
+INSTALLATION
+
+To install this module type the following:
+
+ perl Makefile.PL
+ make
+ make test
+ make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+ Catalyst::Runtime
+ Excel::Template::Plus
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2007 Infinity Interactive, Inc.
+
+http://www.iinteractive.com
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
@@ -0,0 +1,144 @@
+package Catalyst::View::Excel::Template::Plus;
+
+use strict;
+use warnings;
+
+use NEXT;
+use Excel::Template::Plus;
+use Scalar::Util 'blessed';
+
+use Catalyst::Exception;
+
+our $VERSION = '0.01';
+our $AUTHORITY = 'cpan:STEVAN';
+
+use base 'Catalyst::View';
+
+__PACKAGE__->mk_accessors(qw[
+ etp_engine
+ etp_config
+ etp_params
+]);
+
+sub new {
+ my($class, $c, $args) = @_;
+ my $self = $class->NEXT::new($c, $args);
+
+ my $config = $c->config->{'View::Excel::Template::Plus'};
+
+ $args->{etp_engine} ||= $config->{etp_engine} || 'TT';
+ $args->{etp_config} ||= $config->{etp_config} || {};
+ $args->{etp_params} ||= $config->{etp_params} || {};
+
+ $self->etp_engine($args->{etp_engine});
+ $self->etp_config($args->{etp_config});
+ $self->etp_params($args->{etp_params});
+
+ return $self;
+}
+
+sub process {
+ my $self = shift;
+ my $c = shift;
+ my @args = @_;
+
+ my $template = $self->get_template_filename($c);
+
+ (defined $template)
+ || die 'No template specified for rendering';
+
+ my $etp_engine = $c->stash->{etp_engine} || $self->etp_engine;
+ my $etp_config = $c->stash->{etp_config} || $self->etp_config;
+ my $etp_params = $c->stash->{etp_params} || $self->etp_params;
+
+ my $excel = Excel::Template::Plus->new(
+ engine => $etp_engine,
+ template => $template,
+ config => $etp_config,
+ params => $etp_params,
+ );
+
+ $excel->param( $self->get_template_params($c) );
+
+ $c->response->content_type('application/x-msexcel');
+ $c->response->body($excel->output);
+}
+
+sub get_template_filename {
+ my ($self, $c) = @_;
+ $c->stash->{template}
+ ||
+ ($c->action . '.xml.' . $self->config->{TEMPLATE_EXTENSION});
+}
+
+sub get_template_params {
+ my ($self, $c) = @_;
+ my $cvar = $self->config->{CATALYST_VAR} || 'c';
+ return ( $cvar => $c, %{ $c->stash } );
+}
+
+1;
+
+__END__
+
+=pod
+
+=head1 NAME
+
+Catalyst::View::Excel::Template::Plus - A Catalyst View for Excel::Template::Plus
+
+=head1 SYNOPSIS
+
+=head1 DESCRIPTION
+
+This is a Catalyst View subclass which can handle rendering excel content
+through Excel::Template::Plus.
+
+=head1 CONFIG OPTIONS
+
+=over 4
+
+=item I<etp_engine>
+
+=item I<etp_config>
+
+=item I<etp_params>
+
+=back
+
+=head1 METHODS
+
+=over 4
+
+=item B<new>
+
+This really just handles consuming the configuration parameters.
+
+=item B<process>
+
+=item B<get_template_filename>
+
+=item B<get_template_params>
+
+=back
+
+=head1 BUGS
+
+All complex software has bugs lurking in it, and this module is no
+exception. If you find a bug please either email me, or add the bug
+to cpan-RT.
+
+=head1 AUTHOR
+
+Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright 2007 by Infinity Interactive, Inc.
+
+L<http://www.iinteractive.com>
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
@@ -0,0 +1,10 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More no_plan => 1;
+
+BEGIN {
+ use_ok('Catalyst::View::Excel::Template::Plus');
+}
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use FindBin;
+use File::Spec;
+
+use lib (File::Spec->catdir($FindBin::Bin, 'lib'));
+
+use Test::More tests => 6;
+
+use Catalyst::Test 'TestApp';
+use Test::Excel::Template::Plus qw(cmp_excel_files);
+
+BEGIN {
+ use_ok('Catalyst::View::Excel::Template::Plus');
+}
+
+{
+ my $response = request('http://localhost/test_one');
+
+ ok(defined $response, '... got the response successfully');
+ ok($response->is_success, '... response is a success');
+ is($response->code, 200, '... response code is 200');
+ is_deeply(
+ [ $response->content_type ],
+ [ 'application/x-msexcel' ],
+ '... the response content type is application/x-msexcel');
+
+ my $excel = $response->content;
+
+ open FOO, '>', 'temp.xls' || die "Could not write temp file for testing : $!";
+ print FOO $excel;
+ close FOO;
+
+ cmp_excel_files("temp.xls", "t/xls/001_basic.xls", '... the generated excel file was correct');
+
+ #`open temp.xls`;
+ unlink 'temp.xls';
+}
@@ -0,0 +1,40 @@
+package TestApp;
+
+use strict;
+use warnings;
+
+use FindBin;
+
+use Catalyst;
+use Excel::Template::Plus;
+use Path::Class;
+
+use TestApp::View::Excel;
+
+__PACKAGE__->config({
+ name => 'TestApp',
+ 'View::Excel::Template::Plus' => {
+ etp_config => {
+ INCLUDE_PATH => [
+ (dir($FindBin::Bin, 'templates' )->stringify . '/'),
+ ]
+ }
+ }
+});
+
+__PACKAGE__->setup;
+
+sub test_one : Global {
+ my ($self, $c) = @_;
+
+ $c->stash->{template} = 'test_one.xml.tmpl';
+
+ $c->stash->{message} = 'Hello (Excel) World';
+
+ $c->forward('TestApp::View::Excel');
+}
+
+
+1;
+
+__END__
@@ -0,0 +1,10 @@
+package TestApp::View::Excel;
+
+use strict;
+use warnings;
+
+use base 'Catalyst::View::Excel::Template::Plus';
+
+1;
+
+__END__
11 t/pod.t
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod 1.14";
+plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
+
+all_pod_files_ok();
@@ -0,0 +1,11 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+eval "use Test::Pod::Coverage 1.04";
+plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
+
+all_pod_coverage_ok();
@@ -0,0 +1,7 @@
+<workbook>
+ <worksheet>
+ <row>
+ <cell>[% message %]</cell>
+ </row>
+ </worksheet>
+</workbook>
Binary file not shown.

0 comments on commit 2d967ef

Please sign in to comment.