935ff11989172f7907c209e84f1fa9128af34b16
[freeside.git] / bin / pod2html.pl
1 #!/usr/bin/env perl
2
3 =head1 NAME
4
5 pod2html.pl
6
7 =head1 DESCRIPTION
8
9 Generate HTML from POD documentation
10
11 Search directories /usr/local/share/perl and /usr/local/bin
12
13 Output HTML to /var/www/html/freeside-doc
14
15 =cut
16
17 use strict;
18 use warnings;
19 use v5.10;
20
21 use Pod::Simple::Search;
22 use Pod::Simple::HTML;
23 use Pod::Simple::HTMLBatch;
24
25 # Disable this to only build docs for Freeside modules
26 # This will cause links to non-freeside packages to be broken,
27 # but save 30-60secs during build process
28 my $include_system_perl_modules = 1;
29
30
31 my $html_dir = shift @ARGV
32   or HELP_MESSAGE('Please specify an OUTPUT_DIRECTORY');
33
34 HELP_MESSAGE("Directory $html_dir: No write access!")
35   unless -w $html_dir;
36
37
38 my $parser = Pod::Simple::HTMLBatch->new;
39
40 # Uncomment to suppress status output to STDIN
41 # $parser->verbose(0);
42
43 $parser->search_class('Inline::Pod::Simple::Search');
44 $parser->html_render_class('Inline::Pod::Simple::HTML');
45
46 # Customized HTML output
47 our $html_before_title = q{
48   <% include( '/elements/header.html', 'Developer Documentation' ) %>
49   <& /elements/menubar.html,
50     'Freeside Perl Modules' => $fsurl.'docs/library/FS.html',
51     'Complete Index' => $fsurl.'docs/library/index.html',
52   &>
53
54   <div style="width: 90%; margin: 1em auto; font-size: .9em; border: solid 1px #666; background-color: #eee; padding: 1em;">
55   <h1 style="margin: .5em; border-bottom: solid 1px #999;">
56 };
57 our $html_after_title = q{</h1>};
58 our $html_footer = q{</div><% include ('/elements/footer.html' ) %>};
59
60 $parser->contents_page_start(
61   "$html_before_title Freeside Documentation Index $html_after_title"
62 );
63 $parser->contents_page_end( $html_footer );
64
65 my @search_dirs = (
66   '/usr/local/share/perl/5.24.1',
67   '/usr/local/bin',
68   $include_system_perl_modules ? (
69     '/usr/share/perl5',
70     '/usr/share/perl/5.24',
71     '/usr/share/perl/5.24.1',
72   ) : (),
73 );
74
75 $parser->batch_convert( \@search_dirs, $html_dir );
76
77 sub HELP_MESSAGE {
78   my $error = shift;
79   print " ERROR: $error \n"
80     if $error;
81   print "
82     Tool to generate HTML from Freeside POD documentation
83
84     Usage: pod2html.pl OUTPUT_DIRECTORY
85
86   ";
87   exit;
88 }
89
90
91
92 # Subclass Pod::Simple::Search to render POD from files without
93 # normal perl extensions like PL and PM
94 package Inline::Pod::Simple::Search;
95 use base 'Pod::Simple::Search';
96
97 sub new {
98   my $class = shift;
99   my $self = Pod::Simple::Search->new( @_ );
100   $self->laborious(1);
101   $self;
102 }
103 1;
104
105
106 # Subclass Pod::Simple::HTML to control HTML output
107 package Inline::Pod::Simple::HTML;
108 use base 'Pod::Simple::HTML';
109
110 sub html_header_before_title { $html_before_title }
111 sub html_header_after_title { $html_after_title }
112 sub html_footer { $html_footer }
113
114 1;