NAME

CatalystX::Menu::Tree - Generate a menu tree from a Catalyst application's actions

SYNOPSIS

my $tree = CatalystX::Menu::Tree->new(
   context => $c,
   namespaces => [ $c->namespace ],
   filter => sub {
       my ($c, %action) = @_;
       # return the list of k/v pairs that meet criteria
   },
   menupath_attr => 'MenuPath',
   menutitle_attr => 'MenuTitle',
   add_nodes => [
       {
           menupath => '/Bargains'
           menutitle => 'Cheap stuff',
           uri => '/products/cheap',
       },
       {
           menupath => '/Returns'
           menutitle => 'Return a product',
           uri => '/products/returns',
       },
   ],
);

DESCRIPTION

Builds the tree used by CatalystX::Menu::Suckerfish to construct an HTML UL element for use as a degradable, CSS-styled menu or horizontal navbar.

Catalyst actions with the Private attribute are excluded from the tree.

Names the action attribute that contains the menu path:

menupath_attr => 'MenuPath'

# and in your controller:

sub foobar :Local
:MenuPath(/Foo/Bar)
:MenuTitle('Foobar and stuff')
{ ... }

Only actions with the menupath_attr attribute are processed. This attribute's value determines where the action's menu item is placed in the menu structure (HTML UL).

Depending on the attribute values collected from the processed actions, there may be menu items containing only text. If you want a link to a landing page, for example, instead of text, include an action for the landing page with the appropriate MenuPath attribute in your controller, or add an entry manually with the add_nodes parameter.

The menutitle_attr attribute will be used to add the HTML title attribute to each list item. This should result in a balloon text with the title when the pointing device hovers over each list item.

Suckerfish menus: http://www.alistapart.com/articles/dropdowns

Superfish jQuery menu plugin: http://users.tpg.com.au/j_birch/plugins/superfish/

METHODS

new( %params )

Return an instance of this class.

Params

context

The Catalyst application context (usually $c or $ctx in your controller).

The action attribute that contains the menu tree path to the menu item to be inserted for each action.

The action attribute that contains text describing each action. This text is applied as a "title" attribute to the menu item's HTML container so that a tooltip will be displayed when the pointer hovers over the menu item.

This text can be used anywhere in your application where a description of an action is useful.

namespaces

A reference to an array of action namespaces from which actions with the menupath_attr attribute should be collected.

filter

A reference to a subroutine that takes the Catalyst context and a hash of action name/action object and returns the name/action pairs that meet certain criteria.

add_nodes

A list of hash references containing data defining arbitrary menu items to be merged into the menu tree.

INTERNAL METHODS

_build_tree()

Create and store a reference to a hash containing a tree of menu data.

_get_actions()

Build a hash of Catalyst::Action objects.

AUTHOR

David P.C. Wollmann <converter42@gmail.com>

BUGS

This is brand new code, so use at your own risk.

COPYRIGHT & LICENSE

Copyright 2009 by David P.C. Wollmann

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.