Commits

Shlomi Fish committed 0a09a63

Implement li_id for the non-JQTreeView navmenu.

Comments (0)

Files changed (4)

 Short-Term:
 -----------
 
-* Implement li_id for the non-JQueryTreeView tree.
-
 * Make sure H::W::NM will associate the breadcrumbs trail with a category,
 if this category expands there. So, for example:
 

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

 =head1 METHODS
 
 =cut
-
 sub _calc_open_li_tag
 {
     my $self = shift;
 
-    my $li_id = $self->top()->_li_id;
+    my $id_attr = $self->_calc_li_id_attr();
 
-    my $id_attr =
-        (defined ($li_id)
-            ? qq/ id="/ . escape_html($li_id) . qq/"/
-            : q//
-        );
     return
     (
         $self->_is_expanded_for_treeview()

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

     return 0;
 }
 
+sub _calc_li_id_attr
+{
+    my $self = shift;
+
+    my $li_id = $self->top()->_li_id;
+
+    return
+    (defined ($li_id)
+        ? qq/ id="/ . escape_html($li_id) . qq/"/
+        : q//
+    );
+}
+
 =head2 $self->gen_ul_tag({depth => $depth});
 
 Generate a UL tag of depth $depth.
 {
     my $self = shift;
     my $top_item = $self->top;
-    my @tags_to_add = ("<li>", $self->get_link_tag());
+    my @tags_to_add = (("<li" . $self->_calc_li_id_attr() . ">"),
+        $self->get_link_tag());
     if ($top_item->_num_subs_to_go() && $self->_is_expanded())
     {
         push @tags_to_add, ($self->get_open_sub_menu_tags());

module/t/04nav-menu.t

 
 use lib './t/lib';
 
-use Test::More tests => 29;
+use Test::More tests => 30;
 
 use HTML::Widgets::NavMenu;
 use HTML::Widgets::NavMenu::HeaderRole;
 EOF
 
     # TEST
-    test_nav_menu($rendered, $expected_string, "JQTreeView Nav Menu with Hidden Item");
+    test_nav_menu($rendered, $expected_string,
+        "JQTreeView Nav Menu with li_id");
 }
+
+# Test HTML::Widgets::NavMenu (non-JQueryTreeView) with li_id.
+{
+    my $nav_menu = HTML::Widgets::NavMenu->new(
+        'path_info' => "/me/",
+        @{$test_data->{'with_ids_nav_menu'}},
+        'ul_classes' => [ "one", "two", "three" ],
+    );
+
+    my $rendered =
+        $nav_menu->render();
+
+    my $expected_string = <<"EOF";
+<ul class="one">
+<li>
+<a href="../">Home</a>
+</li>
+<li id="about_me">
+<b>About Me</b>
+<br />
+<ul class="two">
+<li id="visible">
+<a href="visible/">Visible</a>
+</li>
+<li id="FooBar">
+<a href="visible-too/">Visible Too</a>
+</li>
+</ul>
+</li>
+</ul>
+EOF
+
+    # TEST
+    test_nav_menu($rendered, $expected_string,
+        "Non-JQTreeView Nav Menu with li_id");
+}