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