#!/usr/bin/perl -w


# transkript all POD from a Perl modules folder in a folder of HTML manuals, an index.html is also generated
# 2003-04-23 Felipe Wettstein
# 2004-03-08 english comments, minor improvements



use  strict;

my  $pod_folder_root  =  '/Library/Perl/5.8.1/Bio';  # root location of PODs (modules folder), a global variable
my  $pod_folder_relative  =  '';  # relative location of PODs, what comes after $pod_folder_root

my  $html_folder_apache  =  '';  # documents root (for apache), leave blank for relative path
my  $html_folder_fs_root  =  '/Users/Felipe/Sites/Bio';  # documents root for file system (absolut)
             # it looks as if the 'bioperl' PODs need a 'Bio' folder
my  $html_folder_fs_relative  ='';  # relative path, above $html_folder_fs_root

my  @shell_lines;  # lots of command lines
my  $shell;   # single command line: pod2html ...
my  $title;  # title of module (will become HTML title tag)
my  @index;  # contains index of all HTML files, will become 'index.html'


my  $htmlroot  =  '';  # pod2html option
if  ($html_folder_apache)  {
     $htmlroot  =  " --htmlroot=".$html_folder_apache;
}


# create dir, where files will be stored if it does not exist
if  (!-e  $html_folder_fs_root)  {
     print  "folder $html_folder_fs_root does not exist. will be made..\n";
     mkdir  $html_folder_fs_root  or  print  "cannot make folder $html_folder_fs_root. this program can only make one folder at a time.\n";
     }


my  $level=1;  # directory level -> level of header foramtting (<h1>, <h2>, <h3...)
print  "\nindex ...\n";
find_all($pod_folder_relative,  $html_folder_fs_relative,$level);

chdir  $html_folder_fs_root;  # pod2html writes a temp file -> change to writable directory

# create 'index.html' in folder '$html_folder_fs_root'
open  (INDEX,  ">index.html")  or  print  "cannot write index.html: $!";
     print  INDEX  <<  "INDEX_HTML";
<!DOCTYPE  html  PUBLIC  "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html  xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>index  of  $html_folder_apache/Bio</title>
    />
     <LINK  REL="stylesheet"  TYPE="text/css"  HREF="../b/pod2html.css">
</head>


INDEX_HTML

    foreach (@index) {
        $_ =~ s/\/\//\//g;  # remove double '/' (come up when $html_folder_fs_relative is empty)
         $_  =~s/href\=\"\//href\=\"/g;        # make links relative (remove leading '/' in link)
         $_  =~s/(\d\>)\//$1/ig;         # remove leading '/' in header
         
         print  INDEX  "$_\n";
     }
     print  INDEX  "\n\n";
close  (INDEX);

print  "\nindex.html done.\n";
`open index.html`;

# do all shell lines (compile 'pod2html'), this is the time consuming step...
print  "pod2html\n...";
foreach  (@shell_lines)  {
     `$_`;
}



# search recursively all folders
sub  find_all  {
     my  ($pod_folder_relative,  $html_folder_fs_relative,  $level)  =  @_;

     mkdir  $html_folder_fs_root.'/'.$html_folder_fs_relative  ;# or print "cannot make folder '$html_folder_fs_relative': $!\n";
     
     chdir  $pod_folder_root.$pod_folder_relative;  # change folder of interest
     my  @thisstep  =  glob  ('*');  # all files from folder of interest

     push  (@index,  "
$level>"); # start unorderd list (in HTML) foreach (@thisstep) { chomp; # if filename contains '.pm' (zb. AlignIO.pm), assume it is a perl module and holds POD information if ($_=~/\.pm/) { # take module title $title = `grep $pod_folder_root$pod_folder_relative/$_ -e"^=head1 NAME" -A4` or $title = $html_folder_fs_relative."/".$_; # it title not found, take module name $title =~ s/^=head1\s.*$//mg; # 'search pattern' entfernen $title =~ s/\s*\n/ /g; # compose command-line for 'pod2html' $shell = "pod2html". $htmlroot. " --infile=".$pod_folder_root.$pod_folder_relative."/".$_. " --outfile=".$html_folder_fs_root."/".$html_folder_fs_relative."/"; $_ =~ s/\.pm/\.html/; push (@index, "<a href=\"$html_folder_apache".$html_folder_fs_relative."/".$_."\">$title"."</a>
"); # apend to '@index' push (@shell_lines, $shell.$_ ); # apend to '@shell_lines' } # else, if it is a folder: search it! elsif (-d $pod_folder_root.$pod_folder_relative.'/'.$_) { push (@index, "\n$level>$pod_folder_relative/$_$level>"); # put a title to '@index' find_all($pod_folder_relative.'/'.$_, $html_folder_fs_relative.'/'.$_,$level+1); } } push (@index, "
"); } exit;