Commits

Anonymous committed 8e8271b

Added the nav_links_obj return, which returns LeadingPath::Component
objects represtenting the navigation links and giving more information about
them.

Comments (0)

Files changed (3)

-* Write tests to test the methods that were extracted due to Petersen's 
-needs.
-
 * Return 'nav_links2' - a hash mapping rel links to objects similar to 
 the leading path ones.
+    - document it.
 
-* Convert the tests to use is_deeply from Test::More.
+* Create an API function for getting a relative URL.
 
 Long-Term:
 ----------

module/lib/HTML/Widgets/NavMenu.pm

     return {'tree' => $tree, 'current_coords' => $current_coords };
 }
 
-sub get_leading_path
+sub get_leading_path_of_coords
 {
     my $self = shift;
+
+    my (%args) = (@_);
     
     my @leading_path;
 
             };
 
         $iterator->find_node_by_coords(
-            $self->get_current_coords(),
+            $args{'coords'},
             $fill_leading_path_callback,
             );
     }
     return \@leading_path;
 }
 
+sub get_leading_path
+{
+    my $self = shift;
+    return $self->get_leading_path_of_coords(
+        'coords' => $self->get_current_coords()
+    );
+}
+
 sub render
 {
     my $self = shift;
     my $hosts = $self->{hosts};
 
     my %nav_links;
+    my %nav_links_obj;
 
     my %links_proto = 
         (
         }
         if (defined($coords))
         {
-            $nav_links{$link_rel} = $self->get_rel_url_from_coords($coords);
+            my $obj = 
+                $self->get_leading_path_of_coords(
+                    'coords' => $coords
+                )->[-1];
+            
+            $nav_links_obj{$link_rel} = $obj;
+            $nav_links{$link_rel} = $obj->direct_url();
         }
     }
 
             'html' => $html,
             'leading_path' => $self->get_leading_path(),
             'nav_links' => \%nav_links,
+            'nav_links_obj' => \%nav_links_obj,
         };
 }
 

module/t/03nav-links.t

 
 use strict;
 
-use Test::More tests => 6;
+use Test::More tests => 11;
 
 use HTML::Widgets::NavMenu;
 
     
     # TEST
     ok ((scalar(keys(%$nav_links)) == 1) && (exists($nav_links->{'next'})),
-        "Lack of Nav-Links in the First Page")
+        "Lack of Nav-Links in the First Page");
+
+    my $obj_nav_links = $rendered->{'nav_links_obj'};
+
+    my $next = $obj_nav_links->{'next'};
+
+    # TEST
+    is ($next->host(), "default", "Checking for \$next->host().");
+    # TEST
+    is ($next->label(), "About Me", "Checking for label()");
+    # TEST
+    is ($next->title(), "About Myself", "Checking for title()");
+    # TEST
+    is ($next->direct_url(), "./me/", "Checking for direct_url()");
+    # TEST
+    is ($next->host_url(), "me/", "Checking for host_url()");
 }
 
 # The purpose of this test is to check for up arrow leading from the middle