chiark / gitweb /
Reorganise docs to include new howto material in intro etc.
[ypp-sc-tools.db-live.git] / yarrg / web / autohandler
index b0d7d98c8700ed81cf851743f3e6a7851d782dc7..8ff09966b953143dfd474a4a0d43c66913f47c38 100644 (file)
@@ -1,4 +1,86 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<%doc>
+
+ This is part of the YARRG website.  YARRG is a tool and website
+ for assisting players of Yohoho Puzzle Pirates.
+
+ Copyright (C) 2009 Ian Jackson <ijackson@chiark.greenend.org.uk>
+ Copyright (C) 2009 Clare Boothby
+
+  YARRG's client code etc. is covered by the ordinary GNU GPL (v3 or later).
+  The YARRG website is covered by the GNU Affero GPL v3 or later, which
+   basically means that every installation of the website will let you
+   download the source.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Affero General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Affero General Public License for more details.
+
+ You should have received a copy of the GNU Affero General Public License
+ along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+ Yohoho and Puzzle Pirates are probably trademarks of Three Rings and
+ are used without permission.  This program is not endorsed or
+ sponsored by Three Rings.
+
+
+ This Mason autohandler contains the doctype, charset and
+ copyright message.
+
+
+</%doc><%perl>
+
+use CommodsWeb;
+
+my $printable= printable($m);
+if ($printable =~ m/^pdf|^ps/) {
+       my $output;
+       my $got= $m->call_self(\$output);
+       if ($got) {
+               my @htargs= qw(htmldoc --continuous --gray --size 210x279mm
+                               --left 1cm --right 1cm);
+               $printable =~ m/^[a-z]+/;
+               push @htargs, '-t',$&;
+               if ($printable =~ m/2$/) {
+                       push @htargs, qw(--nup 2);
+               }
+               push @htargs, qw(-);
+
+               my $tmpfile= IO::File::new_tmpfile();
+               print $tmpfile $output or die $!;
+               $tmpfile->flush() or die $!;
+               seek $tmpfile,0,0 or die $!;
+               my $htmldoc= open HTMLDOC, "-|";
+               defined $htmldoc or die $!;
+               if (!$htmldoc) {
+                       eval {
+                               $ENV{'HTMLDOC_NOCGI'}=1;
+                               open STDIN, '<&', $tmpfile or die $!;
+
+                               exec @htargs;
+                               die $!;
+                       };
+                       print STDERR "HTMLDOC FAILURE $@";
+                       _exit(1);
+               }
+               my ($data,$read);
+               $r->content_type($printable eq 'pdf' ? 'application/pdf' :
+                                               'application/postscript');
+               while ($read= read HTMLDOC,$data,32768) { print $data; }
+               defined $read or die $!;
+               $?=0; $!=0; close HTMLDOC or die "$! $? $output ";
+               return;
+       }
+}
+set_ctype_utf8();
+$r->content_type('text/html; charset=UTF-8');
+
+</%perl><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <!--
     This HTML is generated by the YARRG website, which is
     <& copyrightdate &>.
     covered by the AGPL.
 -->
 
-% $m->call_next;
-
-<%init>
-use CommodsWeb;
-set_ctype_utf8();
-$r->content_type('text/html; charset=UTF-8');
-</%init>
+% $m->call_next();