ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/ermyth/doc/lib/PodHTML.pm
Revision: 1.6
Committed: Sun Sep 16 18:54:42 2007 UTC (19 years ago) by pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +2 -2 lines
Log Message:
#defines to enum

File Contents

# User Rev Content
1 pippijn 1.1 package PodHTML;
2    
3     use strict;
4     use warnings;
5     use utf8;
6    
7 pippijn 1.6 my $rcsid = '$Id: PodHTML.pm,v 1.5 2007-08-28 17:08:06 pippijn Exp $';
8 pippijn 1.2
9 pippijn 1.1 use base "Pod::POM::View";
10    
11     our $subdir;
12     our $dir;
13     our $menu;
14    
15     sub view_pod {
16     my ($self, $item) = @_;
17     $item->content->present ($self)
18     }
19    
20     sub view_head1 {
21     my ($self, $item) = @_;
22     my $file;
23     if ($item->title =~ /\|/) {
24     my @cmds = split /\|/, $item->title;
25     for my $cmd (@cmds) {
26     my $content = "$cmd\n\n" . $item->content->present ($self);
27     $content =~ s/\$CMD/$cmd/g;
28     $file = "$dir/$subdir/" . lc $cmd . ".tt";
29     $file =~ s/ /_/g;
30     open my $fh, ">", $file;
31     print $fh $content;
32     close $fh;
33     }
34     } else {
35     if ($subdir) {
36     $file = "$dir/$subdir/" . lc $item->title . ".tt";
37     } else {
38     $file = "$dir/" . lc $item->title . ".tt";
39     }
40     $file =~ s/ /_/g;
41     open my $fh, ">", $file;
42     my $content = $item->title->present ($self) . "\n\n" . $item->content->present ($self);
43     print $fh $content;
44     close $fh;
45     }
46     my $name = $file;
47     $name =~ s/$dir\/\w+\/(.+)\.tt/$1/;
48     $name =~ s/_/ /g;
49     my $svs;
50     if ($subdir) {
51     $svs = $subdir;
52     } else {
53     $svs = $dir;
54     }
55     $svs =~ s/serv/Serv/;
56     $svs = ucfirst $svs;
57     $file =~ s/$dir/../;
58     $file =~ s/\.tt$//;
59     $menu->{$svs}->[($#{$menu->{$svs}}) + 1] = {
60     href => "$file.html",
61     title => uc $name,
62     };
63     }
64    
65     sub view_head2 {
66     my ($self, $item) = @_;
67     '<h3>',
68     $item->title->present ($self),
69     "</h3>",
70     $item->content->present ($self);
71     }
72    
73     sub view_head3 {
74     my ($self, $item) = @_;
75     '<h4>',
76     $item->title->present ($self),
77     "</h4>",
78     $item->content->present ($self);
79     }
80    
81 pippijn 1.5 sub view_head4 {
82     my ($self, $item) = @_;
83     '<h5>',
84     $item->title->present ($self),
85     "</h5>",
86     $item->content->present ($self);
87     }
88    
89 pippijn 1.1 sub view_seq_entity {
90     my ($self, $item) = @_;
91     $item =~ /^x/
92     ? ('&#', $item, ';')
93     : ('&', $item, ';')
94     }
95    
96 pippijn 1.5 sub view_seq_code { "<span class='code'>$_[1]</span>" }
97 pippijn 1.2 sub view_seq_file { "<i>$_[1]</i>" }
98 pippijn 1.1 sub view_seq_bold { "<b>$_[1]</b>" }
99     sub view_seq_link { my $href = lc $_[1]; "<a href='$href.html'>$_[1]</a>" }
100     sub view_seq_link_top {
101     my ($title, $href) = split /\|/, $_[1], 2;
102     "<a href='$href'>$title</a>"
103     }
104    
105     sub view_verbatim {
106     my ($self, $item) = @_;
107 pippijn 1.5 $self->xmlise (\$item);
108 pippijn 1.1 "<pre>\n$item</pre>"
109     }
110    
111     sub view_over {
112     my ($self, $item) = @_;
113     "<ul>\n",
114     $item->content->present ($self),
115     "</ul>\n"
116     }
117    
118     sub view_item {
119     my ($self, $item) = @_;
120     my $title;
121     if ($item->title =~ /^L</) {
122     $title = $item->title;
123     $title =~ s/L<(.+)>/- $1/;
124 pippijn 1.5 $self->xmlise (\$title);
125 pippijn 1.1 $title = $self->view_seq_link_top ($title);
126     } else {
127     $title = $item->title;
128 pippijn 1.5 $self->xmlise (\$title);
129 pippijn 1.1 }
130    
131 pippijn 1.5 '<li>', ($item->title eq '*' ? '<b>( * )</b> ' : '<b>' . $title . '</b> '), $item->content->present ($self), "</li>\n"
132 pippijn 1.1 }
133    
134     sub view_textblock { "<p>$_[1]</p>" }
135     sub view_seq_index { "&lt;$_[1]&gt;" }
136     sub view_seq_space { "[$_[1]]" }
137    
138     sub view_for {
139     my ($self, $item) = @_;
140     my $format = $item->format;
141     my $text = $item->text;
142     $text =~ s/X<([^>]+)>/&lt;$1&gt;/g;
143     $text =~ s/S<([^>]+)>/[$1]/g;
144    
145     "<blockquote><b>$format</b> $text</blockquote>"
146     }
147    
148     sub xmlise {
149     my ($self, $text) = @_;
150 pippijn 1.5 $$text =~ s/>/&gt;/;
151     $$text =~ s/</&lt;/;
152 pippijn 1.1
153 pippijn 1.5 $$text
154 pippijn 1.1 }
155    
156 pippijn 1.3 =head1 AUTHOR
157    
158     Copyright © 2007 Pippijn van Steenhoven
159    
160     =head1 LICENSE
161    
162     This library is free software, you can redistribute it and/or modify
163 pippijn 1.6 it under the terms of the GNU General Public License version 3 or later.
164 pippijn 1.3
165     =cut
166    
167     1