CatalystX-Menu-mcDropdown

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

examples/README
gitignore
inc/Module/Install.pm
inc/Module/Install/Base.pm
inc/Module/Install/Can.pm
inc/Module/Install/Fetch.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/CatalystX/Menu/mcDropdown.pm
Makefile.PL
MANIFEST			This list of files
MANIFEST.SKIP
META.yml
README
t/00-load.t
t/01-output.t
t/lib/script/testapp_server.pl
t/lib/script/testapp_test.pl
t/lib/TestApp.pm

META.yml  view on Meta::CPAN

  ExtUtils::MakeMaker: 6.42
  Test::More: 0
configure_requires:
  ExtUtils::MakeMaker: 6.42
distribution_type: module
generated_by: 'Module::Install version 0.87'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: CatalystX-Menu-mcDropdown
no_index:
  directory:
    - examples
    - inc
    - t
requires:
  Catalyst::Runtime: 0
  CatalystX::Menu::Tree: 0.02
  HTML::Element: 0
  HTML::Entities: 0
  MRO::Compat: 0
  perl: 5.8.0
resources:
  license: http://dev.perl.org/licenses/
version: 0.01

Makefile.PL  view on Meta::CPAN

use inc::Module::Install;

name 'CatalystX-Menu-mcDropdown';
all_from 'lib/CatalystX/Menu/mcDropdown.pm';

requires 'Catalyst::Runtime';
requires 'MRO::Compat';
requires 'HTML::Entities';
requires 'HTML::Element';
requires 'CatalystX::Menu::Tree', '0.02';
test_requires 'Test::More';

WriteAll();

README  view on Meta::CPAN

CatalystX::Menu::mcDropdown
===========================

INSTALLATION

To install this module type the following:

   perl Makefile.PL
   make
   make test
   make install

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

package CatalystX::Menu::mcDropdown;

use 5.008000;

use strict;
use warnings;
use Carp qw(croak);

use base 'CatalystX::Menu::Tree';

use HTML::Entities;
use HTML::Element;
use MRO::Compat;

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

=head1 NAME

CatalystX::Menu::mcDropdown - Generate HTML UL for a mcDropdown menu

=head1 SYNOPSIS

 package MyApp::Controller::Whatever;

 sub someaction :Local
 :MenuPath('Electronics/Computers')
 :MenuTitle('Computers')
 { ... }

 sub begin :Private {
     my ($self, $c) = @_;

     my $menu = CatalystX::Menu::mcDropdown->new(
        context => $c,
        menupath_attr => 'MenuPath',    # action attribute used to determin menu tree
        menutitle_attr => 'MenuTitle',  # action attribute that supplies menu text
        ul_id => 'menudata',            # <ul id="menudata"> ... </ul>
        ul_class => 'mcdropdown_menu',  # <ul id="menudata" class="mcdropdown_menu"> ... </ul>
                                        # NOTE: mcDropdown expects class="mcdropdown_menu" !
        top_order => [qw(Home * About)],    # Put Home and About on the ends,
                                            #  everything else in-between
        filter => sub {                     # Filter out actions we don't want in menu
            my ($c, %actions) = @_;
            return
                map {$_, $actions{$_}}
                grep {$actions{$_}->can_visit($c)}

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

actions for use as a mcDropdown menu.

mcDropdown menus: L<http://www.givainc.com/labs/mcdropdown_jquery_plugin.htm>

=head1 METHODS

=cut

=head2 C<new( $tree, %params )>

Takes a menu tree produced by Catalyst::Controller::Menutree (CatalystX::MenuTree)
and a list of key/value parameter pairs.

Params

=over

=item menupath_attr

Required (no validation)

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

Required

The mcDropdown menu plugin populates the menu options from the values of
the list itmes (for example: <li>Menu Option</li>).

=item ul_id

Required

The ID attribute to be applied to the outer HTML UL element.

=item ul_class

Required

The class attribute to be applied to the outer HTML UL element. mcDropdown requires
class = mcdropdown_menu.

=item top_order

A list of top level menu item labels. Menu items are sorted alphabetically by
default. top_order allows you to specify the order of one or more items. The
asterisk (*) inserts any menu items not listed in top_order.

=item add_nodes

Optional

A reference to an array of hash references. See the L</SYNOPSIS>.

=back

t/lib/TestApp/Controller/Root.pm  view on Meta::CPAN

package TestApp::Controller::Root;

use Moose;
BEGIN { extends 'Catalyst::Controller' }
use CatalystX::Menu::mcDropdown;
use Data::Dumper;

__PACKAGE__->config(namespace => q{});

my $frozen_tree = <<'EOF';
{
    'About us' => {
        'children' => {},
        'menutitle' => 'About us',
        'uri' => bless( do{\(my $o = 'http://localhost/about/us')}, 'URI::http' )

t/lib/TestApp/Controller/Root.pm  view on Meta::CPAN

                'uri' => bless( do{\(my $o = 'http://localhost/public')}, 'URI::http' )
            }
        }
    }
};
EOF

sub begin :Private {
    my ($self, $c) = @_;

    my $menu = CatalystX::Menu::mcDropdown->new(
        context => $c,
        ul_id => 'navlist',
        ul_class => 'mcdropdown_menu',
        menupath_attr => 'MenuPath',
        menutitle_attr => 'MenuTitle',
        top_order => [qw(Main * Help)],
        filter => sub {
            my ($c, %action) = @_;
            return
            map { $_, $action{$_} }
            grep { $action{$_}->name =~ /^(?:public|aboutus)$/ }
            keys %action;
        },
    );

    $c->stash->{menu} = $menu->output;
}

sub big_menu :Local {
    my ($self, $c) = @_;

    my $menu = CatalystX::Menu::mcDropdown->new(
        context => $c,
        ul_id => 'navlist',
        ul_class => 'mcdropdown_menu',
        menupath_attr => 'MenuPath',
        menutitle_attr => 'MenuTitle',
        #top_order => [qw(Main * Help)],
    );

    $c->res->body($menu->output);
}

sub index :Path :Args(0) {
    my ($self, $c) = @_;
}

t/lib/TestApp/Controller/Root.pm  view on Meta::CPAN

    $c->res->body($c->stash->{menu});
}

sub menu_in_div :Local {
    my ($self, $c) = @_;
    $c->res->body($c->stash->{menu_in_div});
}

sub accounts
:Local
:MenuPath(/Customer/Accounts)
:MenuTitle('Customer accounts')
{
    my ($self, $c) = @_;

    $c->res->body('customer accounts');
}

sub orders
:Local
:MenuPath(/Customer/Orders)
:MenuTitle('Customer orders')
{
    my ($self, $c) = @_;

    $c->res->body('customer orders');
}

sub public
:Local
:MenuPath(/Main/Public)
:MenuTitle('A public function')
{
    my ($self, $c) = @_;

    $c->res->body('public action');
}

sub aboutus
:Path(/about/us)
:MenuPath(/About us)
:MenuTitle('About us')
{
    my ($self, $c) = @_;
    $c->res->body('about us action');
}

1;



( run in 0.656 second using v1.01-cache-2.11-cpan-49f99fa48dc )