Skip to content

Commit

Permalink
use more mojo-y routing by name
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Oct 31, 2015
1 parent 2f80b38 commit 530f04e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/Galileo.pm
Expand Up @@ -187,7 +187,7 @@ sub startup {
my $r = $app->routes;

$r->any( '/' => sub { my $self = shift; $self->redirect_to( $self->home_page ) });
$r->any( '/page/:name' )->to('page#show');
$r->any( '/page/:name' )->to('page#show')->name('show_page');
$r->post( '/login' )->to('user#login');
$r->any( '/logout' )->to('user#logout');

Expand All @@ -197,7 +197,7 @@ sub startup {
});

$if_author->any( '/admin/menu' )->to('menu#edit');
$if_author->any( '/edit/:name' )->to('page#edit');
$if_author->any( '/edit/:name' )->to('page#edit')->name('edit_page');
$if_author->websocket( '/store/page' )->to('page#store');
$if_author->websocket( '/store/menu' )->to('menu#store');
$if_author->websocket( '/files/list' )->to('file#list');
Expand Down
4 changes: 2 additions & 2 deletions lib/Galileo/Page.pm
Expand Up @@ -11,8 +11,8 @@ sub show {
if ($page) {
$self->render( page => $page );
} else {
if ($self->session->{username}) {
$self->redirect_to("/edit/$name");
if ( $self->is_author ) {
$self->redirect_to(edit_page => name => $name);
} else {
$self->reply->not_found;
}
Expand Down
10 changes: 4 additions & 6 deletions lib/Galileo/files/templates/user_menu.html.ep
@@ -1,12 +1,10 @@
% my $user = session 'username';
% my $url = $self->tx->req->url;
% if ($user) {
% if (my $user = session 'username') {
<div class="well" style="padding: 8px 0;">
<ul class="nav nav-list" id="user-menu">
<li class="nav-header">Hello <%== $user %></li>
% if ( is_author($user) and $url =~ s{/page/}{/edit/} ) {
% if ( is_author($user) && current_route 'show_page' ) {
<li><a href="#" onclick="add_page()">Add New Page</a></li>
<li><a href="<%= $url %>">Edit This Page</a></li>
<li><a href="<%= url_for 'edit_page', name => stash('name') %>">Edit This Page</a></li>
% }
<li><a href="/admin/menu">Edit Nav Menu</a></li>
<li><a href="/logout">Log Out</a></li>
Expand Down Expand Up @@ -72,7 +70,7 @@

% } else {
<form class="well" method="post" action="/login" id="login">
<input type="hidden" name="from" value="<%= $url %>">
<input type="hidden" name="from" value="<%= $c->tx->req->url %>">
<input type="text" class="input-small" placeholder="Username" name="username">
<input type="password" class="input-small" placeholder="Password" name="password">
<input type="submit" class="btn" value="Sign In">
Expand Down

0 comments on commit 530f04e

Please sign in to comment.