CatalystX-Menu-Tree

 view release on metacpan or  search on metacpan

lib/CatalystX/Menu/Tree.pm  view on Meta::CPAN

package CatalystX::Menu::Tree;

use 5.008000;

use strict;
use warnings;
use MRO::Compat;

use vars qw($VERSION);
$VERSION = '0.02';

=head1 NAME

CatalystX::Menu::Tree - Generate Catalyst application menus

=head1 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',
        },
    ],
 );

=head1 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.

=head2 Menu Attributes

=over

=item menupath_attr

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.

=item menutitle_attr

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.

=back

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

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

=head1 METHODS

=cut

=head2 C<new( %params )>

Return an instance of this class.

Params

=over

=item context

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

=item menupath_attr

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

=item menutitle_attr

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.

=item namespaces

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

=item 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.

=item add_nodes

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



( run in 1.759 second using v1.01-cache-2.11-cpan-13bb782fe5a )