Commits

Anonymous committed 249e334

Nav-Menu:

Changed gen_site_map to return an array ref of tags instead of a string
of all the text. This was an API change.

Comments (0)

Files changed (5)

 * Write tests to test the url_type and rec_url_type of the leading path,
 and site map.
 
+* Fill in the documents at the root.
+
 * Write full documentation for the module.
 
 Long-Term:

module/lib/HTML/Widgets/NavMenu.pm

 
     my $iterator = $self->get_nav_menu_traverser();
     $iterator->traverse();
-    my $html = [ @{$iterator->{'html'}} ];
+    my $html = $iterator->get_results();
     
     my $hosts = $self->{hosts};
 
 =head2 $text = $nav_menu->gen_site_map()
 
 This function can be called to generate a site map based on the tree of
-contents. It returns a scalar containing all the text of the site map.
+contents. It returns a reference to an array containing the tags of the 
+site map.
 
 =head1 The Input Tree of Contents
 

module/lib/HTML/Widgets/NavMenu/Iterator/Base.pm

 {
     my $self = shift;
 
-    return join("", map { "$_\n" } @{$self->{'html'}});
+    return [ @{$self->{'html'}} ];
 }
 
 1;

module/lib/HTML/Widgets/NavMenu/Iterator/SiteMap.pm

+package HTML::Widgets::NavMenu::Iterator::SiteMap;
+
+use strict;
+use warnings;
+
+use base qw(HTML::Widgets::NavMenu::Iterator::Html);
+
+use CGI;
+
+sub start_root
+{
+    my $self = shift;
+    
+    $self->_add_tags("<ul>");
+}
+
+sub start_sep
+{
+}
+
+sub start_regular
+{
+    my $self = shift;
+
+    my $top_item = $self->top;
+    my $node = $self->top->node();
+
+    my $nav_menu = $self->{'nav_menu'};
+
+    $self->_add_tags("<li>");
+    my $tag = $self->get_a_tag();
+    my $title = $node->title();
+    if (defined($title))
+    {
+        $tag .= " - $title";
+    }
+    $self->_add_tags($tag);
+
+    if ($top_item->num_subs_to_go())
+    {
+        $self->_add_tags("<br />");
+        $self->_add_tags("<ul>");
+    }
+}
+
+sub end_sep
+{
+}
+
+sub is_expanded
+{
+    return 1;
+}
+
+1;

module/t/02site-map.t

 use HTML::Widgets::NavMenu;
 
 use HTML::Widgets::NavMenu::Test::Data;
+use HTML::Widgets::NavMenu::Test::Util;
 
 my $test_data = get_test_data();
 
+sub validate_site_map
+{
+    my $results = shift;
+    my $expected_string = shift;
+    
+    my @result = @$results;
+
+    my @expected = (split(/\n/, $expected_string));
+
+    return (compare_string_arrays(\@expected, \@result) == 0);
+}
+
 {
     my $nav_menu = HTML::Widgets::NavMenu->new(
         'path_info' => "hello/",
         @{$test_data->{'minimal'}},
     );
 
-    my $returned_text = $nav_menu->gen_site_map();
+    my $results = $nav_menu->gen_site_map();
     my $expected_text = <<"EOF";
 <ul>
 <li>
 </li>
 </ul>
 EOF
-    is($returned_text, $expected_text, "site_map #1"); # TEST
+
+    # TEST
+    ok (validate_site_map($results, $expected_text), 
+        "site_map #1");
 }
 
 {
         },
     );
 
-    my $returned_text = $nav_menu->gen_site_map();
+    my $results = $nav_menu->gen_site_map();
     my $expected_text = <<"EOF";
 <ul>
 <li>
 </li>
 </ul>
 EOF
-    is($returned_text, $expected_text, "site_map #2"); # TEST
+    # TEST
+    ok (validate_site_map($results, $expected_text), 
+        "site_map #2");
 }
 
 {
         @{$test_data->{'two_sites'}},
     );
 
-    my $returned_text = $nav_menu->gen_site_map();
+    my $results = $nav_menu->gen_site_map();
     my $expected_text = <<"EOF";
 <ul>
 <li>
 </li>
 </ul>
 EOF
-    is($returned_text, $expected_text, "site_map - complex"); # TEST
+    # TEST
+    ok (validate_site_map($results, $expected_text),
+        "site_map - complex");
 }
 
 # Now testing that the separator is safely skipped and does not generate
         },
     );
 
-    my $returned_text = $nav_menu->gen_site_map();
+    my $results = $nav_menu->gen_site_map();
     my $expected_text = <<"EOF";
 <ul>
 <li>
 </li>
 </ul>
 EOF
-    is($returned_text, $expected_text, "site_map - separator"); # TEST
-
-    
-
+    # TEST
+    ok (validate_site_map($results, $expected_text), 
+        "site_map - separator");
 }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.