#!/usr/bin/perl
# vim: set ts=4 sw=4 tw=78 et si ft=perl:
#
# make-epub-content-opf
#
use 5.010;
use strict;
use warnings;

use App::MakeEPUB;
use File::Spec;
use Getopt::Long;
use Pod::Usage;

my %opt = (
    tocdepth    => 1,
    identifier  => sprintf('%x',time),
    language    => 'en',
    title       => 'You forgot to set a title',
);

my %guidetitle = (
    cover   => 'Cover',
);

GetOptions( \%opt,
    'cover=s',
    'creator=s',
    'identifier=s',
    'language=s',
    'publisher=s',
    'rights=s',
    'spine=s',
    'title=s',
    'output=s',
    'help|?', 'manual')
    or pod2usage(2);

pod2usage(-exitval => 0, -verbose => 1, -input => \*DATA) if ($opt{help});
pod2usage(-exitval => 0, -verbose => 2, -input => \*DATA) if ($opt{manual});

my $epubdir = shift;

pod2usage(-exitval => 1, -verbose => 1, -input => \*DATA) unless ($epubdir);

my $epub = App::MakeEPUB->new({ epubdir     => $epubdir,
                                spine_order => $opt{spine},
                              });

$epub->add_metadata(\%opt);
$epub->write_epub($opt{output});

exit 0;

__END__

=head1 NAME

make-epub - create an EPUB ebook from a directory

=head1 SYNOPSIS

 make-epub [options] path/to/epubdir

Create the metadata for an EPUB book from the files I<path/to/epubdir> and
write the metadata and files into an EPUB file.

=head1 OPTIONS

=over 8

=item B<< -help >>

Print a brief help message and exit.

=item B<< -manual >>

Print the manual page and exit.

=item B<< -output filename >>

This option sets the name of the EPUB file the program will create.

If it is missing the suffix I<< .epub >> is added to I<< path/to/epubdir >>
and used as the name of the EPUB file.

=item B<< -creator name_of_creator >>

This option sets the dc:creator attribute of the metadata.
You may use this for information about the author.

=item B<< -cover coverfile >>

This option marks the file containing the cover for the OPF guide.

=item B<< -identifier >>

Set the I<dc:identifier> for the metadata.

=item B<< -language >>

Set the I<dc:language> for the metadata. Defaults to I<en>.

=item B<< -publisher name_of_publisher >>

This option sets the dc:publisher attribute of the metadata.
You may use this for information about the publisher.

=item B<< -rights the_copyright >>

This options sets the dc:rights attribute of the metadata.
Use this for copyright information.

=item B<< -title title >>

Set the I<dc:title> for the metadata.

=item B<< -spine order >>

This Option determines the order of the HTML pages in the EPUB. The argument
for this options is a comma separated list of basenames (without ending) of
the HTML files in the EPUB book.

For instance if you have two HTML files with path I<OEBPS/part1.html> and
I<OEBPS/part2.html> you would give option C<-spine> like this:

 make-epub-content-opf -spine=part1,part2 ...

=back

=head1 DESCRIPTION

This program will generate the metadata files for an EPUB book.

It determines the name and path of the I<content.opf> and the I<toc.ncx>
file and writes the metadata gathered from the command line and the files in
the given directory into them.

=head1 AUTHOR

Mathias Weidner
=cut
container.xml:<?xml version="1.0"?>
container.xml:<container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container">
container.xml: <rootfiles>
container.xml:  <rootfile full-path="content.opf" media-type="application/oebps-package+xml"/>
container.xml: </rootfiles>
container.xml:</container>
content.opf:<?xml version="1.0"?>
content.opf:<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid" version="2.0">
content.opf:
content.opf: <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:opf="http://www.idpf.org/2007/opf">
content.opf:%%METADATA%%
content.opf: </metadata>
content.opf:
content.opf: <manifest>
content.opf:%%MANIFEST%%
content.opf: </manifest>
content.opf:
content.opf: <spine toc="ncx">
content.opf:%%SPINE%%
content.opf: </spine>
content.opf:
content.opf:%%GUIDE%%
content.opf:</package>
toc.ncx:<?xml version="1.0"?>
toc.ncx:<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
toc.ncx:<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
toc.ncx:
toc.ncx: <head>
toc.ncx:%%TOCNCXHEAD%%
toc.ncx: </head>
toc.ncx:
toc.ncx: <docTitle>
toc.ncx:%%TOCNCXDOCTITLE%%
toc.ncx: </docTitle>
toc.ncx:
toc.ncx: <navMap>
toc.ncx:%%TOCNCXNAVMAP%%
toc.ncx: </navMap>
toc.ncx:
toc.ncx:</ncx>
