RT# 81961 Move POD to HTML code into FS::Misc::Pod2Html module
[freeside.git] / FS / FS / Misc / Pod2Html.pm
1 package FS::Misc::Pod2Html;
2 use strict;
3 use warnings;
4 use Carp qw( croak );
5 use Pod::Simple::HTML;
6 use Pod::Simple::HTMLBatch;
7 use Pod::Simple::Search;
8
9 use base 'Exporter';
10 our @EXPORT_OK = qw(
11   fs_pod2html
12   $include_system_perl_modules
13   $quiet_mode
14 );
15
16 our $include_system_perl_modules = 1;
17 our $quiet_mode = 0;
18
19 =head1 NAME
20
21 FS::Misc::Pod2Html
22
23 =head1 DESCRIPTION
24
25 Generate HTML from POD Documentation
26
27 =head1 SYNOPSIS
28
29 Usage:
30
31   use FS::Misc::Pod2Html 'fs_pod2html';
32   fs_pod2html( '/output/directory' );
33
34 =head2 fs_pod2html /output/directory/
35
36 Generates Freeside-themed HTML docuemtnation from installed perl modules
37
38 =cut
39
40 our $html_before_title = q{
41   <% include( '/elements/header.html', 'Developer Documentation' ) %>
42   <& /elements/menubar.html,
43     'Freeside Perl Modules' => $fsurl.'docs/library/FS.html',
44     'Complete Index' => $fsurl.'docs/library/index.html',
45   &>
46
47   <div style="width: 90%; margin: 1em auto; font-size: .9em; border: solid 1px #666; background-color: #eee; padding: 1em;">
48   <h1 style="margin: .5em; border-bottom: solid 1px #999;">
49 };
50
51 our $html_after_title = q{</h1>};
52
53 our $html_footer = q{</div><% include ('/elements/footer.html' ) %>};
54
55 sub fs_pod2html {
56   my $html_dir = shift
57     or croak 'Please specify an output directory';
58
59   croak "Directory $html_dir: No write access"
60     unless -w $html_dir;
61
62   my @search_dirs = (
63     '/usr/local/share/perl/5.24.1',
64     '/usr/local/bin',
65     $include_system_perl_modules ? (
66       '/usr/share/perl5',
67       '/usr/share/perl/5.24',
68       '/usr/share/perl/5.24.1',
69     ) : (),
70   );
71
72   my $parser = Pod::Simple::HTMLBatch->new;
73
74   $parser->verbose(0)
75     if $quiet_mode;
76
77   $parser->search_class('Inline::Pod::Simple::Search');
78   $parser->html_render_class('Inline::Pod::Simple::HTML');
79   $parser->contents_page_start(
80     "$html_before_title Freeside Documentation Index $html_after_title"
81   );
82   $parser->contents_page_end( $html_footer );
83
84   $parser->batch_convert( \@search_dirs, $html_dir );
85 }
86
87 1;
88
89 =head1 NAME
90
91 Inline::Pod::Simple::Search
92
93 =head2 DESCRIPTION
94
95 Subclass of Pod::Simple::Search
96
97 Enable searching for POD in all files instead of just .pl and .pm
98
99 =cut
100
101 package Inline::Pod::Simple::Search;
102 use base 'Pod::Simple::Search';
103
104 sub new {
105   my $class = shift;
106   my $self = Pod::Simple::Search->new( @_ );
107   $self->laborious(1);
108   $self;
109 }
110 1;
111
112 =head1 NAME
113
114 Inline::Pod::Simple::HTML
115
116 =head2 DESCRIPTION
117
118 Subclass of Pod::Simple::HTML
119
120 Customize parsed HTML output
121
122 =cut
123
124 # Subclass Pod::Simple::HTML to control HTML output
125 package Inline::Pod::Simple::HTML;
126 use base 'Pod::Simple::HTML';
127
128 sub html_header_before_title { $html_before_title }
129 sub html_header_after_title { $html_after_title }
130 sub html_footer { $html_footer }
131
132 1;