Dancer2-Plugin-Menu
view release on metacpan or search on metacpan
Revision history for Dancer2-Plugin-Menu
0.009 2018-11-20 04:41:24-05:00 America/New_York
- typo fixes to POD
- include route prefix in tests
- simplify menu_item code
0.008 2018-11-19 09:58:21-05:00 America/New_York
- improved performance with cache for html menus
- fix bug that could cause wrong menu item to get displayed
- improve tests
This is the Perl distribution Dancer2-Plugin-Menu.
Installing Dancer2-Plugin-Menu is straightforward.
## Installation with cpanm
If you have cpanm, you only need one line:
% cpanm Dancer2::Plugin::Menu
If it does not have permission to install modules to the current perl, cpanm
will automatically set up and install to a local::lib in your home directory.
See the local::lib documentation (https://metacpan.org/pod/local::lib) for
details on enabling it in your environment.
## Installing with the CPAN shell
Alternatively, if your CPAN shell is set up, you should just be able to do:
% cpan Dancer2::Plugin::Menu
## Manual installation
As a last resort, you can manually install it. Download the tarball, untar it,
install configure prerequisites (see below), then build it:
% perl Makefile.PL
% make && make test
Then install it:
* to run make, PHASE = build
* to use the module code itself, PHASE = runtime
* to run tests, PHASE = test
They can all be found in the "PHASE_requires" key of MYMETA.yml or the
"{prereqs}{PHASE}{requires}" key of MYMETA.json.
## Documentation
Dancer2-Plugin-Menu documentation is available as POD.
You can run `perldoc` from a shell to read the documentation:
% perldoc Dancer2::Plugin::Menu
For more information on installing Perl modules via CPAN, please see:
https://www.cpan.org/modules/INSTALL.html
# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012.
Changes
INSTALL
LICENSE
MANIFEST
META.json
META.yml
Makefile.PL
README
dist.ini
lib/Dancer2/Plugin/Menu.pm
t/00-use_ok.t
t/01-basic.t
t/Data.pm
t/environments/development.yml
t/environments/testing.yml
t/views/index.tt
t/views/layouts/experimental.tt
t/views/layouts/experimental.tt.tcc
t/views/layouts/main.tt
t/views/layouts/main.tt.tcc
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150005",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
"version" : 2
},
"name" : "Dancer2-Plugin-Menu",
"prereqs" : {
"configure" : {
"requires" : {
"ExtUtils::MakeMaker" : "0"
}
},
"runtime" : {
"requires" : {
"Dancer2" : "0.206000",
"Dancer2::Core::Hook" : "0",
"Test::More" : "0",
"Test::Most" : "0",
"Test::NoWarnings" : "0",
"Test::Output" : "0"
}
}
},
"release_status" : "stable",
"resources" : {
"bugtracker" : {
"web" : "https://github.com/sdondley/Dancer2-Plugin-Menu/issues"
},
"repository" : {
"type" : "git",
"url" : "git://github.com/sdondley/Dancer2-Plugin-Menu.git",
"web" : "https://github.com/sdondley/Dancer2-Plugin-Menu"
}
},
"version" : "0.009",
"x_generated_by_perl" : "v5.24.4",
"x_serialization_backend" : "Cpanel::JSON::XS version 3.0239"
}
Test::NoWarnings: '0'
Test::Output: '0'
configure_requires:
ExtUtils::MakeMaker: '0'
dynamic_config: 0
generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150005'
license: perl
meta-spec:
url: http://module-build.sourceforge.net/META-spec-v1.4.html
version: '1.4'
name: Dancer2-Plugin-Menu
requires:
Dancer2: '0.206000'
Dancer2::Core::Hook: '0'
Dancer2::Plugin: '0'
Data::Dumper: '0'
HTML::Element: '0'
MooX::HandlesVia: '0'
Storable: '0'
perl: '5.010'
strict: '0'
warnings: '0'
resources:
bugtracker: https://github.com/sdondley/Dancer2-Plugin-Menu/issues
repository: git://github.com/sdondley/Dancer2-Plugin-Menu.git
version: '0.009'
x_generated_by_perl: v5.24.4
x_serialization_backend: 'YAML::Tiny version 1.70'
Makefile.PL view on Meta::CPAN
use 5.010;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Automatically generate an HTML menu for your Dancer2 app",
"AUTHOR" => "Steve Dondley <s\@dondley.com>",
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0
},
"DISTNAME" => "Dancer2-Plugin-Menu",
"LICENSE" => "perl",
"MIN_PERL_VERSION" => "5.010",
"NAME" => "Dancer2::Plugin::Menu",
"PREREQ_PM" => {
"Dancer2" => "0.206000",
"Dancer2::Core::Hook" => 0,
"Dancer2::Plugin" => 0,
"Data::Dumper" => 0,
"HTML::Element" => 0,
"MooX::HandlesVia" => 0,
"Storable" => 0,
"strict" => 0,
"warnings" => 0
This archive contains the distribution Dancer2-Plugin-Menu,
version 0.009:
Automatically generate an HTML menu for your Dancer2 app
This software is copyright (c) 2018 by Steve Dondley.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
name = Dancer2-Plugin-Menu
author = Steve Dondley <s@dondley.com>
license = Perl_5
copyright_holder = Steve Dondley
copyright_year = 2018
[Repository]
;[Bugtracker]
;web = http://github.com/sdondley/%s/issues
[Git::NextVersion]
[GitHub::Meta]
lib/Dancer2/Plugin/Menu.pm view on Meta::CPAN
package Dancer2::Plugin::Menu;
$Dancer2::Plugin::Menu::VERSION = '0.009';
use 5.010; use strict; use warnings;
# ABSTRACT: Automatically generate an HTML menu for your Dancer2 app
use Storable 'dclone';
use Data::Dumper 'Dumper';
use HTML::Element;
use Dancer2::Plugin;
use MooX::HandlesVia;
use Dancer2::Core::Hook;
lib/Dancer2/Plugin/Menu.pm view on Meta::CPAN
}
1; # Magic true value
__END__
=pod
=head1 NAME
Dancer2::Plugin::Menu - Automatically generate an HTML menu for your Dancer2 app
=head1 VERSION
version 0.009
=head1 SYNOPSIS
In your app:
use Dancer2;
use Dancer2::Plugin::Menu;
menu_item(
{ title => 'My Parent Item', weight => 3 },
get 'path' => sub { template },
);
menu_item(
{ title => 'My Child1 Item', weight => 3 },
get 'path/menu1' => sub { template },
);
lib/Dancer2/Plugin/Menu.pm view on Meta::CPAN
C<path/menu1> route is visited:
<ul><li class="active">Path
<ul><li class="active">My Child1 Item</li>
<li>My Child2 Item</li>
</ul>
</ul>
=head1 DESCRIPTION
This module generates HTML for routes wrapped in the C<menu_item> keyword. Menu
items will be injected into the template wherever the C<E<lt>% menu %E<gt>> tag
is located. Child menu items are wrapped in C<E<lt>liE<gt>> HTML tags which are
themselves wrapped in a C<E<lt>ulE<gt>> tag associated with the parent menu
item. Menu items within the current route are given the C<active> class so they
can be styled.
The module is in early development stages and currently has few options. It has
not been heavily tested and there are likely bugs especially with dynamic paths
which are completely untested at this time. The module should work and be
adequate for simple menu structures, however.
=head2 KEYWORDS
=head3 menu_item( { [title => $str], [weight => $num] }, C<ROUTE METHOD> C<REGEXP>, C<CODE>)
Wraps a conventional route handler preceded by a required hash reference
containing data that will be applied to the route's endpoint.
Two keys can be supplied in the hash reference: a C<title> for the menu item and
a C<weight>. The C<title> will be used as the content for the menu items. The
C<weight> will determine the order of the menu items. Heavier items (with larger
values) will "sink" to the bottom compared to sibling menu items. If two sibling
menu items have the same weight, the menu items will be ordered alphabetically.
Menu items that are not endpoints in the route or that don't have a C<title>,
will automatically generate a title according to the path segment's name. For
example, the route C</categories/fun food/desserts> is converted to a hierarchy
of menu items entitled C<Categories>, C<Fun food>, and C<Desserts>. Note that
capitalization is automatically added. Automatic titles will be overridden with
endpoint specific titles if they are supplied in a later C<menu_item> call.
If the C<weight> is not supplied it will default to a value of C<5>.
=head1 CONFIGURATION
lib/Dancer2/Plugin/Menu.pm view on Meta::CPAN
=back
=for :stopwords cpan testmatrix url annocpan anno bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
=head1 SUPPORT
=head2 Perldoc
You can find documentation for this module with the perldoc command.
perldoc Dancer2::Plugin::Menu
=head2 Websites
The following websites have more information about this module, and may be of help to you. As always,
in addition to those websites please use your favorite search engine to discover more resources.
=over 4
=item *
MetaCPAN
A modern, open-source CPAN search engine, useful to view POD in HTML format.
L<https://metacpan.org/release/Dancer2-Plugin-Menu>
=back
=head2 Source Code
The code is open to the world, and available for you to hack on. Please feel free to browse it and play
with it, or whatever. If you want to contribute patches, please send me a diff or prod me to pull
from your repository :)
L<https://github.com/sdondley/Dancer2-Plugin-Menu>
git clone git://github.com/sdondley/Dancer2-Plugin-Menu.git
=head1 BUGS AND LIMITATIONS
You can make new bug reports, and view existing ones, through the
web interface at L<https://github.com/sdondley/Dancer2-Plugin-Menu/issues>.
=head1 INSTALLATION
See perlmodinstall for information and options on installing Perl modules.
=head1 SEE ALSO
L<Dancer2>
=head1 AUTHOR
t/00-use_ok.t view on Meta::CPAN
use strict;
use warnings;
use Test::More tests => 1;
BEGIN { use_ok('Dancer2::Plugin::Menu') }
t/01-basic.t view on Meta::CPAN
BEGIN {
$ENV{'DANCER_ENVIRONMENT'} = 'testing';
}
my $app_obj;
{
package MyApp;
use Dancer2;
use Dancer2::Plugin::Menu;
use Data::Dumper qw(Dumper);
get '/' => sub { return 'hi' };
menu_item(
{ title => 'Deep One', weight => 3 },
get '/test/snig/one/baloney pony/three' =>
sub { template 'index.tt', { html => 'booya' } }
);
menu_item( { title => 'My Menu Item', weight => 1 },
get '/test' => sub { template 'index.tt', { html => 'went_down' } } );
prefix '/test';
menu_item(
{ title => 'A Tom Tom', weight => 3 },
get '/snig' => sub { template }
);
menu_item(
{ title => 'Dinky', weight => 3 },
t/01-basic.t view on Meta::CPAN
'html menu in cache'
);
my @warnings = grep { $_->{Message} =~ /fallback to PP version/ }
&Test::NoWarnings::warnings;
&Test::NoWarnings::clear_warnings if @warnings == &Test::NoWarnings::warnings;
sub _dispatch_route {
my $path = shift;
my $app = Dancer2::Core::App->new();
$app->with_plugins('Menu');
$app->plugins->[0]->menu_item(
{ title => 'blah' },
$app->add_route(
method => 'get',
regexp => '/' . $path,
code => sub { $app->template( 'index.tt', shift ) }
)
);
my $req = Dancer2::Core::Request->new(
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://localhost/css/style.css">
<link rel="stylesheet" href="http://localhost/javascripts/jquery-ui-1.12.1.custom/jquery-ui.min.css">
</head>
<body>
booya
<ul>
<li class="active">My Menu Item<ul>
<li class="active">A Tom Tom<ul>
<li class="active">One<ul>
<li class="active">Baloney pony<ul>
<li class="active">Deep One</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://localhost/css/style.css">
<link rel="stylesheet" href="http://localhost/javascripts/jquery-ui-1.12.1.custom/jquery-ui.min.css">
</head>
<body>
went_down
<ul>
<li class="active">My Menu Item<ul>
<li class="">A Tom Tom<ul>
<li class="">One<ul>
<li class="">Baloney pony<ul>
<li class="">Deep One</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
( run in 1.460 second using v1.01-cache-2.11-cpan-49f99fa48dc )