App-MakeEPUB

 view release on metacpan or  search on metacpan

lib/App/MakeEPUB.pm  view on Meta::CPAN

# ---------------------------------

# _tocncf_navPoints_from_array( {
#     counter => $cnt,
#     array   => $array,
#     indent  => "  ",
#     } )
#
# Returns a string containing <navPoint> entries for the <navMap> in toc.ncf
# from the given array. The first id is named "navPoint-$cnt" and the first
# playOrder "$cnt". $cnt is updated to the next number after the last
# playOrder.
#
# The array should be of the form [ [ $fname, $anchor, $text, $extra ], ... ],
# where $fname is the name of the file, $anchor the id of an html anchor
# (<a id="$anchor" ...>) and $text the text belonging to the anchor. The
# fourth field ($extra) is optional and can be used for next level navPoints.
#
sub _tocncf_navPoints_from_array {
    my ($args) = @_;
    my @anchors = @{$args->{array}};

t/toc_ncf.t  view on Meta::CPAN

  <content src="file1.html#anchor1" />
</navPoint>
<navPoint id="navpoint-4" playOrder="4">
  <navLabel><text>Second Anchor</text></navLabel>
  <content src="file1.html#anchor2" />
</navPoint>
EONP
$args = { counter => 2, array => $npa, indent => '' };
$nps = App::MakeEPUB::_tocncf_navPoints_from_array($args);

is($args->{counter}, 5, "counter updated");
is($nps, $np_ref, "correct navPoint string");

$args->{array} = [
    [ 'file2.html', 'anchor1', 'First Anchor', "    <!-- extra -->\n"],
];
$np_ref = <<EONP;
  <navPoint id="navpoint-5" playOrder="5">
    <navLabel><text>First Anchor</text></navLabel>
    <content src="file2.html#anchor1" />
    <!-- extra -->
  </navPoint>
EONP
$args->{indent} = '  ';
$nps = App::MakeEPUB::_tocncf_navPoints_from_array($args);

is($args->{counter}, 6, "counter updated");
is($nps, $np_ref, "correct navPoint string");

done_testing();



( run in 0.231 second using v1.01-cache-2.11-cpan-05444aca049 )