| blib/lib/App/Pods2Site/SiteBuilder/BasicFramesTreeTOC.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 76 | 82 | 92.6 |
| branch | 22 | 26 | 84.6 |
| condition | n/a | ||
| subroutine | 8 | 8 | 100.0 |
| pod | 0 | 1 | 0.0 |
| total | 106 | 117 | 90.6 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package App::Pods2Site::SiteBuilder::BasicFramesTreeTOC; | ||||||
| 2 | |||||||
| 3 | 2 | 2 | 12 | use strict; | |||
| 2 | 4 | ||||||
| 2 | 50 | ||||||
| 4 | 2 | 2 | 10 | use warnings; | |||
| 2 | 3 | ||||||
| 2 | 109 | ||||||
| 5 | |||||||
| 6 | our $VERSION = '1.003'; | ||||||
| 7 | my $version = $VERSION; | ||||||
| 8 | $VERSION = eval $VERSION; | ||||||
| 9 | |||||||
| 10 | 2 | 2 | 10 | use base qw(App::Pods2Site::SiteBuilder::AbstractBasicFrames); | |||
| 2 | 11 | ||||||
| 2 | 294 | ||||||
| 11 | |||||||
| 12 | 2 | 2 | 12 | use App::Pods2Site::Util qw(slashify readUTF8File writeUTF8File); | |||
| 2 | 4 | ||||||
| 2 | 1630 | ||||||
| 13 | |||||||
| 14 | sub new | ||||||
| 15 | { | ||||||
| 16 | 3 | 3 | 0 | 7 | my $class = shift; | ||
| 17 | |||||||
| 18 | 3 | 47 | my $self = $class->SUPER::new(@_); | ||||
| 19 | 3 | 9 | $self->{maxtocdepth} = -1; | ||||
| 20 | |||||||
| 21 | 3 | 12 | return $self; | ||||
| 22 | } | ||||||
| 23 | |||||||
| 24 | sub _getCategoryTOC | ||||||
| 25 | { | ||||||
| 26 | 6 | 6 | 12 | my $self = shift; | |||
| 27 | 6 | 7 | my $groupName = shift; | ||||
| 28 | 6 | 11 | my $podInfo = shift; | ||||
| 29 | 6 | 7 | my $sitedir = shift; | ||||
| 30 | |||||||
| 31 | 6 | 20 | my $toc = ''; | ||||
| 32 | 6 | 10 | my %tree; | ||||
| 33 | 6 | 42 | foreach my $podName (sort(keys(%$podInfo))) | ||||
| 34 | { | ||||||
| 35 | 10 | 21 | my $treeloc = \%tree; | ||||
| 36 | 10 | 35 | for my $level (split(/::/, $podName)) | ||||
| 37 | { | ||||||
| 38 | 12 | 100 | 55 | $treeloc->{$level} = {} unless exists($treeloc->{$level}); | |||
| 39 | 12 | 32 | $treeloc = $treeloc->{$level}; | ||||
| 40 | } | ||||||
| 41 | } | ||||||
| 42 | 6 | 44 | $self->_genRefs($sitedir, \$toc, $podInfo, \%tree, -1); | ||||
| 43 | 6 | 12 | chomp($toc); | ||||
| 44 | 6 | 50 | 15 | if ($toc) | |||
| 45 | { | ||||||
| 46 | 6 | 50 | 16 | if ($groupName) | |||
| 47 | { | ||||||
| 48 | 6 | 34 | $toc = qq( \n\t\t\t \n); $groupName\n\t\t\t\t$toc\n\t\t |
||||
| 49 | } | ||||||
| 50 | else | ||||||
| 51 | { | ||||||
| 52 | 0 | 0 | my $newtoc = ''; | ||||
| 53 | 0 | 0 | while ($toc =~ /class="toc-(top|\d+)"/g) | ||||
| 54 | { | ||||||
| 55 | 0 | 0 | 0 | my $lvl = ($1 == 0) ? 'top' : $1 - 1; | |||
| 56 | 0 | 0 | $newtoc .= substr( $toc, 0, $-[0] ) . qq(class="toc-$lvl"); | ||||
| 57 | 0 | 0 | $toc = substr( $toc, $+[0] ); | ||||
| 58 | } | ||||||
| 59 | 0 | 0 | $toc = "$newtoc$toc"; | ||||
| 60 | } | ||||||
| 61 | } | ||||||
| 62 | |||||||
| 63 | 6 | 26 | return $toc; | ||||
| 64 | } | ||||||
| 65 | |||||||
| 66 | sub _genRefs | ||||||
| 67 | { | ||||||
| 68 | 17 | 17 | 28 | my $self = shift; | |||
| 69 | 17 | 24 | my $sitedir = shift; | ||||
| 70 | 17 | 21 | my $ref = shift; | ||||
| 71 | 17 | 21 | my $podInfo = shift; | ||||
| 72 | 17 | 21 | my $treeloc = shift; | ||||
| 73 | 17 | 19 | my $depth = shift; | ||||
| 74 | 17 | 34 | my $n = shift; | ||||
| 75 | 17 | 25 | my $np = shift; | ||||
| 76 | |||||||
| 77 | 17 | 100 | 37 | $self->{maxtocdepth} = $depth if $depth > $self->{maxtocdepth}; | |||
| 78 | |||||||
| 79 | 17 | 100 | 46 | my $hasSubNodes = keys(%$treeloc) ? 1 : 0; | |||
| 80 | |||||||
| 81 | 17 | 34 | my $r = ''; | ||||
| 82 | 17 | 100 | 35 | if ($n) | |||
| 83 | { | ||||||
| 84 | 11 | 25 | $r = "${n}::"; | ||||
| 85 | |||||||
| 86 | 11 | 100 | 22 | $$ref .= qq( \n) if $hasSubNodes; |
|||
| 87 | |||||||
| 88 | 11 | 100 | 32 | $$ref .= ($hasSubNodes ? qq( )); |
|||
| 89 | 11 | 29 | my $p = $podInfo->{$n}->{htmlfile}; | ||||
| 90 | 11 | 100 | 27 | if ($p) | |||
| 91 | { | ||||||
| 92 | 10 | 89 | $p =~ s#\Q$sitedir\E.##; | ||||
| 93 | 10 | 33 | $p = slashify($p, '/'); | ||||
| 94 | 10 | 31 | $$ref .= qq($np); | ||||
| 95 | } | ||||||
| 96 | else | ||||||
| 97 | { | ||||||
| 98 | 1 | 3 | $$ref .= qq($np); | ||||
| 99 | } | ||||||
| 100 | 11 | 100 | 30 | $$ref .= ($hasSubNodes ? qq() : qq()); | |||
| 101 | 11 | 21 | $$ref .= "\n"; | ||||
| 102 | } | ||||||
| 103 | |||||||
| 104 | 17 | 77 | foreach my $subnp (sort { lc($a) cmp lc($b) } (keys(%$treeloc))) | ||||
| 3 | 26 | ||||||
| 105 | { | ||||||
| 106 | 11 | 92 | my $subn = "$r$subnp"; | ||||
| 107 | |||||||
| 108 | 11 | 17 | $depth++; | ||||
| 109 | 11 | 42 | $self->_genRefs($sitedir, $ref, $podInfo, $treeloc->{$subnp}, $depth, $subn, $subnp); | ||||
| 110 | 11 | 13 | $depth--; | ||||
| 111 | } | ||||||
| 112 | |||||||
| 113 | 17 | 100 | 39 | if ($n) | |||
| 114 | { | ||||||
| 115 | 11 | 100 | 27 | $$ref .= qq(\n) if $hasSubNodes; | |||
| 116 | } | ||||||
| 117 | } | ||||||
| 118 | |||||||
| 119 | sub _rewriteCss | ||||||
| 120 | { | ||||||
| 121 | 3 | 3 | 6 | my $self = shift; | |||
| 122 | 3 | 6 | my $args = shift; | ||||
| 123 | |||||||
| 124 | 3 | 11 | my $tocrules = < | ||||
| 125 | summary.toc-top | ||||||
| 126 | { | ||||||
| 127 | font-weight: bolder; | ||||||
| 128 | } | ||||||
| 129 | |||||||
| 130 | TOCTOPRULES | ||||||
| 131 | |||||||
| 132 | 3 | 33 | for my $num (0 .. $self->{maxtocdepth}) | ||||
| 133 | { | ||||||
| 134 | 5 | 16 | my $sumem = $num + 1; | ||||
| 135 | 5 | 8 | my $divem = $num + 2; | ||||
| 136 | 5 | 21 | $tocrules .= < | ||||
| 137 | summary.toc-$num | ||||||
| 138 | { | ||||||
| 139 | font-size: small; | ||||||
| 140 | margin-left: ${sumem}em; | ||||||
| 141 | } | ||||||
| 142 | |||||||
| 143 | div.toc-$num | ||||||
| 144 | { | ||||||
| 145 | font-size: small; | ||||||
| 146 | margin-left: ${divem}em; | ||||||
| 147 | } | ||||||
| 148 | |||||||
| 149 | TOCNUMRULES | ||||||
| 150 | } | ||||||
| 151 | |||||||
| 152 | 3 | 12 | my $sitedir = $args->getSiteDir(); | ||||
| 153 | 3 | 10 | my $sbName = $self->getStyleName(); | ||||
| 154 | 3 | 12 | my $sbCssFile = slashify("$sitedir/$sbName.css"); | ||||
| 155 | 3 | 52 | my $cssContent = readUTF8File($sbCssFile); | ||||
| 156 | 3 | 25 | writeUTF8File($sbCssFile, "$cssContent\n$tocrules"); | ||||
| 157 | } | ||||||
| 158 | |||||||
| 159 | 1; |