WE_Frontend/Plugin/TextTable.pm

filter: Statementstmt 14.8% 14 / 94 Branchbran 0.0% 0 / 36 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 50.0% 4 / 8 Podpod 50.0% 2 / 4 totaltotal 12.2% 20 / 163 CC 26 SCAR 54.4
CC
26
Cov
10%
out
380.0
parse_align
56.0
fixeol
6.0
CRAP 231.2
« WE_Frontend/Publish/FTP.pm ↑ Summary WE/Util/Htaccess.pm »
1 # -*- perl -*-
2  
3 #
4 # $Id: TextTable.pm,v 1.10 2004/02/06 16:51:08 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::TextTable;
17 1 ▶use base qw(Template::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 $VERSION = sprintf("%d.%02d", q$Revision: 1.10 $ =~ /(\d+)\.(\d+)/);
24  
25 sub fixeol ($);
26  
27 =head1 NAME
28  
29 WE_Frontend::Plugin::TextTable - format a textual table description to HTML
30  
31 =head1 SYNOPSIS
32  
33 my $t = Template->new({PLUGIN_BASE => "WE_Frontend::Plugin"});
34  
35 [% USE TextTable %]
36 [% TextTable.out(tabledef) %]
37  
38 =head1 DESCRIPTION
39  
40 Format a textual table description into HTML. See also the "table"
41 definitions in F<we_contentlist_templates.tpl.js> in the web.editor
42 distribution.
43  
44 =head2 METHODS
45  
46 =over
47  
48 =cut
49  
50 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
51 0 my($class, $context) = @_;
52 0 my $self = {Context => $context};
53 0 bless $self, $class;
54 }
55  
56 =item out($tabledef)
57  
58 Format and output the given table definition.
59  
60 =cut
61  
62 0 ▶sub out {
Subroutine out: not called CC=19 SCAR=59.4
Pod documented
63 0 my($self, $tabledef) = @_;
64 0 my $type = $tabledef->{type};
65 0 ▶ if ($type ne "table") {
Branch: 1 branch
BranchTrueFalseTotal
if ($type ne "table") 0 0 0
66 0 warn "Element type is `$type', expected `table'";
67 }
68 0 my $title = fixeol $tabledef->{title};
69 0 my $css = fixeol $tabledef->{css};
70 0 my $sep = quotemeta fixeol $tabledef->{sep};
71 0 my $head = fixeol $tabledef->{tablehead};
72 0 my $head_align = fixeol $tabledef->{tablehead_align};
73 0 my $head_is_html = $tabledef->{tablehead_ishtml};
74 0 my $subhead = fixeol $tabledef->{tablesubhead};
75 0 my $subhead_align = fixeol $tabledef->{tablesubhead_align};
76 0 my $subhead_is_html = $tabledef->{tablesubhead_ishtml};
77 0 my $text_align = fixeol $tabledef->{tabletext_align};
78 0 my $text = fixeol $tabledef->{tabletext};
79 0 my @rows = split /\n/, $text;
80 0 my $out = "<table";
81 0 ▶ if (defined $css && $css ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $css and $css ne "") 0 0 0
Condition0%0/3
defined $css and $css ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $css and $css ne ""
defined $css $css ne ""
Truth table0%0/3
A and B
A= defined $cssB= $css ne ""
ABresult
0X0
100
111
82 0 $out .= " class='$css'";
83 }
84 0 $out .= ">\n";
85 0 ▶ if (defined $title && $title ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $title and $title ne "") 0 0 0
Condition0%0/3
defined $title and $title ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $title and $title ne ""
defined $title $title ne ""
Truth table0%0/3
A and B
A= defined $titleB= $title ne ""
ABresult
0X0
100
111
86 0 $out .= "<caption>" . HTML::Entities::encode($title) . "</caption>\n";
87 }
88 0 for my $def ([$head, $head_is_html, $head_align],
89 [$subhead, $subhead_is_html, $subhead_align]
90 ) {
91 0 my($h, $is_html, $align) = @$def;
92 0 ▶ $align = "" if !defined $align;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $align 0 0 0
93 my @style = map {
94 0 my $style = parse_align($_);
95 0 ▶ if ($style ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($style ne "") 0 0 0
96 0 $style = " style='" . $style . "'";
97 }
98 0 $style;
99 } split $sep, $align;
100  
101 0 ▶ if (defined $h && $h ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h and $h ne "") 0 0 0
Condition0%0/3
defined $h and $h ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $h and $h ne ""
defined $h $h ne ""
Truth table0%0/3
A and B
A= defined $hB= $h ne ""
ABresult
0X0
100
111
102 0 $out .= "<tr>";
103 0 ▶ if ($is_html) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_html) { } 0 0 0
104 0 $out .= $h;
105 } else {
106 0 my @cols = split $sep, $h;
107 0 my $col_i = 0;
108 0 ▶ $out .= join "", map { my $s = defined $_ ? $_ : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
109 0 ▶ my $style = $style[$col_i++] || "";
Condition0%0/2
$style[$col_i++] || ''
l!l
00
MC/DC0%0/1
$style[$col_i++] || ''
$style[$col_i++]
Truth table0%0/2
A
A= $style[$col_i++]
Aresult
11
00
110 0 "<th$style>" . HTML::Entities::encode($s) . "</th>" } @cols;
111 }
112 0 $out .= "</tr>\n";
113 }
114 }
115  
116 0 ▶ $text_align = "" if !defined $text_align;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text_align 0 0 0
117 my @td_style = map {
118 0 my $style = parse_align($_);
119 0 ▶ if ($style ne "") {
Branch: 1 branch
BranchTrueFalseTotal
if ($style ne "") 0 0 0
120 0 $style = " style='" . $style . "'";
121 }
122 0 $style;
123 } split $sep, $text_align;
124  
125 0 for my $row (@rows) {
126 0 $out .= "<tr>";
127 0 my @cols = split $sep, $row;
128 0 my $col_i = 0;
129 0 ▶ $out .= join "", map { my $s = defined $_ ? $_ : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
130 0 ▶ my $style = $td_style[$col_i++] || "";
Condition0%0/2
$td_style[$col_i++] || ''
l!l
00
MC/DC0%0/1
$td_style[$col_i++] || ''
$td_style[$col_i++]
Truth table0%0/2
A
A= $td_style[$col_i++]
Aresult
11
00
131 0 "<td$style>" . HTML::Entities::encode($s) . "</td>" } @cols;
132 0 $out .= "</tr>\n";
133 }
134 0 $out .= "</table>\n";
135  
136 0 return $out;
137 }
138  
139 0 ▶sub fixeol ($) {
Subroutine fixeol: not called CC=2 SCAR=17.9
Pod undocumented
140 0 my $s = shift;
141 0 ▶ return if !defined $s;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
142 0 $s =~ s/\015//g;
143 0 $s;
144 }
145  
146 0 ▶sub parse_align {
Subroutine parse_align: not called CC=7 SCAR=40.3
Pod undocumented
147 0 local $_ = shift;
148 0 my $style = "";
149 0 ▶ if (/[<l]/) { $style .= ' text-align:left;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[<l]/) 0 0 0
150 0 ▶ if (/[>r]/) { $style .= ' text-align:right;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[>r]/) 0 0 0
151 0 ▶ if (/[\|c]/) { $style .= ' text-align:center;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[\|c]/) 0 0 0
152 0 ▶ if (/[\^t]/) { $style .= ' vertical-align:top;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[\^t]/) 0 0 0
153 0 ▶ if (/[vb]/) { $style .= ' vertical-align:bottom;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[vb]/) 0 0 0
154 0 ▶ if (/[-m]/) { $style .= ' vertical-align:middle;' }
Branch: 1 branch
BranchTrueFalseTotal
if (/[-m]/) 0 0 0
155 0 $style;
156 }
157  
158 1 1;
159  
160 __END__
« WE_Frontend/Publish/FTP.pm ↑ Summary WE/Util/Htaccess.pm »