#!/usr/bin/perl
use strict; use warnings; no warnings 'once';

=pod

=head1 DESCRIPTION

Builds Screenpager (documentation) files.

=cut

use lib '/usr/local/lib';
require Zelea::AutoEditor;

    our $_project_directory = '/home/mike/project/Screenpager';

    Zelea::AutoEditor::auto_edit( glob $_project_directory . '/*' );

   # Create project manual.html
   # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    {
        chdir '/tmp' or die; # because pod2html leaves a mess
        my $man_raw_file = '/tmp/man-raw-html';
        my $command = '/usr/bin/pod2html'
            . " --infile=$_project_directory/screenpager --outfile=$man_raw_file";
        system $command and die 'unable to execute: ' . $command;

        open( IN_FILE, "<$man_raw_file" ) or die;
        open( OUT_FILE, ">$_project_directory/manual.html" ) or die;
        {
            my $is_background_fixed = 0; # not yet
            while( <IN_FILE> )
            {
                my $line = $_;

               # Correct the background colour.
               #(pod2html specifies foreground, but forgets background)
               # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
                if( !$is_background_fixed
                 && $line =~ s|<body style="background-color: white">|<body>| )
                {
                    $is_background_fixed = 1;
                }

                print OUT_FILE $line;
            }
            $is_background_fixed or warn "could not fix background";
        }
        close OUT_FILE;
        close IN_FILE;

        unlink $man_raw_file;
    }

   # - - -
    exit;