Gluu fer the Wëëbb Part 1

Having been a fan of Mojolicious for a few years it is only reasonable that I pick it as the platform but this time instead of going with my usual default layout and architecture I wanted to give the Toto plugin a whirl.

This plug-in provides a bootstrap flavoured navigation framework. So you can get a nav bar running across the top one, a side bar for and a row a and also a row of tabs underneath each side bar.

Well out of the box with about 3 mins worth of install and a cut and paste from the PDO one gets this

toto_1.jpg

Ok that was painless it even gives you a little hint at what the controller is doing on the side for Toto newbies like me.

Well lets goes back a second and think what I need to display for my AD&D Moose stuff. Well I really just have two parts done so far,

  1. Create a Character and
  2. Display a Character

Well I think I have the display part down pat as I really just spew back what is already in some YAML files. So I will start with #2 as I think the default Toto will work fine and in a few mins I have this


 plugin 'toto' =>
        nav => [ qw{character} ],
        sidebar => {
            character => [ qw{character/list character/search character} ],
        },
        tabs => {
            character=> [qw/view edit delete/],
        };

and auto-majickally I get this

toto_2.jpg

So now I want a little more than that so lets see if I can get my list of 'Character' YAML files off the server and list them up.

So looking at the right hand hint window I think all I need to do is add in the route for this to this page so I gave this a try


get '/character/list' => sub {
my $self = shift;
my @files = glob("*.yml");
my $characters = [];
foreach my $file (@files){;
$file =~ s/.yml//g;
push(@{$characters},$file);
}
$self->stash(characters => $characters);

} => 'character/list';

Unfortunately that did not work as I get this in the log

[Wed Apr 16 22:18:38 2014] [debug] Template "character/list.html.ep" not found.
[Wed Apr 16 22:18:38 2014] [debug] Nothing has been rendered, expecting delayed

so it can't find the template, so I guess I will add that as well


__DATA__
@@ character/list.html.ep

You Characters are
<table>
% for (@$characters) {
<tr>
<td>
%= link_to 'character/view' => { key => $_ } => begin
%= $_
%= end
</td></tr>
% }
</table>

and now I get this

toto_3.jpg

close but I have lost the left nav bar??

Well a little more reading nothing! Well a good 45 mins later looking at the source and playing around a bit I stumbled upon it. Seems the top tabs needs a route as well and with the undocumented 'nav_item' directive I was able to fix it like this


get '/character/list' => { nav_item => 'character' } => sub {

and everything works

toto_4.jpg

Luckily I have about three years worth of experience with Mojo routes so it caught my eye quickly.

Well they did say in the ToDo

Document the autcomplete API.

1 Comment

s/.yml//g

should be

s/\.yml$//

Otherwise, if you have a file named 'myml.txt' it will be changed to '.txt'.

Leave a comment

About byterock

user-pic Long time Perl guy, a few CPAN mods allot of work on DBD::Oracle and a few YAPC presentations