| 1 | 3 | ▶ | use 5.14.0; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||
| 5 | package Stenciller::Plugin::ToHtmlPreBlock; | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 3 | our $VERSION = '0.1302'; # VERSION: | |||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: A plugin that transforms to html | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use Moose; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use List::AllUtils qw/first_index/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 12 | 3 | with 'Stenciller::Transformer'; | |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Types::Standard qw/Bool Str Maybe/; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use MooseX::AttributeShortcuts; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use HTML::Entities 'encode_entities'; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 3 | has output_also_as_html => ( | |||||||||||||||||||||||||||||||
| 19 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 20 | isa => Bool, | ||||||||||||||||||||||||||||||||
| 21 | default => 0, | ||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||
| 23 | 3 | has separator => ( | |||||||||||||||||||||||||||||||
| 24 | is => 'ro', | ||||||||||||||||||||||||||||||||
| 25 | isa => Maybe[Str], | ||||||||||||||||||||||||||||||||
| 26 | predicate => 1, | ||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | sub transform { | ||||||||||||||||||||||||||||||||
| 31 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
transform: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 32 | 3 | my $transform_args = shift; | |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 3 | my @out = $self->init_out($self->stenciller, $transform_args); | |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||
| 36 | STENCIL: | ||||||||||||||||||||||||||||||||
| 37 | 3 | for my $i (0 .. $self->stenciller->max_stencil_index) { | |||||||||||||||||||||||||||||||
| 38 | 7 | ▶ | next STENCIL if $self->should_skip_stencil_by_index($i, $transform_args); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||
| 40 | 6 | my $stencil = $self->stenciller->get_stencil($i); | |||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | next STENCIL if $self->should_skip_stencil($stencil, $transform_args); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 5 | ▶ | push @out => $self->normal($stencil->all_before_input), | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$self->has_separator and $i < $self->stenciller->max_stencil_index
MC/DC100%2/2
$self->has_separator and $i < $self->stenciller->max_stencil_index
$self->has_separator
$i < $self->stenciller->max_stencil_index
Truth table100%3/3
A and B
A= $self->has_separatorB= $i < $self->stenciller->max_stencil_index
| |||||||||||||||||||||||||||||||||
| 44 | $self->pre($stencil->all_input), | ||||||||||||||||||||||||||||||||
| 45 | $self->normal($stencil->all_between), | ||||||||||||||||||||||||||||||||
| 46 | $self->pre($stencil->all_output), | ||||||||||||||||||||||||||||||||
| 47 | $self->output_also_as_html ? $self->normal([$stencil->all_output]) : (), | ||||||||||||||||||||||||||||||||
| 48 | $self->normal($stencil->all_after_output), | ||||||||||||||||||||||||||||||||
| 49 | $self->has_separator && $i < $self->stenciller->max_stencil_index ? $self->separator : (); | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | 3 | return join "\n" => @out; | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | sub normal { | ||||||||||||||||||||||||||||||||
| 56 | 17 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
normal: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 57 | 17 | my @lines = @_; | |||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | 17 | ▶ | return () if !scalar @lines; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 60 | 12 | my $tag = 'p'; | |||||||||||||||||||||||||||||||
| 61 | 12 | ▶ | if(ref $lines[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 2 | $tag = 'div'; | |||||||||||||||||||||||||||||||
| 63 | 2 | @lines = @{ $lines[0] }; | |||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||
| 65 | 12 | return join '' => ("<$tag>", join ('' => @lines), "</$tag>"); | |||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||
| 67 | sub pre { | ||||||||||||||||||||||||||||||||
| 68 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
pre: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 69 | 10 | my @lines = @_; | |||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 10 | my @encoded_lines = map { $_ =~ s{^ {4}}{}; encode_entities($_) } @lines; | |||||||||||||||||||||||||||||||
| 72 | 10 | return join '' => ('<pre>', join ("\n" => @encoded_lines), '</pre>'); | |||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | 3 | 1; | |||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | __END__ | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =pod | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | Stenciller::Plugin::ToHtmlPreBlock - A plugin that transforms to html | ||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||
| 87 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | Version 0.1302, released 2015-11-28. | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||
| 93 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||
| 95 | use Stenciller; | ||||||||||||||||||||||||||||||||
| 96 | my $stenciller = Stenciller->new(filepath => 't/corpus/test-1.stencil'); | ||||||||||||||||||||||||||||||||
| 97 | my $content = $stenciller->transform('ToHtmlPreBlock'); | ||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||
| 99 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||
| 101 | 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. | ||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||
| 103 | Content that will be placed in C<pre> tags (input and output sections in stencils) also have four leading spaces removed. | ||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||
| 105 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||
| 107 | =head2 output_also_as_html | ||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||
| 109 | Default: C<0> | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | If set to a true value, the contents of C<output> in stencils is rendered as html (directly following the pre-block). | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | =head2 separator | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | Default: C<undef> | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | When set, this text is used to separate two stencils. | ||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | =head2 transform | ||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||
| 123 | See L<transform|Stenciller::Transformer/"transform"> in L<Stenciller::Transformer>. | ||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||
| 125 | =head1 SOURCE | ||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||
| 127 | L<https://github.com/Csson/p5-Stenciller> | ||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | =head1 HOMEPAGE | ||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||
| 131 | L<https://metacpan.org/release/Stenciller> | ||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||
| 133 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||
| 135 | Erik Carlsson <info@code301.com> | ||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||
| 137 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | This software is copyright (c) 2015 by Erik Carlsson. | ||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||
| 141 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||
| 142 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | =cut | ||||||||||||||||||||||||||||||||