2 # BEGIN BPS TAGGED BLOCK {{{
6 # This software is Copyright (c) 1996-2013 Best Practical Solutions, LLC
7 # <sales@bestpractical.com>
9 # (Except where explicitly superseded by other copyright notices)
14 # This work is made available to you under the terms of Version 2 of
15 # the GNU General Public License. A copy of that license should have
16 # been provided with this software, but in any event can be snarfed
19 # This work is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 # 02110-1301 or visit their web page on the internet at
28 # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
31 # CONTRIBUTION SUBMISSION POLICY:
33 # (The following paragraph is not intended to limit the rights granted
34 # to you to modify and distribute this software under the terms of
35 # the GNU General Public License and is only of importance to you if
36 # you choose to contribute your changes and enhancements to the
37 # community by submitting them to Best Practical Solutions, LLC.)
39 # By intentionally submitting any modifications, corrections or
40 # derivatives to this work, or any other work intended for use with
41 # Request Tracker, to Best Practical Solutions, LLC, you confirm that
42 # you are the copyright holder for those contributions and you grant
43 # Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
44 # royalty-free, perpetual, license to use, copy, create derivative
45 # works based on those contributions, and sublicense and distribute
46 # those contributions and any derivatives thereof.
48 # END BPS TAGGED BLOCK }}}
55 use File::Path qw(make_path rmtree);
56 use File::Copy qw(copy);
57 use HTML::Entities qw(encode_entities);
58 use RT::Pod::HTMLBatch;
68 if ( $opts{'help'} ) {
70 print Pod::Usage::pod2usage( -verbose => 2 );
74 die "--to=DIRECTORY is required\n" unless $opts{to};
76 $opts{to} = File::Spec->rel2abs($opts{to});
78 make_path( $opts{to} ) unless -e $opts{to};
79 die "--to MUST be a directory\n" unless -d $opts{to};
81 # Unpack the tarball, if that's what we're given.
83 if (($opts{rt} || '') =~ /\.tar\.gz$/ and -f $opts{rt}) {
84 $tmpdir = File::Temp->newdir();
86 system("tar", "xzpf", $opts{rt}, "-C", $tmpdir);
87 $opts{rt} = <$tmpdir/rt-*>;
89 chdir $opts{rt} if $opts{rt};
103 glob("local/plugins/*/{lib,sbin,bin}"),
104 glob("docs/UPGRADING*"),
107 my $converter = RT::Pod::HTMLBatch->new;
109 sub generate_configure_help {
110 my $configure = shift;
111 my $help = `./$configure --help`;
112 my $dest = "$opts{to}/configure.html";
114 if ($help and open my $html, ">", $dest) {
115 print $html join "\n",
116 "<pre>", encode_entities($help), "</pre>", "\n";
118 $converter->note_for_contents_file(["configure options"], $configure, $dest);
120 warn "Can't open $dest: $!";
124 # Generate a page for ./configure --help if we can
125 if (-x "configure.ac" and -d ".git") {
126 rmtree("autom4te.cache") if -d "autom4te.cache";
127 generate_configure_help("configure.ac");
129 elsif (-x "configure") {
130 generate_configure_help("configure");
133 warn "Unable to generate a page for ./configure --help!\n";
136 # Manually "convert" README* and 3.8-era UPGRADING* to HTML and push them into
137 # the known contents.
138 for my $file (<README* UPGRADING*>) {
139 (my $name = $file) =~ s{^.+/}{};
140 my $dest = "$opts{to}/$name.html";
142 open my $source, "<", $file
143 or warn "Can't open $file: $!", next;
145 open my $html, ">", $dest
146 or warn "Can't open $dest: $!", next;
149 print $html encode_entities($_) while <$source>;
150 print $html "</pre>";
152 close $source; close $html;
154 $converter->note_for_contents_file([$name], $file, $dest);
157 # Copy images into place
158 make_path("$opts{to}/images/");
159 copy($_, "$opts{to}/images/")
160 for <docs/images/*.{png,jpeg,jpg,gif}>;
162 # Temporarily set executable bits on upgrading doc to work around
163 # Pod::Simple::Search limitation/bug:
164 # https://rt.cpan.org/Ticket/Display.html?id=80082
166 system("chmod", @_) == 0
167 or die "Unable to chmod: $! (exit $?)";
169 system_chmod("+x", $_) for <docs/UPGRADING*>;
171 # Convert each POD file to HTML
172 $converter->batch_convert( \@dirs, $opts{to} );
174 # Remove execution bit from workaround above
175 system_chmod("-x", $_) for <docs/UPGRADING*>;
177 # Need to chdir back out, if we are in the tmpdir, to let it clean up
178 chdir "/" if $tmpdir;
186 rt-static-docs - generate doc shipped with RT
190 rt-static-docs --to /path/to/output [--rt /path/to/rt]
194 RT ships with documentation (written in POD) embedded in library files, at the
195 end of utility scripts, and in standalone files. This script finds all of that
196 documentation, collects and converts it into a nice set of HTML files, and tops
197 it off with a helpful index.
199 Best Practical uses this to publish documentation under
200 L<http://bestpractical.com/rt/docs/>.
208 Set the destination directory for the output files.
212 Set the RT base directory to search under. Defaults to the current working
213 directory, which is fine if you're running this script as
214 C<devel/tools/rt-static-docs>.
216 May also point to a tarball (a file ending in C<.tar.gz>) which will be
217 unpacked into a temporary directory and used as the RT base directory.