| 1 | package Email::MIME::Kit::Assembler::TextifyHTML 1.004; | ||||||||||
| 2 | # ABSTRACT: textify some HTML arguments to assembly | ||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | 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 | ▶ | use HTML::FormatText::WithLinks; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 42 | |||||||||||
| 43 | has html_args => ( | ||||||||||
| 44 | is => 'ro', | ||||||||||
| 45 | isa => 'ArrayRef', | ||||||||||
| 46 | 0 | ▶ | default => sub { [] }, | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 47 | 1 | ); | |||||||||
| 48 | |||||||||||
| 49 | has formatter_args => ( | ||||||||||
| 50 | is => 'ro', | ||||||||||
| 51 | isa => 'HashRef', | ||||||||||
| 52 | default => sub { | ||||||||||
| 53 | return { | ||||||||||
| 54 | 1 | ▶ | before_link => '', | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 55 | after_link => ' [%l]', | ||||||||||
| 56 | footnote => '', | ||||||||||
| 57 | leftmargin => 0, | ||||||||||
| 58 | }; | ||||||||||
| 59 | }, | ||||||||||
| 60 | 1 | ); | |||||||||
| 61 | |||||||||||
| 62 | has formatter => ( | ||||||||||
| 63 | is => 'ro', | ||||||||||
| 64 | isa => 'HTML::FormatText::WithLinks', | ||||||||||
| 65 | lazy => 1, | ||||||||||
| 66 | init_arg => undef, | ||||||||||
| 67 | default => sub { | ||||||||||
| 68 | 1 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 69 | HTML::FormatText::WithLinks->new( | ||||||||||
| 70 | 1 | %{ $self->formatter_args }, | |||||||||
| 71 | ); | ||||||||||
| 72 | } | ||||||||||
| 73 | 1 | ); | |||||||||
| 74 | |||||||||||
| 75 | around assemble => sub { | ||||||||||
| 76 | 1 | ▶ | my ($orig, $self, $arg) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 77 | 1 | my $local_arg = { %$arg }; | |||||||||
| 78 | |||||||||||
| 79 | 1 | for my $key (@{ $self->html_args }) { | |||||||||
| 80 | 1 | ▶ | next unless defined $local_arg->{ $key }; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 1 | $local_arg->{ $key } = $self->formatter->parse($local_arg->{ $key }); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 1 | return $self->$orig($local_arg); | |||||||||
| 85 | 1 | }; | |||||||||
| 86 | |||||||||||
| 87 | 1 | ▶ | no Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 88 | 1 | 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.004 | ||||||||||
| 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 PERL VERSION | ||||||||||
| 131 | |||||||||||
| 132 | This library should run on perls released even a long time ago. It should work | ||||||||||
| 133 | on any version of perl released in the last five years. | ||||||||||
| 134 | |||||||||||
| 135 | Although it may work on older versions of perl, no guarantee is made that the | ||||||||||
| 136 | minimum required version will not be increased. The version may be increased | ||||||||||
| 137 | for any reason, and there is no promise that patches will be accepted to lower | ||||||||||
| 138 | the minimum required perl. | ||||||||||
| 139 | |||||||||||
| 140 | =head1 BY THE WAY | ||||||||||
| 141 | |||||||||||
| 142 | There will probably exist a TextifyHTML renderer, someday, which will first | ||||||||||
| 143 | render the part with the parent part's renderer, and then convert the produced | ||||||||||
| 144 | HTML to text. This would allow you to use one template for both HTML and text. | ||||||||||
| 145 | |||||||||||
| 146 | =head1 AUTHOR | ||||||||||
| 147 | |||||||||||
| 148 | Ricardo Signes <rjbs@semiotic.systems> | ||||||||||
| 149 | |||||||||||
| 150 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 151 | |||||||||||
| 152 | This software is copyright (c) 2022 by Ricardo Signes. | ||||||||||
| 153 | |||||||||||
| 154 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 155 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 156 | |||||||||||
| 157 | =cut | ||||||||||