WE_Frontend/Plugin/HTMLFromText.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 66 CC 5 SCAR 26.1
CC
5
Cov
0%
out
30.0
new
2.0
fixeol
2.0
CRAP 13.7
1 # -*- perl -*-
2  
3 #
4 # $Id: HTMLFromText.pm,v 1.5 2004/01/12 16:21:32 eserte Exp $
5 # Author: Slaven Rezic
6 #
7 # Copyright (C) 2003 Slaven Rezic.
8 # This is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License, see the file COPYING.
10  
11 #
12 # Mail: slaven@rezic.de
13 # WWW: http://we-framework.sourceforge.net
14 #
15  
16 package WE_Frontend::Plugin::HTMLFromText;
17 use base qw(Template::Plugin);
18  
19 use HTML::Entities;
20 use HTML::FromText;
21  
22 use strict;
23 use vars qw($VERSION);
24 $VERSION = sprintf("%d.%02d", q$Revision: 1.5 $ =~ /(\d+)\.(\d+)/);
25  
26 sub fixeol ($);
27  
28 =head1 NAME
29  
30 WE_Frontend::Plugin::HTMLFromText - format a textual table description to HTML
31  
32 =head1 SYNOPSIS
33  
34 my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"});
35  
36 [% USE HTMLFromText %]
37 [% HTMLFromText.out(textdef) %]
38  
39 =head1 DESCRIPTION
40  
41 This plugin feeds the textdef object to L<HTML::FromText>. The B<opts>
42 member can be set a list of decorators and output modes.
43  
44 =head2 METHODS
45  
46 =over
47  
48 =cut
49  
50 sub new {
51 my($class, $context) = @_;
52 my $self = {Context => $context};
53 bless $self, $class;
54 }
55  
56 =item out($textdef)
57  
58 Format and output the given text definition.
59  
60 =cut
61  
62 sub out {
63 my($self, $textdef) = @_;
64 my $type = $textdef->{type};
65 if ($type ne "autoformattext") {
66 warn "Element type is `$type', expected `autoformattext'";
67 }
68 my $opts = $textdef->{opts}||"";
69 my $text = fixeol $textdef->{text};
70 my %std_opts = map {($_,1)} split /,/, "urls,email,bold,underline,paras,bullets,numbers,tables";
71 my %opts;
72 my @set_opts = split /,/, $opts;
73 if (!grep { /^[^\+\-]/ } @set_opts) {
74 %opts = %std_opts;
75 } else {
76 warn "Do not set options";
77 }
78 for my $opt_def (@set_opts) {
79 if ($opt_def =~ /^-(.*)/) {
80 delete $opts{$1};
81 } elsif ($opt_def =~ /^\+?(.*)/) {
82 $opts{$1} = 1;
83 }
84 }
85  
86 return text2html($text, %opts);
87 }
88  
89 sub fixeol ($) {
90 my $s = shift;
91 $s =~ s/\015//g;
92 $s;
93 }
94  
95 1;
96  
97 __END__