[Jifty-commit] jifty branch, master, updated. c2cad37e19dd3d53cbf4c18eefa0a199cbfe0192

Jifty commits jifty-commit at lists.jifty.org
Tue Dec 29 20:39:53 EST 2009


The branch, master has been updated
       via  c2cad37e19dd3d53cbf4c18eefa0a199cbfe0192 (commit)
      from  33e8717694bae6e44b1778ab318c75b0cf26f7b4 (commit)

Summary of changes:
 lib/Jifty/Web/Menu.pm |   50 ++++++++++++++++++++++++++++++++----------------
 1 files changed, 33 insertions(+), 17 deletions(-)

- Log -----------------------------------------------------------------
commit c2cad37e19dd3d53cbf4c18eefa0a199cbfe0192
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Tue Dec 29 20:39:31 2009 -0500

    Refactor submenu rendering for more flexibility

diff --git a/lib/Jifty/Web/Menu.pm b/lib/Jifty/Web/Menu.pm
index 4db9dbd..79c7725 100644
--- a/lib/Jifty/Web/Menu.pm
+++ b/lib/Jifty/Web/Menu.pm
@@ -300,7 +300,8 @@ sub render_as_context_menu {
 =head2 render_as_hierarchical_menu_item
 
 Render an <li> for this item. suitable for use in a regular or contextual
-menu. Currently renders one level of submenu, if it exists.
+menu. Currently renders one level of submenu, if it exists, using
+L</render_submenu>.
 
 =cut
 
@@ -311,37 +312,52 @@ sub render_as_hierarchical_menu_item {
         @_
     );
     my @kids = $self->children;
-    my $web = Jifty->web;
-    my $id   = $web->serial;
+    my $web  = Jifty->web;
     $web->out( qq{<li class="toplevel }
             . ( $self->active ? 'active' : 'closed' ) .' '.($self->class||"").' '. qq{">}
             . qq{<span class="title">} );
     $web->out( $self->as_link );
     $web->out(qq{</span>});
     if (@kids) {
+        my $id = $web->serial;
         $web->out(
             qq{<span class="expand"><a href="#" onclick="Jifty.ContextMenu.hideshow('}
                 . $id
-                . qq{'); return false;">&nbsp;</a></span>}
-                . qq{<ul id="}
-                . $id
-                . qq{">} );
-        for (@kids) {
-            $web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
-
-            # We should be able to get this as a string.
-            # Either stringify the link object or output the label
-            # This is really icky. XXX TODO
-            $web->out( $_->as_link );
-            $web->out("</li>");
-        }
-        $web->out(qq{</ul>});
+                . qq{'); return false;">&nbsp;</a></span>} );
+        $self->render_submenu( id => $id );
     }
     $web->out(qq{</li>});
     '';
 
 }
 
+=head2 render_submenu
+
+Renders a <ul> for the children (but not descendants) of this menu object,
+suitable for use as part of a regular or contextual menu.  Called by
+L</render_as_hierarchical_menu_item>. You probably don't need to use this
+on it's own.
+
+=cut
+
+sub render_submenu {
+    my $self = shift;
+    my %args = ( id => '', @_ );
+
+    my $web = Jifty->web;
+    $web->out(qq(<ul id="$args{id}">));
+    for ($self->children) {
+        $web->out(qq{<li class="submenu }.($_->active ? 'active' : '' ).' '. ($_->class || "").qq{">});
+
+        # We should be able to get this as a string.
+        # Either stringify the link object or output the label
+        # This is really icky. XXX TODO
+        $web->out( $_->as_link );
+        $web->out("</li>");
+    }
+    $web->out(qq{</ul>});
+}
+
 =head2 render_as_classical_menu
 
 Render this menu with html markup as old classical mason menu. 

-----------------------------------------------------------------------


More information about the Jifty-commit mailing list