| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Email::MIME::Kit::Assembler::TextifyHTML; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: textify some HTML arguments to assembly |
|
3
|
|
|
|
|
|
|
$Email::MIME::Kit::Assembler::TextifyHTML::VERSION = '1.003'; |
|
4
|
1
|
|
|
1
|
|
109628
|
use Moose; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
|
|
extends 'Email::MIME::Kit::Assembler::Standard'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
|
8
|
|
|
|
|
|
|
#pod |
|
9
|
|
|
|
|
|
|
#pod In your F<manifest.yaml>: |
|
10
|
|
|
|
|
|
|
#pod |
|
11
|
|
|
|
|
|
|
#pod alteratives: |
|
12
|
|
|
|
|
|
|
#pod - type: text/plain |
|
13
|
|
|
|
|
|
|
#pod path: body.txt |
|
14
|
|
|
|
|
|
|
#pod assembler: |
|
15
|
|
|
|
|
|
|
#pod - TextifyHTML |
|
16
|
|
|
|
|
|
|
#pod - html_args: [ body ] |
|
17
|
|
|
|
|
|
|
#pod - type: text/html |
|
18
|
|
|
|
|
|
|
#pod path: body.html |
|
19
|
|
|
|
|
|
|
#pod |
|
20
|
|
|
|
|
|
|
#pod Then: |
|
21
|
|
|
|
|
|
|
#pod |
|
22
|
|
|
|
|
|
|
#pod my $email = $kit->assemble({ |
|
23
|
|
|
|
|
|
|
#pod body => '<div><p> ... </p></div>', |
|
24
|
|
|
|
|
|
|
#pod }); |
|
25
|
|
|
|
|
|
|
#pod |
|
26
|
|
|
|
|
|
|
#pod The C<body> argument will be rendered intact in the the HTML part, but will |
|
27
|
|
|
|
|
|
|
#pod converted to plaintext before the plaintext part is rendered. |
|
28
|
|
|
|
|
|
|
#pod |
|
29
|
|
|
|
|
|
|
#pod This will be done by |
|
30
|
|
|
|
|
|
|
#pod L<HTML::FormatText::WithLinks|HTML::FormatText::WithLinks>, using the arguments |
|
31
|
|
|
|
|
|
|
#pod provided in the C<formatter_args> assembler attribute. |
|
32
|
|
|
|
|
|
|
#pod |
|
33
|
|
|
|
|
|
|
#pod =head1 BY THE WAY |
|
34
|
|
|
|
|
|
|
#pod |
|
35
|
|
|
|
|
|
|
#pod There will probably exist a TextifyHTML renderer, someday, which will first |
|
36
|
|
|
|
|
|
|
#pod render the part with the parent part's renderer, and then convert the produced |
|
37
|
|
|
|
|
|
|
#pod HTML to text. This would allow you to use one template for both HTML and text. |
|
38
|
|
|
|
|
|
|
#pod |
|
39
|
|
|
|
|
|
|
#pod =cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
1
|
|
|
1
|
|
5153
|
use HTML::FormatText::WithLinks; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has html_args => ( |
|
44
|
|
|
|
|
|
|
is => 'ro', |
|
45
|
|
|
|
|
|
|
isa => 'ArrayRef', |
|
46
|
|
|
|
|
|
|
default => sub { [] }, |
|
47
|
|
|
|
|
|
|
); |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has formatter_args => ( |
|
50
|
|
|
|
|
|
|
is => 'ro', |
|
51
|
|
|
|
|
|
|
isa => 'HashRef', |
|
52
|
|
|
|
|
|
|
default => sub { |
|
53
|
|
|
|
|
|
|
return { |
|
54
|
|
|
|
|
|
|
before_link => '', |
|
55
|
|
|
|
|
|
|
after_link => ' [%l]', |
|
56
|
|
|
|
|
|
|
footnote => '', |
|
57
|
|
|
|
|
|
|
leftmargin => 0, |
|
58
|
|
|
|
|
|
|
}; |
|
59
|
|
|
|
|
|
|
}, |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has formatter => ( |
|
63
|
|
|
|
|
|
|
is => 'ro', |
|
64
|
|
|
|
|
|
|
isa => 'HTML::FormatText::WithLinks', |
|
65
|
|
|
|
|
|
|
lazy => 1, |
|
66
|
|
|
|
|
|
|
init_arg => undef, |
|
67
|
|
|
|
|
|
|
default => sub { |
|
68
|
|
|
|
|
|
|
my ($self) = @_; |
|
69
|
|
|
|
|
|
|
HTML::FormatText::WithLinks->new( |
|
70
|
|
|
|
|
|
|
%{ $self->formatter_args }, |
|
71
|
|
|
|
|
|
|
); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
around assemble => sub { |
|
76
|
|
|
|
|
|
|
my ($orig, $self, $arg) = @_; |
|
77
|
|
|
|
|
|
|
my $local_arg = { %$arg }; |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
for my $key (@{ $self->html_args }) { |
|
80
|
|
|
|
|
|
|
next unless defined $local_arg->{ $key }; |
|
81
|
|
|
|
|
|
|
$local_arg->{ $key } = $self->formatter->parse($local_arg->{ $key }); |
|
82
|
|
|
|
|
|
|
} |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
return $self->$orig($local_arg); |
|
85
|
|
|
|
|
|
|
}; |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
no Moose; |
|
88
|
|
|
|
|
|
|
1; |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=encoding UTF-8 |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 NAME |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Email::MIME::Kit::Assembler::TextifyHTML - textify some HTML arguments to assembly |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 VERSION |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
version 1.003 |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
In your F<manifest.yaml>: |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
alteratives: |
|
109
|
|
|
|
|
|
|
- type: text/plain |
|
110
|
|
|
|
|
|
|
path: body.txt |
|
111
|
|
|
|
|
|
|
assembler: |
|
112
|
|
|
|
|
|
|
- TextifyHTML |
|
113
|
|
|
|
|
|
|
- html_args: [ body ] |
|
114
|
|
|
|
|
|
|
- type: text/html |
|
115
|
|
|
|
|
|
|
path: body.html |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Then: |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
my $email = $kit->assemble({ |
|
120
|
|
|
|
|
|
|
body => '<div><p> ... </p></div>', |
|
121
|
|
|
|
|
|
|
}); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
The C<body> argument will be rendered intact in the the HTML part, but will |
|
124
|
|
|
|
|
|
|
converted to plaintext before the plaintext part is rendered. |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
This will be done by |
|
127
|
|
|
|
|
|
|
L<HTML::FormatText::WithLinks|HTML::FormatText::WithLinks>, using the arguments |
|
128
|
|
|
|
|
|
|
provided in the C<formatter_args> assembler attribute. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 BY THE WAY |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
There will probably exist a TextifyHTML renderer, someday, which will first |
|
133
|
|
|
|
|
|
|
render the part with the parent part's renderer, and then convert the produced |
|
134
|
|
|
|
|
|
|
HTML to text. This would allow you to use one template for both HTML and text. |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 AUTHOR |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Ricardo Signes <rjbs@cpan.org> |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
This software is copyright (c) 2015 by Ricardo Signes. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
145
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |