[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
texinfo/tp Texinfo/Structuring.pm t/do_master_m...
From: |
Patrice Dumas |
Subject: |
texinfo/tp Texinfo/Structuring.pm t/do_master_m... |
Date: |
Sun, 26 Feb 2012 18:26:03 +0000 |
CVSROOT: /sources/texinfo
Module name: texinfo
Changes by: Patrice Dumas <pertusus> 12/02/26 18:26:03
Modified files:
tp/Texinfo : Structuring.pm
Added files:
tp/t : do_master_menu.t
Log message:
New function do_master_menu to generate a master menu.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/Texinfo/Structuring.pm?cvsroot=texinfo&r1=1.121&r2=1.122
http://cvs.savannah.gnu.org/viewcvs/texinfo/tp/t/do_master_menu.t?cvsroot=texinfo&rev=1.1
Patches:
Index: Texinfo/Structuring.pm
===================================================================
RCS file: /sources/texinfo/texinfo/tp/Texinfo/Structuring.pm,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -b -r1.121 -r1.122
--- Texinfo/Structuring.pm 26 Feb 2012 15:44:28 -0000 1.121
+++ Texinfo/Structuring.pm 26 Feb 2012 18:26:03 -0000 1.122
@@ -1416,14 +1416,15 @@
return $entry;
}
-sub _new_menu($$)
+sub _new_block_command($$$)
{
- my $menu_entries = shift;
+ my $block_contents = shift;
my $parent = shift;
+ my $command_name = shift;
my $end = {'cmdname' => 'end', 'extra' =>
- {'command_argument' => 'menu',
- 'text_arg' => 'menu'}};
+ {'command_argument' => $command_name,
+ 'text_arg' => $command_name}};
push @{$end->{'args'}},
{'type' => 'misc_line_arg', 'parent' => $end};
push @{$end->{'args'}->[0]->{'contents'}},
@@ -1431,21 +1432,21 @@
'text' => ' ',
'extra' => {'command' => $end},
'parent' => $end->{'args'}->[0]},
- {'text' => 'menu', 'parent' => $end->{'args'}->[0]},
+ {'text' => $command_name, 'parent' => $end->{'args'}->[0]},
{'type' => 'spaces_at_end', 'text' => "\n",
'parent' => $end->{'args'}->[0]});
- my $new_menu = {'cmdname' => 'menu', 'parent' => $parent,
+ my $new_block = {'cmdname' => $command_name, 'parent' => $parent,
'extra'=>{'end_command' => $end}};
- $end->{'extra'}->{'command'} = $new_menu;
- $new_menu->{'contents'} = [{'extra' =>
- {'command' => $new_menu},
+ $end->{'extra'}->{'command'} = $new_block;
+ $new_block->{'contents'} = [{'extra' =>
+ {'command' => $new_block},
'type' => 'empty_line_after_command',
'text' => "\n"},
- @$menu_entries, $end];
- foreach my $content (@{$new_menu->{'contents'}}) {
- $content->{'parent'} = $new_menu;
+ @$block_contents, $end];
+ foreach my $content (@{$new_block->{'contents'}}) {
+ $content->{'parent'} = $new_block;
}
- return $new_menu;
+ return $new_block;
}
sub complete_node_menu($$)
@@ -1504,7 +1505,7 @@
if (scalar(@pending)) {
if (!$current_menu) {
my $section = $node->{'extra'}->{'associated_section'};
- $current_menu = _new_menu (address@hidden, $section);
+ $current_menu = _new_block_command (address@hidden, $section, 'menu');
push @{$section->{'contents'}}, $current_menu;
} else {
foreach my $entry (@pending) {
@@ -1543,6 +1544,75 @@
}
}
+sub do_master_menu($;$)
+{
+ my $self = shift;
+ my $labels = shift;
+ $labels = $self->labels_information() if (!defined($labels));
+ my $top_node = $labels->{'Top'};
+ return undef if (!defined($top_node));
+
+ my @first_level_nodes;
+ if ($top_node->{'menus'} and scalar(@{$top_node->{'menus'}})) {
+ foreach my $menu (@{$top_node->{'menus'}}) {
+ foreach my $entry (@{$menu->{'contents'}}) {
+ if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
+ my $entry_node = $entry->{'extra'}->{'menu_entry_node'};
+ if (! $entry_node->{'manual_content'}
+ and defined($entry_node->{'normalized'})) {
+ push @first_level_nodes, $entry_node->{'normalized'};
+ }
+ }
+ }
+ }
+ }
+
+ my @master_menu_contents;
+ foreach my $normalized_node (@first_level_nodes) {
+ my $node = $labels->{$normalized_node};
+ next if (!defined($node) or !$node->{'extra'});
+ my $node_title_contents;
+ if ($node->{'extra'}->{'associated_section'}
+ and $node->{'extra'}->{'associated_section'}->{'extra'}
+ and
$node->{'extra'}->{'associated_section'}->{'extra'}->{'misc_content'}) {
+ $node_title_contents
+ =
dclone($node->{'extra'}->{'associated_section'}->{'extra'}->{'misc_content'});
+ } else {
+ $node_title_contents = dclone($node->{'extra'}->{'node_content'});
+ }
+ my $menu_comment = {'type' => 'menu_comment'};
+ $menu_comment->{'contents'}->[0] = {'type' => 'preformatted',
+ 'parent' => $menu_comment};
+
+ $menu_comment->{'contents'}->[0]->{'contents'}
+ = [{'text' => "\n", 'type' => 'empty_line'}, @$node_title_contents,
+ {'text' => "\n", 'type' => 'empty_line'},
+ {'text' => "\n", 'type' => 'empty_line'}];
+ foreach my $content (@{$menu_comment->{'contents'}->[0]->{'contents'}}) {
+ $content->{'parent'} = $menu_comment->{'contents'}->[0];
+ }
+ push @master_menu_contents, $menu_comment;
+ if ($node->{'menus'}) {
+ foreach my $menu (@{$node->{'menus'}}) {
+ foreach my $entry (@{$menu->{'contents'}}) {
+ if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
+ push @master_menu_contents, dclone($entry);
+ }
+ }
+ }
+ }
+ }
+ my $first_preformatted = $master_menu_contents[0]->{'contents'}->[0];
+ my $master_menu_title = $self->gdt(' --- The Detailed Node Listing ---');
+ my @master_menu_title_contents;
+ foreach my $content (@{$master_menu_title->{'contents'}}, {'text' => "\n"}) {
+ $content->{'parent'} = $first_preformatted;
+ push @master_menu_title_contents, $content;
+ }
+ unshift @{$first_preformatted->{'contents'}}, @master_menu_title_contents;
+ return _new_block_command(address@hidden, undef, 'detailmenu');
+}
+
sub _sort_string($$)
{
my $a = shift;
Index: t/do_master_menu.t
===================================================================
RCS file: t/do_master_menu.t
diff -N t/do_master_menu.t
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ t/do_master_menu.t 26 Feb 2012 18:26:03 -0000 1.1
@@ -0,0 +1,151 @@
+use strict;
+
+use Test::More;
+BEGIN { plan tests => 1 };
+
+use lib 'maintain/lib/Unicode-EastAsianWidth/lib/';
+use lib 'maintain/lib/libintl-perl/lib/';
+use lib 'maintain/lib/Text-Unidecode/lib/';
+use Texinfo::Parser qw(parse_texi_text);
+use Texinfo::Structuring;
+use Texinfo::Convert::Texinfo;
+
+use Data::Dumper;
+
+ok(1);
+
+sub _get_in($)
+{
+ my $fragment = shift;
+
+ my $in = '@node Top
address@hidden top
+
address@hidden
+* chap1::
+* chap @code{in code} 2::
+* lone node::
+* (the manual)::
+
+'.$fragment.
+'
address@hidden menu
+
address@hidden
+* unnumbered1::
address@hidden menu
+
address@hidden chap1
address@hidden chap
+
address@hidden
+* sec0::
+* sec1:: D1
+ GGG
+
+Menu comment
+
+* label: sec2. D2
address@hidden menu
+
address@hidden sec0
address@hidden sec0
+
address@hidden
+* subsec::
address@hidden menu
+
address@hidden subsec
address@hidden sss
+
address@hidden sec1
address@hidden sec1
+
address@hidden sec2
address@hidden sec2
+
address@hidden chap @code{in code} 2, lone node, chap1, Top
address@hidden chapter @code{in code} 2
+
address@hidden
+* sec 2-0::
+* sec 2-1::
address@hidden menu
+
address@hidden sec 2-0
address@hidden sec 2-0
+
address@hidden sec 2-1
address@hidden sec 2-1
+
address@hidden lone node, chap1, unnumbered1, Top
+
address@hidden
+* inter node::
+* inter node 2::
address@hidden menu
+
address@hidden inter node
+
address@hidden inter node 2
+
address@hidden unnumbered1, , lone node, Top
address@hidden unnumbered1
+
address@hidden
+* sec un0:: D
+* sec un1::
+* (some no manual) sec::
address@hidden menu
+
address@hidden sec un0
address@hidden un0
+
address@hidden sec un1
address@hidden un1
+
+';
+return $in;
+}
+
+my $in_detailmenu = _get_in('@detailmenu
+* sec1::
address@hidden detailmenu');
+
+my $parser = Texinfo::Parser::parser();
+my $tree = $parser->parse_texi_text($in_detailmenu);
+my $master_menu = Texinfo::Structuring::do_master_menu($parser);
+my $out = Texinfo::Convert::Texinfo::convert($master_menu);
+
+my $reference = '@detailmenu
+ --- The Detailed Node Listing ---
+
+chap
+
+* sec0::
+* sec1:: D1
+ GGG
+* label: sec2. D2
+
+chapter @code{in code} 2
+
+* sec 2-0::
+* sec 2-1::
+
+lone node
+
+* inter node::
+* inter node 2::
+
+unnumbered1
+
+* sec un0:: D
+* sec un1::
+* (some no manual) sec::
address@hidden detailmenu
+';
+#print STDERR $out;
+is ($reference, $out, 'master menu');
+
+
+
- texinfo/tp Texinfo/Structuring.pm t/do_master_m...,
Patrice Dumas <=