NAME

Mojolicious::Plugin::Toto - A simple tab and object based site structure

SYNOPSIS

use Mojolicious::Lite;

plugin 'toto'
     => menu => $menu;

app->start;

OR use Mojolicious::Lite;

plugin 'toto'
     => nav => $nav,
        sidebar => $sidebar,
        tabs => $tabs;

app->start;

DESCRIPTION

This plugin provides a navigational structure and a default set of routes for a Mojolicious or Mojolicious::Lite app

The navigational structure is a slight variation of this example used by twitter's bootstrap :

http://twitter.github.com/bootstrap/examples/fluid.html

The plugin provides a sidebar, a nav bar, and also a row of tabs underneath the name of an object.

The row of tabs is an extension of BREAD or CRUD -- in a BREAD application, browse and add are operations on zero or many objects, while edit, add, and delete are operations on one object. In the toto structure, these two types of operations are distinguished by placing the former in the side nav bar, and the latter in a row of tabs underneath the object to which the action applies.

Additionally, a top nav bar contains menu items to take the user to a particular side bar.

HOW DOES IT WORK

After loading the toto plugin, the default layout is set to 'toto'.

Defaults routes are generated for every sidebar entry and tab entry.

The names of the routes are of the form "controller/action", where controller is both the controller class and the model class.

Templates in the directory templates/<controller>/<action>.html.ep will be used when they exist.

The stash values "object" and "tab" are set for each auto-generated route. Also "noun" is set as an alias to "object".

A version of twitter's bootstrap (<http://twitter.github.com/bootstrap>) is included in this distribution.

OPTIONS

In addition to "menu", "nav/sidebar/tabs", the following options are recognized :

prefix
prefix => /my/subpath

A prefix to prepend to the path for the toto routes.

model_namespace
model_namespace => "Myapp::Model'

A namespace for model classes : the model class will be camelized and appended to this.

EXAMPLE

Simple structure

The "menu" format can be used to automatically generate the nav bar, side bar and rows of tabs, using actions which correspond to many objects or actions which correspond to one object.

#!/usr/bin/env perl

use Mojolicious::Lite;

plugin 'toto' =>
     menu => [
        beer => {
            many => [qw/search browse/],
            one  => [qw/picture ingredients pubs/],
        },
        pub => {
            many => [qw/map list search/],
            one  => [qw/info comments/],
        }
    ];

app->start;

Complex structure

The "nav/sidebar/tabs" format can be used for a more versatile structure, in which the nav bar and side bar are less constrained.

use Mojolicious::Lite;

get '/my/url/to/list/beers' => sub {
     shift->render_text("Here is a page for listing beers.");
} => "beer/list";

get '/beer/create' => sub {
   shift->render_text("Here is a page to create a beer.");
} => "beer/create";

plugin 'toto' =>

     # top nav bar items
     nav => [
         'brewpub',          # Refers to a sidebar entry below
         'beverage'          # Refers to a sidebar entry below
     ],

     # possible sidebars, keyed on nav entries
     sidebar => {
       brewpub => [
           'brewery/phonelist',
           'brewery/mailing_list',
           'pub/search',
           'pub/map',
           'brewery',        # Refers to a "tab" entry below
           'pub',            # Refers to a "tab" entry below
       ],
       beverage =>
         [ 'beer/list',      # This will use the route defined above named "beer/list"
           'beer/create',
           'beer/search',
           'beer/browse',    # This will use the controller at the top (Beer::browse)
           'beer'            # Refers to a "tab" entry below
          ],
     },

     # possible rows of tabs, keyed on sidebar entries without a /
     tabs => {
       brewery => [ 'view', 'edit', 'directions', 'beers', 'info' ],
       pub     => [ 'view', 'info', 'comments', 'hours' ],
       beer    => [ 'view', 'edit', 'pictures', 'notes' ],
     };
;

app->start;

NOTES

To create pages outside of the toto framework, just set the layout to something other than "toto', e.g.

get '/no/toto' => { layout => 'default' } => ...

This module is experimental. The API may change without notice. Feedback is welcome!

AUTHOR

Brian Duggan bduggan@matatu.org

SEE ALSO

http://twitter.github.com/bootstrap/examples/fluid.html http://www.beer.dotcloud.com