diff --git a/guestbook-ng.pl b/guestbook-ng.pl index 0df94ca..22666ee 100755 --- a/guestbook-ng.pl +++ b/guestbook-ng.pl @@ -58,19 +58,23 @@ under sub ($c) { 1; }; +#get '/' => sub ($c) { +# my $this_page = $c->param('page') || 1; +# my $last_page = $c->message->get_last_page(); +# my $view_posts = $c->message->get_posts($this_page); +# +# $c->stash( +# view_posts => $view_posts, +# this_page => $this_page, +# last_page => $last_page +# ); +# +# $c->render(); +#} => 'index'; + get '/' => sub ($c) { - my $this_page = $c->param('page') || 1; - my $last_page = $c->message->get_last_page(); - my $view_posts = $c->message->get_posts($this_page); - - $c->stash( - view_posts => $view_posts, - this_page => $this_page, - last_page => $last_page - ); - - $c->render(); -} => 'index'; + $c->redirect_to('view'); +}; get '/spam' => sub ($c) { my $this_page = $c->param('page') || 1; @@ -143,7 +147,26 @@ group { $c->stash(view_post => @view_post); - #$c->render(text => "You've requested message number: $message_id"); + $c->render(); + }; +}; + +group { + under '/view'; + + get '/:page_number', {page_number => 1} => sub ($c) { + my $this_page = $c->param('page_number'); + my $last_page = $c->message->get_last_page('spam'); + my $view_posts = $c->message->get_spam($this_page); + my $base_path = $c->url_for(page_number => undef); + + $c->stash( + view_posts => $view_posts, + this_page => $this_page, + last_page => $last_page, + base_path => $base_path + ); + $c->render(); }; }; diff --git a/templates/page_number.html.ep b/templates/page_number.html.ep new file mode 100644 index 0000000..5f44489 --- /dev/null +++ b/templates/page_number.html.ep @@ -0,0 +1,29 @@ +% layout 'default'; +% title 'View'; +

Messages from the World Wide Web

+
+ <% for my $view_post (@$view_posts) { =%> +
+ + <%= link_to "#@$view_post[4]" => "/message/@$view_post[4]" %> + +

<%= @$view_post[0] %>

+
+

<%= @$view_post[2] %>

+
+
+

+ - <%= @$view_post[1] %> + <% if (@$view_post[3]) { =%> + (<%= link_to Homepage => @$view_post[3] %>) + <% } =%> +

+
+
+ <% } =%> +
+<% if ($last_page && $last_page != 1) { =%> + +<% } =%>