Skip to content

Instantly share code, notes, and snippets.

@memowe
Created April 12, 2010 23:50
Show Gist options
  • Save memowe/364140 to your computer and use it in GitHub Desktop.
Save memowe/364140 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojolicious::Lite;
ladder sub {
my $self = shift;
$self->stash( navi => {
index => { name => 'Index page', sort => 0 },
foo => { name => 'First page', sort => 1 },
bar => { name => 'Another page', sort => 2 },
});
return 1;
};
get '/:site' => [ site => qr/index|foo|bar|/ ] => sub {
my $self = shift;
$self->stash( active_page => $self->param('site') || 'index' );
} => 'site';
app->start;
__DATA__
@@ layouts/default.html.ep
<!doctype html><html>
<head><title>Yay!</title>
%== include 'style'
</head>
<body>
%== include 'navi'
%== content
</body>
</html>
@@ style.html.ep
<style type="text/css">
ul#navi a.active {
font-weight : bold;
color : #<%= sprintf '%x' => int rand 0xffffff %>;
</style>
@@ navi.html.ep
<ul id="navi">
% my @navi_keys = sort { $navi->{$a}{sort} <=> $navi->{$b}{sort} } keys %$navi;
% foreach my $site ( @navi_keys ) {
% my $class = $site eq $active_page ? ' class="active"' : '';
<li><a href="/<%== $site %>.html"<%== $class %>>
<%= $navi->{$site}{name} %>
</a></li>
% }
</ul>
@@ site.html.ep
% layout 'default';
<h1><%= $active_page %></h1>
<p>Hi, this is <em><%= $navi->{$active_page}{name} %></em></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment