Skip to content

Commit

Permalink
Item8260: fix it so that links to topics that are not published don't…
Browse files Browse the repository at this point in the history
… get rewritten. Also refactored generators into a subdirectory to make life a bit easier.

git-svn-id: http://svn.foswiki.org/trunk/PublishPlugin@15234 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Jul 30, 2012
1 parent 9ae10a1 commit 35d1c46
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 113 deletions.
29 changes: 12 additions & 17 deletions data/System/PublishPlugin.txt
Expand Up @@ -144,7 +144,7 @@ table.publishForm .paramCol {
Include filter
</td>
<td class="inputCol">
<input type="text" name="inclusions" class="foswikiInputField" value="%URLPARAM{"inclusions" default="*" encode="entity"}%" size="30" title="Use * to publish all topics in the topic list">
<input type="text" name="inclusions" class="foswikiInputField" value="%URLPARAM{"inclusions" default="*" encode="entity"}%" size="30" title="Use * to publish all topics in the topic list" />
</td>
<td class="infoCol">
Comma-separated list of [[#WildcardPattern][wildcard patterns]] that match the names of topics to include. This acts as a filter on the topic list. Use =*= to publish all topics in the list.
Expand Down Expand Up @@ -234,7 +234,7 @@ table.publishForm .paramCol {
<textarea name="preferences" class="foswikiInputField" rows="5" cols="80"></textarea>
</td>
<td class="infoCol">
Lets you define [[PreferenceSettings][preferences]] that apply only to this
Lets you define Foswiki [[PreferenceSettings][preferences]] that will be available for use in topics during this
publishing run. Define preferences one per line, using the syntax
=PREFERENCE=VALUE= - for example, <verbatim>
TOOL_VERSION=3.14.15
Expand Down Expand Up @@ -321,16 +321,14 @@ ISBN=1-56592-149-6
<td class="nameCol">Output format</td>
<td class="inputCol">
<select name="format" id="selectedFormat" class="foswikiSelect">
<option>file</option>
<option>flatfile</option>
<option>zip</option>
<option>tgz</option>
<option>pdf</option>
<option>ftp</option>
%PUBLISHING_GENERATORS{format="<option>$name</option>" separator=""}%
</select>
</td>
<td class="infoCol">
Generates HTML output (=file=), HTML output compressed as =zip= or =tgz=, HTML uploaded to a =ftp= server, or =pdf=. =flatfile= will generate a single =.html= file with all topics concatenated into it.
The available formats are:
<dl>
%PUBLISHING_GENERATORS{format="<dt> =$name= </dt><dd>$help</dd>" separator=""}%
</dl>
</td>
<td class="paramCol">
=format=
Expand Down Expand Up @@ -661,21 +659,17 @@ The history topic contains a list of all the parameters used, and the versions o
---++ Installation Instructions
---+++ Dependencies

Note: If you want to generate PDF files, you will need an installation of =htmldoc=. This program is available from http://www.easysw.com/htmldoc/ for free, but you are *strongly* recommended to buy the commercial version. Your support for open-source projects helps make open-source software possible.

%$INSTALL_INSTRUCTIONS%

Run =configure= and complete the installation in the *PublishPlugin* section.
*IMPORTANT* Run =configure= and complete the installation in the *PublishPlugin* section.

---++++ =PDF= output
Install htmldoc from http://www.easysw.com/htmldoc/
If you want to generate PDF files, you will need an installation of a PDF generator, for example =htmldoc= or =prince=. Find them using google.

Note that =htmldoc= can also be used to generate !PostScript by using the =-t= option in the =Other output generator options= above. See the =htmldoc= man pages for details.

---++++ =.tgz= (tar) output
Install Archive::Tar and everything it depends on
If you want =.zip= output you will have to install =Archive::Zip= and everything it depends on.

---++++ =.zip= output
If you want =.tgz= (tar) output, install Archive::Tar and everything it depends on.
Install Archive::Zip and everything it depends on

*WARNING!* Anything published is no longer under the
Expand All @@ -694,6 +688,7 @@ This add-on started life as the !GenHTMLAddon, written by Foswiki:Main/CrawfordC
| Version: | %$VERSION% |
| Release: | %$RELEASE% |
| Change History: | |
| 2.4.0 (30 Jul 2012) | Foswiki:Tasks/Item12016 Add capability to construct flat HTML and PDF files. Bugfixes: Foswiki:Tasks/Item11988 Foswiki:Tasks/Item11339 Foswiki:Tasks/Item11345 Foswiki:Tasks/Item8260 Foswiki:Tasks/Item10597 Foswiki:Tasks/Item11346 |
| 2.3.2 (10 Aug 2011) | Foswiki:Tasks/Item10944: Fix publishing of attachments |
| 2.3.1 (14 Jun 2011) | Foswiki:Tasks/Item10870: support skinning of the history topic. Foswiki:Tasks/Item10870: support definition of session preferences from the publish form. Foswiki:Tasks/Item10843: bugfix to publishers control centre |
| 2.2.1 (25 May 2011) | Foswiki:Tasks/Item10578: allow list of publishskins; Foswiki:Tasks/Item10580: allow empty outfile param; Foswiki:Tasks/Item10585: support all valid topic names in topiclist; Foswiki:Tasks/Item10578: made template purging configurable Foswiki:Tasks/Item10594: merged patch; Foswiki:Tasks/Item10581: correct paths to resources in HTML output. (Diab Jerius and Crawford Currie) |
Expand Down
49 changes: 46 additions & 3 deletions lib/Foswiki/Plugins/PublishPlugin.pm
Expand Up @@ -13,7 +13,7 @@ use Error qw( :try );
use Assert;

our $VERSION = '$Rev$';
our $RELEASE = '2.3.2';
our $RELEASE = '2.4.0';
our $SHORTDESCRIPTION =
'Generate static output (HTML, PDF) optionally upload (FTP) the output to a publishing site.';

Expand Down Expand Up @@ -41,7 +41,9 @@ sub initPlugin {

Foswiki::Func::registerRESTHandler( 'publish', \&_publishRESTHandler );
Foswiki::Func::registerTagHandler( 'PUBLISHERS_CONTROL_CENTRE',
\&_publishControlCentre );
\&_PUBLISHERS_CONTROL_CENTRE );
Foswiki::Func::registerTagHandler( 'PUBLISHING_GENERATORS',
\&_PUBLISHING_GENERATORS );
return 1; # coupersetique
}

Expand Down Expand Up @@ -94,7 +96,48 @@ sub _display {
}

# Allow manipulation of $Foswiki::cfg{PublishPlugin}{Dir}
sub _publishControlCentre {
sub _PUBLISHING_GENERATORS {
my ( $session, $params, $topic, $web, $topicObject ) = @_;

my $format = defined $params->{format} ? $params->{format} : '$item';
my $separator = defined $params->{separator} ? $params->{separator} : ',';

# Get a list of available generators
my @list;
foreach my $place (@INC) {
print STDERR "BLAH $place\n";
my $d;
if ( opendir( $d, "$place/Foswiki/Plugins/PublishPlugin/BackEnd" ) ) {
foreach my $gen ( readdir $d ) {
next unless ( $gen =~ /^(\w+)\.pm$/ );
my $name = $1;
my $entry = $format;
$entry =~ s/\$name/$name/g;
if ( $entry =~ /\$help/ ) {
my $help;
my $class =
"Foswiki::Plugins::PublishPlugin::BackEnd::$name";
eval "require $class";
if ($@) {
$help = $@;
}
elsif ( !$class->can('DESCRIPTION') ) {
$help = 'no description';
}
else {
$help = $class->DESCRIPTION;
}
$entry =~ s/\$help/$help/g;
}
push( @list, $entry );
}
}
}
return Foswiki::Func::decodeFormatTokens( join( $separator, @list ) );
}

# Allow manipulation of $Foswiki::cfg{PublishPlugin}{Dir}
sub _PUBLISHERS_CONTROL_CENTRE {
my ( $session, $params, $topic, $web, $topicObject ) = @_;

my $query = Foswiki::Func::getCgiQuery();
Expand Down
Expand Up @@ -14,7 +14,7 @@
#
# File writer module for PublishPlugin
#
package Foswiki::Plugins::PublishPlugin::file;
package Foswiki::Plugins::PublishPlugin::BackEnd::file;

use strict;

Expand All @@ -24,6 +24,9 @@ our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd');
use File::Copy ();
use File::Path ();

use constant DESCRIPTION =>
"A directory tree on the server containing a single HTML file for each topic and copies of all published attachments.";

sub new {
my $class = shift;
my $this = $class->SUPER::new(@_);
Expand Down
Expand Up @@ -14,12 +14,15 @@
#
# File writer module for PublishPlugin
#
package Foswiki::Plugins::PublishPlugin::flatfile;
package Foswiki::Plugins::PublishPlugin::BackEnd::flatfile;

use strict;

use Foswiki::Plugins::PublishPlugin::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::file');
use Foswiki::Plugins::PublishPlugin::BackEnd::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd::file');

use constant DESCRIPTION =>
'Single HTML file containing all topics. Attachments will be saved to a resource directory on the server.';

sub new {
my $class = shift;
Expand Down Expand Up @@ -52,9 +55,8 @@ sub addString {
my $fh = $this->{flatfile};

# Add an anchor to act as a destination for jumps to this topic
print $fh "<!-- $file -->";
my $a = _encodeAnchor($file);
print $fh "<a name='$a'></a><h1>$file</h1>";
print $fh "<a name='$a'><!-- $file --></a>";
print $fh $string;
}

Expand Down Expand Up @@ -85,8 +87,12 @@ sub _encodeAnchor {
# Convert a topic URL to an anchor references
sub mapTopicURL {
my ( $this, $path ) = @_;

return '#' . _encodeAnchor($path);
print STDERR "CUNT $path\n";
if ( $path =~ /(#.*)$/ ) {
return $1;
}
$path = '#' . _encodeAnchor($path);
return $path;
}

sub close {
Expand Down
84 changes: 84 additions & 0 deletions lib/Foswiki/Plugins/PublishPlugin/BackEnd/flatpdf.pm
@@ -0,0 +1,84 @@
#
# Copyright (C) 2005 Crawford Currie, http://c-dot.co.uk
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# 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 General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html
#
# PDF writer module for PublishPlugin
#

package Foswiki::Plugins::PublishPlugin::BackEnd::flatpdf;

use strict;
use Foswiki::Plugins::PublishPlugin::BackEnd::flatfile;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd::flatfile');

use constant DESCRIPTION =>
'PDF file with all topics and attachments inside it. Topics will follow one another with no intervening page breaks.';

use File::Path;

sub new {
my $class = shift;
my ($params) = @_;
$params->{outfile} ||= "flatpdf";
my $this = $class->SUPER::new(@_);
return $this;
}

sub param_schema {
my $class = shift;
return {
outfile => {
default => 'flatpdf',
validator =>
\&Foswiki::Plugins::PublishPlugin::Publisher::validateFilename
},
%{ $class->SUPER::param_schema() }
};
}

sub close {
my $this = shift;
my $dir = $this->{path};
eval { File::Path::mkpath($dir) };
die $@ if ($@);

my @files = ("$dir$this->{params}->{outfile}/master.html");

my $cmd = $Foswiki::cfg{PublishPlugin}{PDFCmd};
die "{PublishPlugin}{PDFCmd} not defined" unless $cmd;

my $landed = "$this->{params}->{outfile}.pdf";
my @extras = split( /\s+/, $this->{extras} || '' );

$ENV{HTMLDOC_DEBUG} = 1; # see man htmldoc - goes to apache err log
$ENV{HTMLDOC_NOCGI} = 1; # see man htmldoc

$this->{path} .= '/' unless $this->{path} =~ m#/$#;
my ( $data, $exit ) = Foswiki::Sandbox::sysCommand(
$Foswiki::sharedSandbox,
$cmd,
FILE => "$this->{path}$landed",
FILES => \@files,
EXTRAS => \@extras
);

# htmldoc failsa lot, so log rather than dying
$this->{logger}->logError("htmldoc failed: $exit/$data/$@") if $exit;

# Get rid of the temporaries
unlink( @{ $this->{files} } );

return $landed;
}

1;
Expand Up @@ -19,14 +19,17 @@
# allow method POST for 'ftp:' URLs"
# TODO: clean up ftp site, removing/archiving/backing up old version

package Foswiki::Plugins::PublishPlugin::ftp;
package Foswiki::Plugins::PublishPlugin::BackEnd::ftp;

use strict;

# Inherit from file backend; we use the local copy as the cache for
# uploading from
use Foswiki::Plugins::PublishPlugin::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::file');
use Foswiki::Plugins::PublishPlugin::BackEnd::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd::file');

use constant DESCRIPTION =>
'Upload generated HTML to an FTP site. Options controlling the upload can be set below.';

use File::Temp qw(:seekable);
use File::Spec;
Expand Down
Expand Up @@ -15,11 +15,14 @@
# PDF writer module for PublishPlugin
#

package Foswiki::Plugins::PublishPlugin::pdf;
package Foswiki::Plugins::PublishPlugin::BackEnd::pdf;

use strict;
use Foswiki::Plugins::PublishPlugin::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::file');
use Foswiki::Plugins::PublishPlugin::BackEnd::file;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd::file');

use constant DESCRIPTION =>
'PDF file with all content in it. Each topic will start on a new page in the PDF.';

use File::Path;

Expand Down
Expand Up @@ -14,13 +14,16 @@
#
# Archive::Zip writer module for PublishPlugin
#
package Foswiki::Plugins::PublishPlugin::tgz;
package Foswiki::Plugins::PublishPlugin::BackEnd::tgz;

use strict;

use Foswiki::Plugins::PublishPlugin::BackEnd;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd');

use constant DESCRIPTION =>
'HTML compressed into a single tgz archive for shipping.';

use Foswiki::Func;
use File::Path;
use Assert;
Expand Down
Expand Up @@ -14,13 +14,16 @@
#
# Archive::Zip writer module for PublishPlugin
#
package Foswiki::Plugins::PublishPlugin::zip;
package Foswiki::Plugins::PublishPlugin::BackEnd::zip;

use strict;

use Foswiki::Plugins::PublishPlugin::BackEnd;
our @ISA = ('Foswiki::Plugins::PublishPlugin::BackEnd');

use constant DESCRIPTION =>
'HTML compressed into a single zip file for shipping.';

use Foswiki::Func;
use File::Path;

Expand Down
13 changes: 7 additions & 6 deletions lib/Foswiki/Plugins/PublishPlugin/MANIFEST
Expand Up @@ -7,12 +7,13 @@ lib/Foswiki/Plugins/PublishPlugin/Config.spec 0444
lib/Foswiki/Plugins/PublishPlugin/Publisher.pm 0444
lib/Foswiki/Plugins/PublishPlugin/PageAssembler.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd.pm 0444
lib/Foswiki/Plugins/PublishPlugin/file.pm 0444
lib/Foswiki/Plugins/PublishPlugin/flatfile.pm 0444
lib/Foswiki/Plugins/PublishPlugin/ftp.pm 0444
lib/Foswiki/Plugins/PublishPlugin/pdf.pm 0444
lib/Foswiki/Plugins/PublishPlugin/tgz.pm 0444
lib/Foswiki/Plugins/PublishPlugin/zip.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/file.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/flatfile.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/flatpdf.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/ftp.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/pdf.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/tgz.pm 0444
lib/Foswiki/Plugins/PublishPlugin/BackEnd/zip.pm 0444
pub/System/PublishPlugin/publish.gif 0644
pub/System/PublishPlugin/wikiringlogo20x20.png 0644
templates/view.basic_publish.tmpl 0444
Expand Down

0 comments on commit 35d1c46

Please sign in to comment.