Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur Axel 'fREW' Schmidt committed May 20, 2014
0 parents commit 5d63f1c
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.build
Email-MIME-Kit-Renderer-Xslate-*
20 changes: 20 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
language: perl
perl:
- "5.18"
- "5.16"
- "5.14"
- "5.12"
- "5.10"
- "5.8"

install:
- export RELEASE_TESTING=1 AUTOMATED_TESTING=1 AUTHOR_TESTING=1 HARNESS_OPTIONS=j10:c HARNESS_TIMER=1
- cpanm --quiet --notest Devel::Cover::Report::Coveralls
- cpanm --quiet --notest --installdeps .

script:
- PERL5OPT=-MDevel::Cover=-coverage,statement,branch,condition,path,subroutine prove -lrsv t
- cover

after_success:
- cover -report coveralls
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Revision history for {{$dist->name}}

{{$NEXT}}
- Initial Release
6 changes: 6 additions & 0 deletions cpanfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
requires 'Email::MIME::Kit' => 2;
requires 'Text::Xslate' => '3.2.4';

on test => sub {
requires 'Test::More' => 0.94;
};
18 changes: 18 additions & 0 deletions dist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name = Email-MIME-Kit-Renderer-Xslate
author = Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
license = Perl_5
copyright_holder = Arthur Axel "fREW" Schmidt
version = 0.001000

[NextRelease]
[@Git]
[@Basic]
[GithubMeta]
issues = 1

[MetaJSON]
[PodWeaver]
[PkgVersion]
[ReadmeFromPod]
[PodSyntaxTests]
[Prereqs::FromCPANfile]
69 changes: 69 additions & 0 deletions lib/Email/MIME/Kit/Renderer/Xslate.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package Email::MIME::Kit::Renderer::Xslate;

use Moose;
with 'Email::MIME::Kit::Role::Renderer';

# ABSTRACT: render parts of your mail with Text::Xslate

use Text::Xslate;

sub render {
my ($self, $tpl, $stash) = @_;

\($self->_render_tx($$tpl, $stash||{}))
}

has options => (
is => 'ro',
default => sub { {} },
);

has _tx => (
is => 'ro',
lazy => 1,
init_arg => undef,
default => sub { Text::Xslate->new(shift->options) },
handles => {
_render_tx => 'render_string',
},
);

1;

__END__
=pod
=head1 DESCRIPTION
This is a renderer plugin for L<Email::MIME::Kit>, and renders message parts
using L<Text::Xslate>. When specifying a renderer in F<manifest.json>, you
might write something like this:
{ ..., "renderer": "Xslate" }
Or, to supply options:
{
...,
"renderer": [
"Xslate", {
"options": {
"syntax": "Kolon"
// etc etc
}
}
]
}
All options are passed verbatim to C<< Text::Xslate->new >>.
For plaintext emails a good default is
"renderer": [
"Xslate", {
"options": { "type":"text" }
}
]
=cut
36 changes: 36 additions & 0 deletions t/assemble.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

use Email::MIME::Kit;

my $kit = Email::MIME::Kit->new({
source => 't/kits/test.mkit',
});

my $email_1 = $kit->assemble({
name => 'Reticulo Johnson',
game => "eatin' pancakes",
});

like(
$email_1->body,
qr{\QReticulo Johnson is my name, eatin' pancakes is my game},
"tt stuff happened",
);

my $email_2 = $kit->assemble({
name => 'Bryan Allen',
game => "nukin' jar cheese",
});

like(
$email_2->body,
qr{\QBryan Allen is my name, nukin' jar cheese is my game},
"tt stuff happened",
);

done_testing;
9 changes: 9 additions & 0 deletions t/kits/test.mkit/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"renderer": ["Xslate", { "options": { "type":"text" } }],
"header": [
{ "Subject": "Test TT Message" },
{ "From": "test@example.com" }
],
"type": "text/plain",
"body": "<: $name :> is my name, <: $game :> is my game."
}

0 comments on commit 5d63f1c

Please sign in to comment.