Upgrade 4.0.17 clean.
[usit-rt.git] / lib / RT / Pod / HTMLBatch.pm
CommitLineData
403d7b0b
MKG
1# BEGIN BPS TAGGED BLOCK {{{
2#
3# COPYRIGHT:
4#
5# This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
6# <sales@bestpractical.com>
7#
8# (Except where explicitly superseded by other copyright notices)
9#
10#
11# LICENSE:
12#
13# This work is made available to you under the terms of Version 2 of
14# the GNU General Public License. A copy of that license should have
15# been provided with this software, but in any event can be snarfed
16# from www.gnu.org.
17#
18# This work is distributed in the hope that it will be useful, but
19# WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21# General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26# 02110-1301 or visit their web page on the internet at
27# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
28#
29#
30# CONTRIBUTION SUBMISSION POLICY:
31#
32# (The following paragraph is not intended to limit the rights granted
33# to you to modify and distribute this software under the terms of
34# the GNU General Public License and is only of importance to you if
35# you choose to contribute your changes and enhancements to the
36# community by submitting them to Best Practical Solutions, LLC.)
37#
38# By intentionally submitting any modifications, corrections or
39# derivatives to this work, or any other work intended for use with
40# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41# you are the copyright holder for those contributions and you grant
42# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
43# royalty-free, perpetual, license to use, copy, create derivative
44# works based on those contributions, and sublicense and distribute
45# those contributions and any derivatives thereof.
46#
47# END BPS TAGGED BLOCK }}}
48
dab09ea8
MKG
49use strict;
50use warnings;
51
52package RT::Pod::HTMLBatch;
53use base 'Pod::Simple::HTMLBatch';
54
55use List::MoreUtils qw/all/;
56
57use RT::Pod::Search;
58use RT::Pod::HTML;
59
01e3b242
MKG
60my $MOD2PATH;
61
dab09ea8
MKG
62sub new {
63 my $self = shift->SUPER::new(@_);
64 $self->verbose(0);
65
66 # Per-page output options
67 $self->css_flurry(0); # No CSS
68 $self->javascript_flurry(0); # No JS
69 $self->no_contents_links(1); # No header/footer "Back to contents" links
70
71 # TOC options
72 $self->index(1); # Write a per-page TOC
73 $self->contents_file("index.html"); # Write a global TOC
74
75 $self->html_render_class('RT::Pod::HTML');
76 $self->search_class('RT::Pod::Search');
77
78 return $self;
79}
80
81sub classify {
82 my $self = shift;
83 my %info = (@_);
84
85 my $is_install_doc = sub {
86 my %page = @_;
87 local $_ = $page{name};
88 return 1 if /^(README|UPGRADING)/;
01e3b242 89 return 1 if /^RT\w*?_Config$/;
dab09ea8
MKG
90 return 1 if $_ eq "web_deployment";
91 return 1 if $page{infile} =~ m{^configure(\.ac)?$};
92 return 0;
93 };
94
95 my $section = $info{infile} =~ m{/plugins/([^/]+)} ? "05 Extension: $1" :
96 $info{infile} =~ m{/local/} ? '04 Local Documenation' :
97 $is_install_doc->(%info) ? '00 Install and Upgrade '.
98 'Documentation' :
99 $info{infile} =~ m{/(docs|etc)/} ? '01 User Documentation' :
100 $info{infile} =~ m{/bin/} ? '02 Utilities (bin)' :
101 $info{infile} =~ m{/sbin/} ? '03 Utilities (sbin)' :
102 $info{name} =~ /^RT::Action/ ? '08 Actions' :
103 $info{name} =~ /^RT::Condition/ ? '09 Conditions' :
104 $info{name} =~ /^RT(::|$)/ ? '07 Developer Documentation' :
105 $info{infile} =~ m{/devel/tools/} ? '20 Utilities (devel/tools)' :
106 '06 Miscellaneous' ;
107
108 if ($info{infile} =~ m{/(docs|etc)/}) {
109 $info{name} =~ s/_/ /g;
110 $info{name} = join "/", map { ucfirst } split /::/, $info{name};
111 }
112
113 return ($info{name}, $section);
114}
115
116sub write_contents_file {
117 my ($self, $to) = @_;
118 return unless $self->contents_file;
119
120 my $file = join "/", $to, $self->contents_file;
121 open my $index, ">", $file
122 or warn "Unable to open index file '$file': $!\n", return;
123
124 my $pages = $self->_contents;
125 return unless @$pages;
126
127 # Classify
128 my %toc;
129 for my $page (@$pages) {
130 my ($name, $infile, $outfile, $pieces) = @$page;
131
132 my ($title, $section) = $self->classify(
133 name => $name,
134 infile => $infile,
135 );
136
137 (my $path = $outfile) =~ s{^\Q$to\E/?}{};
138
139 push @{ $toc{$section} }, {
140 name => $title,
141 path => $path,
142 };
143 }
144
145 # Write out index
146 print $index "<dl class='superindex'>\n";
147
148 for my $key (sort keys %toc) {
149 next unless @{ $toc{$key} };
150
151 (my $section = $key) =~ s/^\d+ //;
152 print $index "<dt>", esc($section), "</dt>\n";
153 print $index "<dd>\n";
154
155 my @sorted = sort {
156 my @names = map { $_->{name} } $a, $b;
157
158 # Sort just the upgrading docs descending within everything else
159 @names = reverse @names
160 if all { /^UPGRADING-/ } @names;
161
162 $names[0] cmp $names[1]
163 } @{ $toc{$key} };
164
165 for my $page (@sorted) {
166 print $index " <a href='", esc($page->{path}), "'>",
167 esc($page->{name}),
168 "</a><br>\n";
169 }
170 print $index "</dd>\n";
171 }
172 print $index '</dl>';
173
174 close $index;
175}
176
177sub esc {
178 Pod::Simple::HTMLBatch::esc(@_);
179}
180
01e3b242
MKG
181sub find_all_pods {
182 my $self = shift;
183 $MOD2PATH = $self->SUPER::find_all_pods(@_);
184 return $MOD2PATH;
185}
186
187sub found {
188 my ($self, $module) = @_;
189 return(exists $MOD2PATH->{$module} and defined $MOD2PATH->{$module});
190}
191
dab09ea8 1921;