texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]


From: Gavin D. Smith
Date: Fri, 4 Aug 2023 08:16:19 -0400 (EDT)

branch: master
commit e8959274c17dc124fba353b3bd0f84f3fa12acd7
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Fri Aug 4 12:03:10 2023 +0100

    Move new_master_menu
    
    * tp/Texinfo/Transformations.pm
    * tp/Texinfo/Common.pm (new_master_menu): Move to Common.pm.
    * tp/t/do_master_menu.t: Update.
---
 ChangeLog                     |   8 +++
 tp/Texinfo/Common.pm          | 139 ++++++++++++++++++++++++++++++++++++++++++
 tp/Texinfo/Transformations.pm | 114 +---------------------------------
 tp/t/do_master_menu.t         |   4 +-
 4 files changed, 150 insertions(+), 115 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8fa9deddd7..1760d1acd4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-08-04  Gavin Smith <gavinsmith0123@gmail.com>
+
+       Move new_master_menu
+
+       * tp/Texinfo/Transformations.pm
+       * tp/Texinfo/Common.pm (new_master_menu): Move to Common.pm.
+       * tp/t/do_master_menu.t: Update.
+
 2023-08-04  Patrice Dumas  <pertusus@free.fr>
 
        * tp/texi2any.pl (set_translations_encoding): really pass argument.
diff --git a/tp/Texinfo/Common.pm b/tp/Texinfo/Common.pm
index 45b87298c1..c34f9eb3cf 100644
--- a/tp/Texinfo/Common.pm
+++ b/tp/Texinfo/Common.pm
@@ -1944,6 +1944,138 @@ sub _collect_commands_list_in_tree($$$)
   }
 }
 
+# NB duplicated from Texinfo::Transformations
+sub _normalized_entry_associated_internal_node($;$)
+{
+  my $entry = shift;
+  my $labels = shift;
+
+  foreach my $arg (@{$entry->{'contents'}}) {
+    if ($arg->{'type'} eq 'menu_entry_node') {
+      if (! $arg->{'extra'}->{'manual_content'}) {
+        my $normalized_entry_node = $arg->{'extra'}->{'normalized'};
+        if (defined($normalized_entry_node)) {
+          if ($labels) {
+            return ($normalized_entry_node, $labels->{$normalized_entry_node});
+          } else {
+            return ($normalized_entry_node, undef);
+          }
+        }
+      }
+      last;
+    }
+  }
+  return (undef, undef);
+}
+
+# used in Plaintext converter and tree transformations
+sub new_master_menu($$)
+{
+  my $self = shift;
+  my $labels = shift;
+  my $node = $labels->{'Top'};
+  return undef if (!defined($node));
+
+  my @master_menu_contents;
+  if ($node->{'extra'}
+      and $node->{'extra'}->{'menus'}
+      and scalar(@{$node->{'extra'}->{'menus'}})) {
+    foreach my $menu (@{$node->{'extra'}->{'menus'}}) {
+      foreach my $entry (@{$menu->{'contents'}}) {
+        if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
+          my ($normalized_entry_node, $node)
+               = _normalized_entry_associated_internal_node($entry, $labels);
+          if (defined($node) and $node->{'extra'}) {
+            push @master_menu_contents, _print_down_menus($node, $labels);
+          }
+        }
+      }
+    }
+  }
+  if (scalar(@master_menu_contents)) {
+    my $first_preformatted = $master_menu_contents[0]->{'contents'}->[0];
+    my $master_menu_title = Texinfo::Translations::gdt($self,
+                                      ' --- 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 Texinfo::Structuring::new_block_command(\@master_menu_contents, 
undef,
+                                                   'detailmenu');
+  } else {
+    return undef;
+  }
+}
+
+sub _print_down_menus($$);
+sub _print_down_menus($$)
+{
+  my $node = shift;
+  my $labels = shift;
+
+  my @master_menu_contents;
+
+  if ($node->{'extra'}->{'menus'} and scalar(@{$node->{'extra'}->{'menus'}})) {
+    my @node_children;
+    foreach my $menu (@{$node->{'extra'}->{'menus'}}) {
+      foreach my $entry (@{$menu->{'contents'}}) {
+        if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
+          push @master_menu_contents, Texinfo::Common::copy_tree($entry);
+          # gather node children to recursively print their menus
+          my ($normalized_entry_node, $node)
+               = _normalized_entry_associated_internal_node($entry, $labels);
+          if (defined($node) and $node->{'extra'}) {
+            push @node_children, $node;
+          }
+        }
+      }
+    }
+    if (scalar(@master_menu_contents)) {
+      # Prepend node title
+      my $node_title_contents;
+      if ($node->{'extra'}->{'associated_section'}
+          and $node->{'extra'}->{'associated_section'}->{'args'}
+          and $node->{'extra'}->{'associated_section'}->{'args'}->[0]
+          and 
$node->{'extra'}->{'associated_section'}->{'args'}->[0]->{'contents'}) {
+        $node_title_contents
+          = Texinfo::Common::copy_contents(
+                      
$node->{'extra'}->{'associated_section'}->{'args'}->[0]->{'contents'});
+      } else {
+        $node_title_contents
+           = 
Texinfo::Common::copy_contents($node->{'args'}->[0]->{'contents'});
+      }
+      my $menu_comment = {'type' => 'menu_comment', 'contents' => []};
+      $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];
+      }
+      unshift @master_menu_contents, $menu_comment;
+
+      # now recurse in the children
+      foreach my $child (@node_children) {
+        push @master_menu_contents, _print_down_menus($child, $labels);
+      }
+    }
+  }
+  return @master_menu_contents;
+}
+
+if (0) {
+  # it is needed to mark the translation as gdt is called like
+  # Texinfo::Translations::gdt($self, ' --- The Detailed Node Listing ---')
+  # and not like gdt(' --- The Detailed Node Listing ---')
+  gdt(' --- The Detailed Node Listing ---');
+}
+
+
+
 
 # functions useful for Texinfo tree transformations
 # and some tree transformations functions, mostly those
@@ -2918,6 +3050,13 @@ In tables, relate index entries preceding and following 
an
 entry with said item.  Reference one of them in the entry's
 C<entry_associated_element>.
 
+=item $detailmenu = new_master_menu($translations, $labels)
+X<C<new_master_menu>>
+
+Returns a detailmenu tree element formatted as a master node.
+I<$translations>, if defined, should be a L<Texinfo::Translations> object and
+should also hold customization information.
+
 =item $normalized_name = normalize_top_node_name($node_string)
 X<C<normalize_top_node_name>>
 
diff --git a/tp/Texinfo/Transformations.pm b/tp/Texinfo/Transformations.pm
index 5a314192a0..af89538400 100644
--- a/tp/Texinfo/Transformations.pm
+++ b/tp/Texinfo/Transformations.pm
@@ -522,71 +522,6 @@ sub complete_tree_nodes_missing_menu($;$)
   }
 }
 
-sub _print_down_menus($$);
-sub _print_down_menus($$)
-{
-  my $node = shift;
-  my $labels = shift;
-
-  my @master_menu_contents;
-
-  if ($node->{'extra'}->{'menus'} and scalar(@{$node->{'extra'}->{'menus'}})) {
-    my @node_children;
-    foreach my $menu (@{$node->{'extra'}->{'menus'}}) {
-      foreach my $entry (@{$menu->{'contents'}}) {
-        if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
-          push @master_menu_contents, Texinfo::Common::copy_tree($entry);
-          # gather node children to recursively print their menus
-          my ($normalized_entry_node, $node)
-               = _normalized_entry_associated_internal_node($entry, $labels);
-          if (defined($node) and $node->{'extra'}) {
-            push @node_children, $node;
-          }
-        }
-      }
-    }
-    if (scalar(@master_menu_contents)) {
-      # Prepend node title
-      my $node_title_contents;
-      if ($node->{'extra'}->{'associated_section'}
-          and $node->{'extra'}->{'associated_section'}->{'args'}
-          and $node->{'extra'}->{'associated_section'}->{'args'}->[0]
-          and 
$node->{'extra'}->{'associated_section'}->{'args'}->[0]->{'contents'}) {
-        $node_title_contents
-          = Texinfo::Common::copy_contents(
-                      
$node->{'extra'}->{'associated_section'}->{'args'}->[0]->{'contents'});
-      } else {
-        $node_title_contents
-           = 
Texinfo::Common::copy_contents($node->{'args'}->[0]->{'contents'});
-      }
-      my $menu_comment = {'type' => 'menu_comment', 'contents' => []};
-      $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];
-      }
-      unshift @master_menu_contents, $menu_comment;
-
-      # now recurse in the children
-      foreach my $child (@node_children) {
-        push @master_menu_contents, _print_down_menus($child, $labels);
-      }
-    }
-  }
-  return @master_menu_contents;
-}
-
-if (0) {
-  # it is needed to mark the translation as gdt is called like
-  # Texinfo::Translations::gdt($self, ' --- The Detailed Node Listing ---')
-  # and not like gdt(' --- The Detailed Node Listing ---')
-  gdt(' --- The Detailed Node Listing ---');
-}
-
 sub _normalized_entry_associated_internal_node($;$)
 {
   my $entry = shift;
@@ -610,46 +545,6 @@ sub _normalized_entry_associated_internal_node($;$)
   return (undef, undef);
 }
 
-sub new_master_menu($$)
-{
-  my $self = shift;
-  my $labels = shift;
-  my $node = $labels->{'Top'};
-  return undef if (!defined($node));
-
-  my @master_menu_contents;
-  if ($node->{'extra'}
-      and $node->{'extra'}->{'menus'}
-      and scalar(@{$node->{'extra'}->{'menus'}})) {
-    foreach my $menu (@{$node->{'extra'}->{'menus'}}) {
-      foreach my $entry (@{$menu->{'contents'}}) {
-        if ($entry->{'type'} and $entry->{'type'} eq 'menu_entry') {
-          my ($normalized_entry_node, $node)
-               = _normalized_entry_associated_internal_node($entry, $labels);
-          if (defined($node) and $node->{'extra'}) {
-            push @master_menu_contents, _print_down_menus($node, $labels);
-          }
-        }
-      }
-    }
-  }
-  if (scalar(@master_menu_contents)) {
-    my $first_preformatted = $master_menu_contents[0]->{'contents'}->[0];
-    my $master_menu_title = Texinfo::Translations::gdt($self,
-                                      ' --- 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 Texinfo::Structuring::new_block_command(\@master_menu_contents, 
undef,
-                                                   'detailmenu');
-  } else {
-    return undef;
-  }
-}
-
 # self is used to pass down a translatable object with customization
 # information for the gdt() call.
 sub regenerate_master_menu($$)
@@ -659,7 +554,7 @@ sub regenerate_master_menu($$)
   my $top_node = $labels->{'Top'};
   return undef if (!defined($top_node));
 
-  my $new_master_menu = new_master_menu($self, $labels);
+  my $new_master_menu = Texinfo::Common::new_master_menu($self, $labels);
   return undef if (!defined($new_master_menu)
                    or !$top_node->{'extra'}
                    or !$top_node->{'extra'}->{'menus'}
@@ -973,13 +868,6 @@ A simple menu has no I<menu_comment>, I<menu_entry> or 
I<menu_entry_description>
 container anymore, their content are merged directly in the menu in
 I<preformatted> container.
 
-=item $detailmenu = new_master_menu($translations, $labels)
-X<C<new_master_menu>>
-
-Returns a detailmenu tree element formatted as a master node.
-I<$translations>, if defined, should be a L<Texinfo::Translations> object and
-should also hold customization information.
-
 =item protect_hashchar_at_line_beginning($registrar, 
$customization_information, $tree)
 X<C<protect_hashchar_at_line_beginning>>
 
diff --git a/tp/t/do_master_menu.t b/tp/t/do_master_menu.t
index 9ea5153251..1f7ee8f4d7 100644
--- a/tp/t/do_master_menu.t
+++ b/tp/t/do_master_menu.t
@@ -130,7 +130,7 @@ my $parser_information = $parser->global_information();
 my $refs = $parser->internal_references_information();
 Texinfo::Structuring::associate_internal_references($registrar, $parser,
                                  $parser_information, $labels, $refs);
-my $master_menu = Texinfo::Transformations::new_master_menu($parser, $labels);
+my $master_menu = Texinfo::Common::new_master_menu($parser, $labels);
 my $out = Texinfo::Convert::Texinfo::convert_to_texinfo($master_menu);
 
 my $reference = '@detailmenu
@@ -175,7 +175,7 @@ $parser_information = $parser->global_information();
 $refs = $parser->internal_references_information();
 Texinfo::Structuring::associate_internal_references($registrar, $parser,
                                  $parser_information, $labels, $refs);
-$master_menu = Texinfo::Transformations::new_master_menu($parser, $labels);
+$master_menu = Texinfo::Common::new_master_menu($parser, $labels);
 $out = Texinfo::Convert::Texinfo::convert_to_texinfo($master_menu);
 is ($out, $reference, 'master menu no detailmenu');
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]