package Mail::LMLM::Render::HTML;
use strict;
use vars qw(@ISA);
use Mail::LMLM::Render;
@ISA=qw(Mail::LMLM::Render);
sub initialize
{
my $self = shift;
my $out_file = shift;
$self->{'out'} = $out_file;
return 0;
}
sub _htmlize_onechar
{
my $c = shift;
if ($c eq "<")
{
return "\<";
}
elsif ($c eq ">")
{
return "\>";
}
elsif ($c eq '&')
{
return "\&"
}
elsif ($c eq "\n")
{
return "
";
}
else
{
return $c;
}
}
sub _htmlize
{
my $text = shift;
$text =~ s/(<|>|\&|\n)/_htmlize_onechar($1)/ge;
return $text;
}
sub text
{
my $self = shift;
my $text = shift;
my $style;
if (scalar(@_))
{
$style = shift;
}
else
{
$style = {};
}
my $out = _htmlize($text);
if ($style->{'bold'})
{
$out = "".$out."";
}
if ($style->{'underline'})
{
$out = "".$out."";
}
if ($style->{'italic'})
{
$out = "".$out."";
}
print {*{$self->{'out'}}} $out;
return 0;
}
sub newline
{
my $self = shift;
print {*{$self->{'out'}}} "
\n" ;
}
sub indent_inc
{
my $self = shift;
print {*{$self->{'out'}}} "\n
\n";
return 0;
}
sub indent_dec
{
my $self = shift;
print {*{$self->{'out'}}} "\n
\n" ;
return 0;
}
sub start_link
{
my $self = shift;
my $url = shift;
print {*{$self->{'out'}}} "";
return 0;
}
sub end_link
{
my $self = shift;
print {*{$self->{'out'}}} "";
return 0;
}
sub start_section
{
my $self = shift;
my $title = shift;
my $options;
if (scalar(@_))
{
$options = shift;
}
else
{
$options = {};
}
my $o = $self->{'out'};
my $id_attr = "";
if (exists($options->{'id'}))
{
$id_attr = " id=\"" . $options->{'id'} . "\"";
}
print {*{$o}} "" ;
print {*{$o}} "\n\n";
return 0;
}
sub start_para
{
my $self = shift;
print {*{$self->{'out'}}}("\n");
return 0;
}
sub end_para
{
my $self = shift;
print {*{$self->{'out'}}}("\n
\n");
return 0;
}
sub end_section
{
my $self = shift;
print {*{$self->{'out'}}}("\n\n");
return 0;
}
sub start_document
{
my $self = shift;
my $head_title = shift;
my $body_title = shift;
my $o = $self->{'out'};
print {*{$o}} <<"EOF" ;
$head_title
EOF
print {*{$o}}("");
$self->text($body_title);
print {*{$o}}("
\n\n");
return 0;
}
sub end_document
{
my $self = shift;
print {*{$self->{'out'}}}(
"\n" .
"\n" .
"\n"
);
return 0;
}
sub horizontal_line
{
my $self = shift;
print {*{$self->{'out'}}}("\n\n
\n\n");
return 0;
}
1;
=head1 NAME
Mail::LMLM::Render::HTML - backend for rendering HTML.
=head1 SYNOPSIS
use Mail::LMLM::Render::HTML;
open O, ">out.html";
my $r = Mail::LMLM::Render::HTML->new(\*O);
$r->start_document("My Document", "Head Title");
$r->start_section("Google", { 'title_url' => "http://www.google.com/", });
$r->para("Google is a very nice search engine.");
$r->end_section();
$r->end_document();
close(O);
=head1 DESCRIPTION
This is a derived class of L that renders HTML.
=head1 METHODS
=head2 start_document($head_title, $body_title)
=head2 end_document()
=head2 start_section($title [, { 'title_url' => $url } ])
=head2 end_section()
=head2 start_para()
=head2 end_para()
=head2 text($text [, $style])
=head2 newline()
=head2 start_link($url)
=head2 end_link()
=head2 indent_inc()
=head2 indent_dec()
=head2 horizontal_line()
=head2 email_address($account,$host)
=head2 url($url [, $inside])
=head2 para($text [, $style])
See the documentation at L.
=head2 initialize()
Construction method. For internal use.
=head1 AUTHOR
Shlomi Fish L.