Skip to content

Commit

Permalink
Item8863: Add TOCBUTTONS feature for TocPlugin
Browse files Browse the repository at this point in the history
Signed-off-by: Wolfgang Denk <wd@denx.de>



git-svn-id: http://svn.foswiki.org/trunk/TocPlugin@7270 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
WolfgangDenk authored and WolfgangDenk committed Apr 27, 2010
1 parent 6369618 commit bd6559e
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 4 deletions.
2 changes: 2 additions & 0 deletions data/System/TocPlugin.txt
@@ -1,3 +1,4 @@
%META:TOPICINFO{author="WolfgangDenk" date="1271416286" format="1.1" version="1.2"}%
---++ <nop>%TOPIC%

%SHORTDESCRIPTION%
Expand All @@ -13,6 +14,7 @@ Adds a number of new tags:
* %<nop>CONTENTS% - generates a table of contents for a topic or an entire web, with full expansion depth control
* %<nop>REF% - inserts a symbolically named cross-reference URL
* %<nop>ANCHOR% - inserts a symbolically named jump target
* %<nop>TOCBUTTONS% - inserts "Prev", "Home" and "Next" buttons
Example:

%ATTACHURL%/screenshot.png
Expand Down
19 changes: 19 additions & 0 deletions data/System/TocPluginHelp.txt
@@ -1,3 +1,4 @@
%META:TOPICINFO{author="WolfgangDenk" date="1271417585" format="1.1" reprev="1.2" version="1.2"}%
If you see tags such as %<nop>SECTION0% on the next line, read TocPlugin

%SECTION0% Table of Contents and Cross-Reference Plugin
Expand Down Expand Up @@ -187,6 +188,24 @@ requested type will be listed.
*NOTES*
* If you use =REFTABLE= with the type =Section= the table will contain a list of all _named_ sections. For example %ANCHOR{type=Example,name=example2,display=no}% REFTABLE{type=Section} example %REFTABLE{type=Section}%

%SECTION1{name=AddTocButtos}% Adding navigation buttons
When using the =WebOrder= special topic to collect a list of topics
into a somewhat "linearized" form (a "book"), it is often very
convenient to be able to add navigation buttons to the previous and
the next pages as well as to the home page (table of contents). This
can be done by adding the %<nop>TOCBUTTONS% tag to your pages. For
example, you can use it in a template which is included either at the
top or the bottom of your pages. The included
="view.tocbuttons.tmpl"= template (intended to be used with NatSkin)
adds the %<nop>TOCBUTTONS% tag to the content footer of all pages in
the web. To activate it, use ="* set SKIN = tocbuttons, nat"= in your
<nop>WebPreferences.

Note that the "Prev", "Home" and "Next" links will be added only for
such topics that are listed in the =WebOrder= special topic, and they
will only be inserted when viewing a page, i. e. they will for
example not show up when printing such a topic or the whole "book".

%SECTION1{name=IndentedWebOrder}% Getting clever
It is possible to change the way the table of contents for the web is
ordered by using extra levels of indent in the WebOrder. If you indent
Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/TocPlugin.pm
Expand Up @@ -37,6 +37,7 @@ sub preRenderingHandler {
$web, $topic);
$_[0] = Foswiki::Plugins::TocPlugin::TOC::processTopic(
$wif, $web, $topic, $_[0]);
$_[0] =~ s/%TOCBUTTONS%//go; #dzus ugly fix - FIXME in time
}

1;
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/TocPlugin/Section.pm
Expand Up @@ -612,6 +612,7 @@ sub replaceAllTags {
$text = _replaceTypeTags("REFTABLE", $text, $alt);
$text = _replaceTypeTags("CONTENTS", $text, $alt);
$text = _replaceTypeTags("TOCCHECK", $text, $alt);
$text = _replaceTypeTags("TOCBUTTONS", $text, $alt);

return $text;
}
Expand Down
73 changes: 69 additions & 4 deletions lib/Foswiki/Plugins/TocPlugin/TOC.pm
Expand Up @@ -35,13 +35,16 @@ sub _processTag {
} elsif ($tag eq "TOCDUMP") {
return $toc->toString(0);
} else {
# my $ct = $toc->currentTopic();
if ($tag eq "TOCBUTTONS") {
# Return nothing for topics not in WebOrder
return "" unless $ct;
return &Foswiki::Plugins::TocPlugin::TOC::processTOCBUTTONSTag($toc, $wif, $ct->wikiName());
}
return Foswiki::Plugins::TocPlugin::Section::_error("Bad $tag: Current topic not in WebOrder") unless $ct;
if ($tag eq "ANCHOR") {
my $anc = $ct->processANCHORTag(@params);
return $anc->generateTarget() if $anc;
} elsif ($tag eq "SECTION") {
# my $ct = $toc->currentTopic();
my $sec = $ct->processSECTIONTag(@params);
return $sec->generateTarget() if $sec;
} elsif ($tag eq "REF") {
Expand Down Expand Up @@ -85,9 +88,73 @@ sub _processTOCTags {
$text =~ s/%(TOCDUMP)%/&_processTag($toc, $wif, $toc->currentTopic, $1, $nullatt)/geo;
$text =~ s/%(TOCCHECK)%/&_processTag($toc, $wif, $toc->currentTopic, $1, $nullatt)/geo;
$text =~ s/%(CONTENTS)({[^%]*})?%/&_processTag($toc, $wif, $toc->currentTopic, $1, Foswiki::Plugins::TocPlugin::Attrs->new($2))/geo;
$text =~ s/%(TOCBUTTONS)%/&_processTag($toc, $wif, $toc->currentTopic, $1, $nullatt)/geo;
return $text;
}

my $toc = undef;
my $mess = undef;

sub processTOCBUTTONSTag
{
my ($toc, $wif, $topic) = @_;

return "" unless (defined $toc);
my $mytopic = $toc->currentTopic();
return "" unless (defined $mytopic);

# Get list of files in the web
my $i;
my @fullList = ();
$toc->getTopicList(\@fullList);

for ($i = 0; $i< scalar(@fullList); $i++) {
last if ($fullList[$i] eq $topic);
}

my ($prev, $next, $home);
my ($prevText, $nextText, $homeText);
if ($i>0) {
$prev=$fullList[$i-1];
$prevText="Prev";
} else {
$prev=$prevText="";
}
if ($i<scalar(@fullList)-1) {
$next=$fullList[$i+1];
$nextText="Next";
} else {
$next=$nextText="";
}
$home=$fullList[0];
$homeText="Home";

if ($prev) {
$prev=$toc->_findTopic($prev);
$toc->loadTopic($prev);
$prev=$prev->generateReference($prev->wikiName());
}
if ($next) {
$next=$toc->_findTopic($next);
$toc->loadTopic($next);
$next=$next->generateReference($next->wikiName());
}
if ($home) {
$home=$toc->_findTopic($home);
$toc->loadTopic($home);
$home=$home->generateReference($home->wikiName());
}

return ("<table WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">
<tr><td WIDTH=\"33%\" ALIGN=\"left\" VALIGN=\"top\">$prev<td>
<td WIDTH=\"33%\" ALIGN=\"center\" VALIGN=\"top\">$home<td>
<td WIDTH=\"33%\" ALIGN=\"right\" VALIGN=\"top\">$next<td><tr>
<tr><td WIDTH=\"33%\" ALIGN=\"left\" VALIGN=\"top\">$prevText<td>
<td WIDTH=\"33%\" ALIGN=\"center\" VALIGN=\"top\">$homeText<td>
<td WIDTH=\"33%\" ALIGN=\"right\" VALIGN=\"top\">$nextText<td><tr></table>");
}


sub _printWithTOCTags {
my ($toc, $wif, $ct, $text) = @_;

Expand Down Expand Up @@ -120,8 +187,6 @@ sub _printWithTOCTags {
return $text;
}

my $toc = undef;

sub _webPrint {
my ($toc, $wif, $web) = @_;
return $toc->toPrint($toc, $wif, $web, 0);
Expand Down
6 changes: 6 additions & 0 deletions templates/view.tocbuttons.tmpl
@@ -0,0 +1,6 @@
%TMPL:INCLUDE{"view"}%
%TMPL:DEF{"contentfooter"}%<!-- content footer -->
%IF{"$'DISPLAYREVISIONINFO'='off'" else="$percntTMPL:P{\"revinfo\"}$percnt"}%<!-- revinfo //-->
<hr class="doNotDisplay" />
<div id="main-copy">%TOCBUTTONS%</div>
<!-- //content footer -->%TMPL:END%

0 comments on commit bd6559e

Please sign in to comment.