#!/usr/local/bin/perl

eval 'exec /usr/local/bin/perl  -S $0 ${1+"$@"}'
    if 0; # not running under some shell

 #   map perl POD to S5
 #
 #
 #   This  file  is  part of the  PodWiki  web-based authoring tool.
 #
 #   By  accessing  this software,  PodWiki,  you are  duly informed
 #   of and  agree to be  bound  by the  conditions  described below
 #   in this notice:
 #
 #   This software product, PodWiki,  is developed by  Thomas Linden
 #   and      copyrighted  (C) 2007     by  Thomas Linden,  with all
 #   rights reserved.
 #
 #   There is  no charge for  PodWiki software. You can redistribute
 #   it and/or modify it under  the terms of the  GNU General Public
 #   License, which is incorporated by reference herein.
 #
 #   PodWiki is distributed WITHOUT ANY WARRANTY,IMPLIED OR EXPRESS,
 #   OF  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that
 #   the  use of it will not infringe on any third party's intellec-
 #   tual property rights.
 #
 #   You  should  have  received a  copy  of  the GNU General Public
 #   License along with PodWiki.  Copies  can also be obtained from:
 #
 #     http://www.gnu.org/copyleft/gpl.html
 #
 #   or by writing to:
 #
 #     Free Software Foundation, Inc.
 #     59 Temple Place, Suite 330
 #     Boston, MA 02111-1307
 #     USA
 #
 #   Or contact:
 #
 #    "Thomas Linden" <tom |AT| cpan.org>
 #
 #   Additional Copyrights:
 #
 #    Eric Meyer (D/pod2s5/Pod-S5-0.01/demo/example/index.html)
 #     S5 Version 1.2a (Attribution-ShareAlike 2.0 License)
 #
 #


package Pod::S5::Script;

$Pod::S5::Script::VERSION = 0.08;

use Pod::S5;
use Getopt::Long;
use Shell qw(cp);

my $host = `hostname`;
chomp $host;

my($v, $h, $t, $d, $a, $c, $w, $co, $n);

Getopt::Long::Configure( qw(no_ignore_case));
if (! GetOptions (
		  'theme=s'    => \$t,
		  'dest=s'     => \$d,
		  'author=s'   => \$a,
		  'creation=s' => \$c,
		  'where=s'    => \$w,
		  'company=s'  => \$co,
		  'name=s'     => \$n,
		  'version'    => \$v,
		  'help'       => \$h
		 ) ) {
  &usage;
}

if ($h) {
  &usage;
}

if ($v) {
  print qq($0 version $Pod::S5::Script::VERSION\n);
  exit;
}

my %opt = (
	   theme    => $t  || 'default',
	   dest     => $d  || '',
	   author   => $a  || $ENV{USER},
	   creation => $c  || scalar localtime,
	   where    => $w  || $host,
	   company  => $co || '&nbsp;',
	   name     => $n  || '',
	   );

$opt{podfile} = shift;

if (! $opt{podfile}) {
  &usage;
}

if (! $opt{name}) {
  # use filename as slide name
  $opt{name} = $opt{podfile};
  $opt{name} =~ s/\.pod$//;
  $opt{name} =~ s/[\.\_\-]/ /g;
  $opt{name} =~ s/^(.)/uc($1)/e;
}
if (! $opt{dest}) {
  # use filename as dest directory, based on current directory
  $opt{dest} = $opt{podfile};
  $opt{dest} =~ s/\.pod$//;
  $opt{dest} =~ s/[^a-zA-Z0-9]//g;
}
$opt{version} = $Pod::S5::Script::VERSION;


if (! -d $opt{dest}) {
  mkdir $opt{dest} or die "Could not create destination directory $opt{dest}: $!\n";
}



open S5, "> $opt{dest}/index.html" or die "Could not create $opt{dest}/index.html: $!\n";
select S5;





#####  start the rendering process
my $s5 = new Pod::S5(%opt);

open POD, "<$opt{podfile}" or die "Could not load $opt{podfile}: $!\n";
my $pod = join "", <POD>;
close POD;

print STDERR qq(Generating $opt{dest}/index.html .. );

print $s5->process($pod);

print STDERR qq(done\n);

if (! -d "$opt{dest}/ui") {
  # install S5
  print STDERR qq(Installing S5 to $opt{dest}/ .. );

  my $s5 = (grep { -d } map { "$_/Pod/S5/s5" } @INC)[0];
  if(!$s5) { die "s5/ html/css files seem not to be exist!\n" };

  cp ("-R", "$s5/*", "$opt{dest}/") and die "Could not copy S5 files from $s5 to $opt{dest}: $!\n"; 

  print STDERR qq(done\n);
}

exit;


sub usage {
  print qq(Usage: $0 [-hv] [options] <inputfile.pod>
    --theme <theme>     the theme to use, default is 'default'. Available
                        themes: default, flower, i18n, pixel, yatil.

    --dest <directory>  target directory where to install the slideshow.
                        If not specified the target directory name will
                        be generated from the B<name> parameter or from
                        the filename of the source pod file.

    --author <author>   the name of the slideshow author.

    --creation <date>   when the slideshow were generated (default: current date).

    --company <org>     company or organisation (default: none).

    --where <location>  where the slideshow were made (default: hostname).

    --name <name>       the name of the slideshow (title).

 -v --version           print the current version of the program.

 -h --help              print usage information.

 Please refer to the the pod2s5(1) manpage for more details.
);
  exit;
}

1;

=head1 NAME

Pod::S5 - Generate S5 slideshow from POD source file.

=head1 SYNOPSIS

 pod2s5 [-hv] [options] inputfile.pod
    --theme <theme>     the theme to use, default is 'default'. Available
                        themes: default, flower, i18n, pixel, yatil.

    --dest <directory>  target directory where to install the slideshow.
                        If not specified the target directory name will
                        be generated from the B<name> parameter or from
                        the filename of the source pod file.

    --author <author>   the name of the slideshow author.

    --creation <date>   when the slideshow were generated (default: current date).

    --company <org>     company or organisation (default: none).

    --where <location>  where the slideshow were made (default: hostname).

    --name <name>       the name of the slideshow (title).

 -v --version           print the current version of the program.

 -h --help              print usage information.

=head1 DESCRIPTION

B<pod2s5> converts POD input to a S5 HTML slideshow. No
additional software is required. Just write a POD file, run
B<pod2s5> on it - and you're done.

=head1 POD

Beside the known L<perlpod> markup some additions have been made:

Since we are generating a slideshow, the POD must be devided into
pieces which can be used as slides. Slides will be separated by the
B<=head1> title tag (which itself becomes the title of the slide.

 =head1 Intro --+
                |
 [..]           +------- Slide 1
 [..]           |
            ----+
 
 =head1 Intro --+
                |
 [..]           +------- Slide 2
 [..]           |
            ----+
 
 =head1 End   --+
                |
 [..]           +------- Slide 3
 [..]           |
            ----+

Each slide may contain any valid POD.

=over

=item

Images can be included using the tag B<GE<lt>>image.pngB<E<gt>>.
You must manually copy images to the target directory.

=item

Plain HTML code can be included using the B<html> formatter, eg:

 =begin html
 
 <title>Blah</title>
 
 =end html

=item

You can create incremental slides using bullet lists, that is
each list item will appear separately, as if it were on an extra
slide.

Example:

 =over
 
 =item *
 
 1st item
 
 =item *
 
 2nd item
 
 =back

=item

You can add special formatters for code, which will be syntax
highlighted if the module L<Syntax::Highlight::Engine::Kate>
is installed. Use the name of the programming language as the
formatter name.

Example:

 =begin perl
 
 if ($var) {
  exit;
 }
 
 =end perl

To get a list of the available languages, refer to the
L<Syntax::Highlight::Engine::Kate> manpage.

=back


=head1 DEPENDENCIES

L<Pod::S5>

L<unzip(1)>

L<Syntax::Highlight::Engine::Kate> is optional.

S5 is already included in the
script and will automatically installed if you generate a
new slide.

=head1 LICENSE AND COPYRIGHT

Copyright (c) 2007 Thomas Linden

This tool is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

S5 Copyright (c) 2007 Eric Meyer
S5 Version 1.2a (Attribution-ShareAlike 2.0 License)

=head1 BUGS AND LIMITATIONS

See rt.cpan.org for current bugs, if any.

=head1 INCOMPATIBILITIES

None known.

=head1 DIAGNOSTICS

To debug pod2s5 use B<debug()> or the perl debugger, see L<perldebug>.

=head1 AUTHOR

Thomas Linden <tlinden |AT| cpan.org>

=head1 VERSION

0.08

=cut

