File Coverage

blib/lib/Stenciller/Plugin/ToHtmlPreBlock.pm
Criterion Covered Total %
statement 37 37 100.0
branch 6 6 100.0
condition n/a
subroutine 9 9 100.0
pod 1 3 33.3
total 53 55 96.3


line stmt bran cond sub pod time code
1 2     2   1006 use 5.14.0;
  2         6  
  2         81  
2 2     2   8 use strict;
  2         3  
  2         58  
3 2     2   7 use warnings;
  2         2  
  2         113  
4              
5             package Stenciller::Plugin::ToHtmlPreBlock;
6             our $VERSION = '0.1212'; # VERSION:
7             # ABSTRACT: A plugin that transforms to html
8              
9 2     2   7 use Moose;
  2         5  
  2         16  
10 2     2   11577 use List::AllUtils qw/first_index/;
  2         3  
  2         150  
11             with 'Stenciller::Transformer';
12              
13 2     2   1061 use HTML::Entities 'encode_entities';
  2         10088  
  2         808  
14              
15             sub transform {
16 2     2 1 763 my $self = shift;
17 2         3 my $transform_args = shift;
18              
19 2         58 my @out = $self->init_out($self->stenciller, $transform_args);
20              
21             STENCIL:
22 2         51 for my $i (0 .. $self->stenciller->max_stencil_index) {
23 5 100       38 next STENCIL if $self->should_skip_stencil_by_index($i, $transform_args);
24              
25 4         118 my $stencil = $self->stenciller->get_stencil($i);
26 4 100       173 next STENCIL if $self->should_skip_stencil($stencil, $transform_args);
27              
28 3         116 push @out => $self->normal($stencil->all_before_input),
29             $self->pre($stencil->all_input),
30             $self->normal($stencil->all_between),
31             $self->pre($stencil->all_output),
32             $self->normal($stencil->all_after_output);
33              
34             }
35 2         22 return join "\n" => @out;
36             }
37              
38             sub normal {
39 9     9 0 61 my $self = shift;
40 9         13 my @lines = @_;
41              
42 9 100       24 return () if !scalar @lines;
43 6         201 return join '' => ('<p>', join ('' => @lines), '</p>');
44             }
45             sub pre {
46 6     6 0 41 my $self = shift;
47 6         9 my @lines = @_;
48              
49 6         8 my @encoded_lines = map { $_ =~ s{^ {4}}{}; encode_entities($_) } @lines;
  12         153  
  12         26  
50 6         248 return join '' => ('<pre>', join ("\n" => @encoded_lines), '</pre>');
51             }
52              
53             1;
54              
55             __END__
56              
57             =pod
58              
59             =encoding UTF-8
60              
61             =head1 NAME
62              
63             Stenciller::Plugin::ToHtmlPreBlock - A plugin that transforms to html
64              
65             =head1 VERSION
66              
67             Version 0.1212, released 2015-02-10.
68              
69              
70              
71             =head1 SYNOPSIS
72              
73             use Stenciller;
74             my $stenciller = Stenciller->new(filepath => 't/corpus/test-1.stencil');
75             my $content = $stenciller->transform('ToHtmlPreBlock');
76              
77             =head1 DESCRIPTION
78              
79             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.
80              
81             Content that will be placed in C<pre> tags (input and output sections in stencils) also have four leading spaces removed.
82              
83             =head1 METHODS
84              
85             =head2 transform
86              
87             See L<transform|Stenciller::Transformer/"transform"> in L<Stenciller::Transformer>.
88              
89             =head1 SOURCE
90              
91             L<https://github.com/Csson/p5-Stenciller>
92              
93             =head1 HOMEPAGE
94              
95             L<https://metacpan.org/release/Stenciller>
96              
97             =head1 AUTHOR
98              
99             Erik Carlsson <info@code301.com>
100              
101             =head1 COPYRIGHT AND LICENSE
102              
103             This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
104              
105             This is free software; you can redistribute it and/or modify it under
106             the same terms as the Perl 5 programming language system itself.
107              
108             =cut