[Catalyst-commits] r6712 - in trunk/Catalyst-View-Email: .
lib/Catalyst/View lib/Catalyst/View/Email t t/lib
t/lib/TestApp/Controller t/lib/TestApp/View t/root/text_html
t/root/text_plain
jshirley at dev.catalyst.perl.org
jshirley at dev.catalyst.perl.org
Wed Aug 22 17:31:23 GMT 2007
Author: jshirley
Date: 2007-08-22 17:31:23 +0100 (Wed, 22 Aug 2007)
New Revision: 6712
Added:
trunk/Catalyst-View-Email/t/07mason.t
trunk/Catalyst-View-Email/t/lib/TestApp/View/Mason.pm
Modified:
trunk/Catalyst-View-Email/Changes
trunk/Catalyst-View-Email/MANIFEST
trunk/Catalyst-View-Email/Makefile.PL
trunk/Catalyst-View-Email/lib/Catalyst/View/Email.pm
trunk/Catalyst-View-Email/lib/Catalyst/View/Email/Template.pm
trunk/Catalyst-View-Email/t/05template.t
trunk/Catalyst-View-Email/t/06config.t
trunk/Catalyst-View-Email/t/lib/TestApp.pm
trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm
trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm
trunk/Catalyst-View-Email/t/root/text_html/test.tt
trunk/Catalyst-View-Email/t/root/text_plain/test.tt
Log:
Bump to v0.06, adding in Mason tests and better config handling
Modified: trunk/Catalyst-View-Email/Changes
===================================================================
--- trunk/Catalyst-View-Email/Changes 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/Changes 2007-08-22 16:31:23 UTC (rev 6712)
@@ -1,5 +1,12 @@
Revision history for Perl extension Catalyst::View::Email.
+0.06
+ - Fixing some slight issues with configuration not being handled
+ appropriately (thanks dwc and mst)
+0.05
+ - Better support for configuration
+ - Adding Mason tests
+
0.04
- Fixing MANIFEST, distribution
Modified: trunk/Catalyst-View-Email/MANIFEST
===================================================================
--- trunk/Catalyst-View-Email/MANIFEST 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/MANIFEST 2007-08-22 16:31:23 UTC (rev 6712)
@@ -22,11 +22,15 @@
t/04basic.t
t/05template.t
t/06config.t
+t/07mason.t
t/lib/TestApp.pm
t/lib/TestApp/Controller/Root.pm
t/lib/TestApp/View/Email.pm
t/lib/TestApp/View/Email/AppConfig.pm
t/lib/TestApp/View/Email/Template.pm
+t/lib/TestApp/View/Mason.pm
t/lib/TestApp/View/TT.pm
+t/root/text_html/test.m
t/root/text_html/test.tt
+t/root/text_plain/test.m
t/root/text_plain/test.tt
Modified: trunk/Catalyst-View-Email/Makefile.PL
===================================================================
--- trunk/Catalyst-View-Email/Makefile.PL 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/Makefile.PL 2007-08-22 16:31:23 UTC (rev 6712)
@@ -10,7 +10,13 @@
requires 'Email::MIME' => '1.859';
requires 'Email::MIME::Creator' => '1.453';
-build_requires 'Catalyst::View::TT';
+feature 'Template Toolkit Support',
+ -default => 1,
+ 'Catalyst::View::TT' => 0;
+feature 'Mason Support',
+ -default => 0,
+ 'Catalyst::View::Mason';
+
auto_install;
WriteAll;
Modified: trunk/Catalyst-View-Email/lib/Catalyst/View/Email/Template.pm
===================================================================
--- trunk/Catalyst-View-Email/lib/Catalyst/View/Email/Template.pm 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/lib/Catalyst/View/Email/Template.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -10,8 +10,10 @@
use base qw|Catalyst::View::Email|;
-our $VERSION = '0.03';
+our $VERSION = '0.06';
+__PACKAGE__->mk_accessors( qw(default_view template_prefix) );
+
=head1 NAME
Catalyst::View::Email::Template - Send Templated Email from Catalyst
@@ -97,13 +99,13 @@
sub process {
my ( $self, $c ) = @_;
- my $stash_key = $self->config->{stash_key} || 'email';
+ my $stash_key = $self->stash_key || 'email';
croak "No template specified for rendering"
unless $c->stash->{$stash_key}->{template} or
$c->stash->{$stash_key}->{templates};
# Where to look
- my $template_prefix = $self->config->{template_prefix};
+ my $template_prefix = $self->template_prefix;
my @templates = ();
if ( $c->stash->{$stash_key}->{templates} && !ref $c->stash->{$stash_key}->{templates}[0]) {
@@ -116,7 +118,7 @@
$c->stash->{$stash_key}->{template});
}
- my $default_view = $c->view( $self->config->{default_view} );
+ my $default_view = $c->view( $self->default_view );
unless ( $default_view->can('render') ) {
croak "Email::Template's configured view does not have a render method!";
@@ -137,8 +139,13 @@
} else {
$content_type = 'text/plain';
}
- my $output = $default_view->render( $c, $template,
- { content_type => $content_type, %{$c->stash} });
+
+ my $output = $default_view->render( $c, $template, {
+ content_type => $content_type,
+ stash_key => $self->stash_key,
+ %{$c->stash},
+ });
+
# Got a ref, not a scalar. An error!
if ( ref $output ) {
croak $output->can("as_string") ? $output->as_string : $output;
@@ -178,9 +185,9 @@
}
}
- delete $c->stash->{email}->{body};
- $c->stash->{email}->{parts} ||= [];
- push @{$c->stash->{email}->{parts}}, @parts;
+ delete $c->stash->{$stash_key}->{body};
+ $c->stash->{$stash_key}->{parts} ||= [];
+ push @{$c->stash->{$stash_key}->{parts}}, @parts;
# Let C::V::Email do the actual sending. We just assemble the tasty bits.
return $self->next::method($c);
Modified: trunk/Catalyst-View-Email/lib/Catalyst/View/Email.pm
===================================================================
--- trunk/Catalyst-View-Email/lib/Catalyst/View/Email.pm 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/lib/Catalyst/View/Email.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -11,7 +11,7 @@
use base qw|Catalyst::View|;
-our $VERSION = '0.05';
+our $VERSION = '0.06';
__PACKAGE__->mk_accessors(qw(sender stash_key content_type mailer));
Modified: trunk/Catalyst-View-Email/t/05template.t
===================================================================
--- trunk/Catalyst-View-Email/t/05template.t 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/05template.t 2007-08-22 16:31:23 UTC (rev 6712)
@@ -1,11 +1,18 @@
use strict;
use warnings;
-use Test::More tests => 10;
+use Test::More;
use Email::Send::Test;
use FindBin;
use lib "$FindBin::Bin/lib";
+eval "use Catalyst::View::TT";
+if ( $@ ) {
+ plan skip_all => 'Catalyst::View::TT required for Template tests';
+ exit;
+}
+plan tests => 10;
+
use_ok('Catalyst::Test', 'TestApp');
my $response;
Modified: trunk/Catalyst-View-Email/t/06config.t
===================================================================
--- trunk/Catalyst-View-Email/t/06config.t 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/06config.t 2007-08-22 16:31:23 UTC (rev 6712)
@@ -1,6 +1,6 @@
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 13;
use Email::Send::Test;
use FindBin;
@@ -9,11 +9,33 @@
use_ok('Catalyst::Test', 'TestApp');
my $response;
-my $time = time;
+my $time;
+my @emails;
+
+$time = time;
+
ok( ($response = request("/email_app_config?time=$time"))->is_success, 'request ok');
-my @emails = Email::Send::Test->emails;
+ at emails = Email::Send::Test->emails;
is(@emails, 1, "got emails");
isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
like($emails[0]->body, qr/$time/, 'Got our email');
+
+Email::Send::Test->clear;
+
+$time = time;
+ok( ($response = request("/template_email_app_config?time=$time"))->is_success, 'request ok');
+
+ at emails = Email::Send::Test->emails;
+
+is(@emails, 1, "got emails");
+isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+my @parts = $emails[0]->parts;
+cmp_ok(@parts, '==', 2, 'got parts');
+
+is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain ok');
+like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
+is($parts[1]->content_type, 'text/html; charset="us-ascii"', 'text/html ok');
+like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
+
Added: trunk/Catalyst-View-Email/t/07mason.t
===================================================================
--- trunk/Catalyst-View-Email/t/07mason.t (rev 0)
+++ trunk/Catalyst-View-Email/t/07mason.t 2007-08-22 16:31:23 UTC (rev 6712)
@@ -0,0 +1,37 @@
+use strict;
+use warnings;
+use Test::More;
+
+use Email::Send::Test;
+use FindBin;
+use lib "$FindBin::Bin/lib";
+
+eval "use Catalyst::View::Mason";
+if ( $@ ) {
+ plan skip_all => 'Catalyst::View::Mason required for Mason tests';
+ exit;
+}
+plan tests => 10;
+
+use_ok('Catalyst::Test', 'TestApp');
+
+TestApp->config->{default_view} = 'mason';
+
+my $response;
+my $time = time;
+ok( ( $response = request("/mason_email?time=$time"))->is_success,
+ 'request ok' );
+like( $response->content, qr/Mason Email Ok/, 'controller says ok' );
+my @emails = Email::Send::Test->emails;
+
+cmp_ok(@emails, '==', 1, 'got emails');
+isa_ok( $emails[0], 'Email::MIME', 'email is ok' );
+my @parts = $emails[0]->parts;
+cmp_ok(@parts, '==', 2, 'got parts');
+
+is($parts[0]->content_type, 'text/plain; charset="us-ascii"', 'text/plain ok');
+like($parts[0]->body, qr/test-email\@example.com on $time/, 'got content back');
+is($parts[1]->content_type, 'text/html; charset="us-ascii"', 'text/html ok');
+like($parts[1]->body, qr{<em>test-email\@example.com</em> on $time}, 'got content back');
+#like($emails[0]->body, qr/$time/, 'Got our email');
+
Modified: trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/Controller/Root.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -79,4 +79,57 @@
}
}
+sub template_email_app_config : Global('template_email_app_config') {
+ my ($self, $c, @args) = @_;
+
+ $c->stash->{time} = $c->req->params->{time} || time;
+
+ $c->stash->{template_email} = {
+ to => 'test-email at example.com',
+ from => 'no-reply at example.com',
+ subject => 'Just a test',
+ content_type => 'multipart/alternative',
+ templates => [
+ qw{text_plain/test.tt},
+ qw{text_html/test.tt}
+ ]
+ };
+
+ $c->forward('TestApp::View::Email::Template::AppConfig');
+
+ if ( scalar( @{ $c->error } ) ) {
+ $c->res->status(500);
+ $c->res->body('Template Email Failed');
+ } else {
+ $c->res->body('Template Email Ok');
+ }
+}
+
+sub mason_email : Global('mason_email') {
+ my ($self, $c, @args) = @_;
+
+ $c->stash->{time} = $c->req->params->{time} || time;
+
+ $c->stash->{email} = {
+ to => 'test-email at example.com',
+ from => 'no-reply at example.com',
+ subject => 'Just a test',
+ content_type => 'multipart/alternative',
+ templates => [
+ qw{text_plain/test.m},
+ qw{text_html/test.m}
+ ]
+ };
+
+ $c->forward('TestApp::View::Email::Template');
+
+ if ( scalar( @{ $c->error } ) ) {
+ $c->res->status(500);
+ $c->res->body('Mason Email Failed');
+ } else {
+ $c->res->body('Mason Email Ok');
+ }
+}
+
+
1;
Added: trunk/Catalyst-View-Email/t/lib/TestApp/View/Mason.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/View/Mason.pm (rev 0)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/View/Mason.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -0,0 +1,7 @@
+package # Hide me.
+ TestApp::View::Mason;
+
+use strict;
+eval "use base 'Catalyst::View::Mason';";
+
+1;
Modified: trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/lib/TestApp/View/TT.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -2,6 +2,6 @@
TestApp::View::TT;
use strict;
-use base 'Catalyst::View::TT';
+eval "use base 'Catalyst::View::TT';";
1;
Modified: trunk/Catalyst-View-Email/t/lib/TestApp.pm
===================================================================
--- trunk/Catalyst-View-Email/t/lib/TestApp.pm 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/lib/TestApp.pm 2007-08-22 16:31:23 UTC (rev 6712)
@@ -12,6 +12,12 @@
method => 'Test',
},
},
+ 'View::Email::Template::AppConfig' => {
+ stash_key => 'template_email',
+ sender => {
+ method => 'Test',
+ },
+ },
);
TestApp->setup;
Modified: trunk/Catalyst-View-Email/t/root/text_html/test.tt
===================================================================
--- trunk/Catalyst-View-Email/t/root/text_html/test.tt 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/root/text_html/test.tt 2007-08-22 16:31:23 UTC (rev 6712)
@@ -1,7 +1,7 @@
<html>
<body>
<h1>Look at my style</h1>
- <p>I was sent to <em>[% email.to %]</em> on [% time %]</p>
+ <p>I was sent to <em>[% $stash_key.to %]</em> on [% time %]</p>
</body>
</html>
Modified: trunk/Catalyst-View-Email/t/root/text_plain/test.tt
===================================================================
--- trunk/Catalyst-View-Email/t/root/text_plain/test.tt 2007-08-22 08:25:18 UTC (rev 6711)
+++ trunk/Catalyst-View-Email/t/root/text_plain/test.tt 2007-08-22 16:31:23 UTC (rev 6712)
@@ -1,3 +1,3 @@
I am plain text. I have no style.
-I was sent to [% email.to %] on [% time %]
+I was sent to [% $stash_key.to %] on [% time %]
More information about the Catalyst-commits
mailing list