use Stenciller::Standard;

our $VERSION = '0.1004'; # VERSION
# ABSTRACT: A plugin that renders to html
# PODNAME: Stenciller::Plugin::ToHtmlPreBlock

class Stenciller::Plugin::ToHtmlPreBlock using Moose with Stenciller::Renderer {

    use HTML::Entities 'encode_entities';

    has stenciller => (
        is => 'ro',
        isa => Stenciller,
        required => 1,
    );

    method render {
        my @out = ();

        STENCIL:
        foreach my $stencil ($self->stenciller->all_stencils) {

            push @out => $self->normal($stencil->all_before_input);
            push @out => $self->pre($stencil->all_input);
            push @out => $self->normal($stencil->all_between);
            push @out => $self->pre($stencil->all_output);
            push @out => $self->normal($stencil->all_after_output);

        }
        return join '' => @out;
    }

    method normal(@lines) {
        return () if !scalar @lines;
        return join "\n" => '<p>', @lines, '</p>';
    }

    method pre(@lines) {
        return () if !scalar @lines;

        my @encoded_lines = map {  encode_entities($_) } @lines;
        return  join "\n" => '<pre>', @encoded_lines, '</pre>';
    }
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

Stenciller::Plugin::ToHtmlPreBlock - A plugin that renders to html

=head1 VERSION

Version 0.1004, released 2015-01-15.

=head1 SYNOPSIS

    use Stenciller;
    my $stenciller = Stenciller->new(filepath => 't/corpus/test-1.stencil');
    my $content = $stenciller->render('ToHtmlPreBlock');

=head1 DESCRIPTION

This plugin to L<Stenciller> places the C<before_input>, C<between> and C<after_output> regions in C<E<lt>pE<gt>> tags and the C<input> and C<output> regions inside C<E<lt>preE<gt>> tags.



=head1 SOURCE

L<https://github.com/Csson/p5-Stenciller>

=head1 HOMEPAGE

L<https://metacpan.org/release/Stenciller>

=head1 AUTHOR

Erik Carlsson <info@code301.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
