DocSet/Doc/POD2HTML.pm untested

filter: Statementstmt 0.0% 0 / 101 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 23 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 136 CC 3 SCAR 9.7
CC
3
Cov
0%
slice_by_head
6.0
view_seq_file
6.0
convert
2.0
CRAP 2.6
1 package DocSet::Doc::POD2HTML;
2  
3 use strict;
4 use warnings;
5  
6 use File::Spec::Functions;
7 use File::Basename ();
8  
9 use DocSet::Util;
10 use DocSet::RunTime;
11  
12 require Pod::POM;
13 my $view_mode = 'DocSet::Doc::POD2HTML::View::HTML';
14  
15 use DocSet::Doc::Common ();
16 *fetch_pdf_doc_ver = \&DocSet::Doc::Common::fetch_pdf_doc_ver;
17 *fetch_src_doc_ver = \&DocSet::Doc::Common::fetch_src_doc_ver;
18  
19 use vars qw(@ISA);
20 require DocSet::Source::POD;
21 @ISA = qw(DocSet::Source::POD);
22  
23 my %split_by = map {"head".$_ => 1} 1..4;
24  
25 sub convert {
26 my ($self) = @_;
27  
28 set_render_obj($self);
29  
30 my $pom = $self->{parsed_tree};
31  
32 my @sections = $pom->content();
33 shift @sections; # skip the title
34  
35 # my @body = ();
36 # foreach my $node (@sections) {
37 ## my $type = $node->type();
38 ## print "$type\n";
39 # push @body, $node->present($view_mode);
40 # }
41  
42
43 #dumper $sections[$#sections];
44  
45 my @body = slice_by_head(@sections);
46  
47 my $vars = {
48 meta => $self->{meta},
49 toc => $self->{toc},
50 body => \@body,
51 headers => {},
52 dir => $self->{dir},
53 nav => $self->{nav},
54 last_modified => $self->{timestamp},
55 pdf_doc => $self->fetch_pdf_doc_ver,
56 src_doc => $self->fetch_src_doc_ver,
57 };
58  
59 my $tmpl_file = 'page';
60 my $mode = $self->{tmpl_mode};
61 my $tmpl_root = $self->{tmpl_root};
62 $self->{output} = proc_tmpl($tmpl_root, $tmpl_file, $mode, {doc => $vars} );
63  
64 unset_render_obj();
65  
66 }
67  
68  
69 sub slice_by_head {
70 my @sections = @_;
71 my @body = ();
72 for my $node (@sections) {
73 my @next = ();
74 # assumption, after the first 'headX' section, there can only
75 # be other 'headX' sections
76 my $count = scalar $node->content;
77 my $id = -1;
78 for ($node->content) {
79 $id++;
80 next unless exists $split_by{ $_->type };
81 @next = splice @{$node->content}, $id;
82 last;
83 }
84 push @body, $node->present($view_mode), slice_by_head(@next);
85 }
86 return @body;
87 }
88  
89  
90 1;
91  
92  
93 package DocSet::Doc::POD2HTML::View::HTML;
94  
95 use vars qw(@ISA);
96 require Pod::POM::View::HTML;
97 @ISA = qw( Pod::POM::View::HTML);
98  
99 use DocSet::RunTime;
100  
101 use File::Spec::Functions;
102 use File::Basename;
103  
104 sub view_head1 {
105 my ($self, $head1) = @_;
106 return "<h1>" . $self->anchor($head1->title) . "</h1>\n\n" .
107 $head1->content->present($self);
108 }
109  
110 sub view_head2 {
111 my ($self, $head2) = @_;
112 return "<h2>" . $self->anchor($head2->title) . "</h2>\n\n" .
113 $head2->content->present($self);
114 }
115  
116 sub view_head3 {
117 my ($self, $head3) = @_;
118 return "<h3>" . $self->anchor($head3->title) . "</h3>\n\n" .
119 $head3->content->present($self);
120 }
121  
122 sub view_head4 {
123 my ($self, $head4) = @_;
124 return "<h4>" . $self->anchor($head4->title) . "</h4>\n\n" .
125 $head4->content->present($self);
126 }
127  
128 sub view_seq_file {
129 my ($self, $path) = @_;
130 my $doc_obj = get_render_obj();
131 my $base_dir = dirname catfile $doc_obj->{src_root}, $doc_obj->{src_uri};
132 my $file = catfile $base_dir, $path;
133 #warn "file: $file";
134  
135 # XXX: may need to test the location at dest_path, not src, to
136 # make sure that the file actually gets copied
137 return -e $file ? qq{<a href="$path">$path</a>} : qq{<i>$path</i>};
138 }
139  
140 # the <pre> section uses class "pre-section", which allows to use a custom
141 # look-n-feel via the CSS
142 sub view_verbatim {
143 my ($self, $text) = @_;
144 for ($text) {
145 s/&/&amp;/g;
146 s/</&lt;/g;
147 s/>/&gt;/g;
148 }
149  
150 return qq{<pre class="pre-section">$text</pre>\n};
151 }
152  
153  
154 #sub view_for {
155 # my $self = shift;
156 # my ($for) = @_;
157 # return $self->SUPER::view_for(@_) if $for->format() =~ /\bhtml\b/;
158 # if ($for->format() =~ /\btt2\b/) {
159 # my $text = $for->text();
160 #print "$text\n";
161 #return $text;
162 ## "WHOOOOOOOOOOOOOOOOOOOOOOO";
163 ## $self->parse_sequence($text);
164 # }
165 #}
166  
167 *anchor = \&DocSet::Doc::Common::pod_pom_html_anchor;
168 *view_seq_link_transform_path = \&DocSet::Doc::Common::pod_pom_html_view_seq_link_transform_path;
169  
170 #*view_seq_link = \&DocSet::Doc::Common::pod_pom_html_view_seq_link;
171  
172 #use DocSet::Util;
173 ## META: temp override
174 ## the one in superclass screws up URLs in L<>: L<http://foo.bar.com>
175 ## should view_seq_text be called at all on these parts?
176 #sub view_seq_text {
177 # my ($self, $text) = @_;
178 #dumper $self;
179 ##print $self->[CMD];
180 # return $text;
181 #}
182  
183 1;
184  
185  
186  
187 __END__