#--- propagate.t -------------------------------------------------------------- # function: Test ToC propagation. use strict; use Test; BEGIN { plan tests => 10; } use HTML::Toc; use HTML::TocGenerator; use HTML::TocInsertor; my ($output, $content, $filename); my $toc = HTML::Toc->new; my $tocGenerator = HTML::TocGenerator->new; my $tocInsertor = HTML::TocInsertor->new; $toc->setOptions({ 'doLinkToToken' => 0, 'levelIndent' => 0, 'insertionPoint' => 'before

', 'header' => '', 'footer' => '', }); BEGIN { # Create test file $filename = "file$$.htm"; die "$filename is already there" if -e $filename; open(FILE, ">$filename") || die "Can't create $filename: $!"; print FILE <<'EOT'; close(FILE);

Header

EOT } END { # Remove test file unlink($filename) or warn "Can't unlink $filename: $!"; } #--- 1. propagate ------------------------------------------------------------- $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); ok($output, "

Header

"); #--- 2. propagateFile --------------------------------------------------------- $tocInsertor->insertIntoFile($toc, $filename, {'output' => \$output}); ok($output, "

Header

\n"); #--- 3. doLinkToToken ----------------------------------------------------- $toc->setOptions({'doLinkToToken' => 1}); $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); ok("$output\n", <<'EOT');

Header

EOT #--- 4. templateAnchorHrefBegin ----------------------------------------------- $toc->setOptions( {'templateAnchorHrefBegin' => '"<$node${file}test${groupId}>"'} ); $tocInsertor->insertIntoFile($toc, $filename, {'output' => \$output}); ok($output, "

Header

\n"); $toc->setOptions({'templateAnchorHrefBegin' => undef}); #--- 5. templateAnchorNameBegin ----------------------------------------------- $toc->setOptions({ 'templateAnchorName' => '"$node$groupId"', 'templateAnchorNameBegin' => '"<$anchorName>"' }); $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); ok($output, "<1h>

Header

"); $toc->setOptions({'templateAnchorName' => undef}); #--- 6. templateAnchorName function ------------------------------------------- sub AssembleAnchorName { # Get arguments my ($aFile, $aGroupId, $aLevel, $aNode) = @_; # Return value return $aFile . $aGroupId . $aLevel . $aNode; } # AssembleAnchorName() # Set options $toc->setOptions({'templateAnchorNameBegin' => \&AssembleAnchorName}); # Propagate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok($output, "h11

Header

"); # Restore options $toc->setOptions({'templateAnchorNameBegin' => undef}); #--- 7. doNumberToken -------------------------------------------------------- # Set options $toc->setOptions({'doNumberToken' => 1}); $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); ok("$output\n", <<'EOT');

1  Header

EOT # Reset options $toc->setOptions({ 'templateTokenNumber' => undef, 'doNumberToken' => 0 }); #--- 8. templateTokenNumber --------------------------------------------------- # Set options $toc->setOptions({ 'templateTokenNumber' => '"-$node-"', 'doNumberToken' => 1 }); # Propagate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok("$output\n", <<'EOT');

-1-Header

EOT # Reset options $toc->setOptions({ 'doNumberToken' => 0, 'templateTokenNumber' => undef }); #--- 9. numberingStyle -------------------------------------------------------- # Set options $toc->setOptions({ 'doNumberToken' => 1, 'tokenToToc' => [{ 'level' => 1, 'tokenBegin' => '

', 'numberingStyle' => 'lower-alpha' }] }); # Propagate ToC $tocInsertor->insert($toc, "

Header

", {'output' => \$output}); # Test ToC ok("$output\n", <<'EOT');

a  Header

EOT # Reset options $toc->setOptions({ 'doNumberToken' => 0, 'tokenToToc' => undef, }); #--- 10. declaration pass through --------------------------------------------- $tocInsertor->insert($toc, '

Header

', {'output' => \$output}); # Test ToC ok($output, '

Header

');