summaryrefslogtreecommitdiff
path: root/cgi/index.pl
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-08-19 01:32:27 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-08-19 01:32:27 +0200
commitc30580e5297fdb94da44b6f13b101da00d59e925 (patch)
tree4db5c478e51bf6cc04c1c5b88ad458d174de632f /cgi/index.pl
parent224bdfc68ee626995dbfec357be1268177d02cc9 (diff)
Simplify template and request handling
Diffstat (limited to 'cgi/index.pl')
-rw-r--r--cgi/index.pl118
1 files changed, 45 insertions, 73 deletions
diff --git a/cgi/index.pl b/cgi/index.pl
index 69e4698..3f79200 100644
--- a/cgi/index.pl
+++ b/cgi/index.pl
@@ -25,29 +25,24 @@ sub get_results_for {
return @{$results};
}
-get '/' => sub {
+sub handle_request {
my $self = shift;
- my $station = $self->param('station');
+ my $station = $self->stash('station');
- $self->stash( 'version', $VERSION );
+ $self->stash( departures => [] );
+ $self->stash( title => 'db-fakedisplay' );
+ $self->stash( version => $VERSION );
if ( not $station ) {
- return $self->render;
+ $self->render('multi');
+ return;
}
- $self->redirect_to("/${station}");
-} => 'index';
-
-get '/:station' => sub {
- my $self = shift;
- my $station = $self->stash('station');
my @departures;
my @results = get_results_for($station);
- $self->stash( 'version', $VERSION );
-
if ( not @results ) {
- $self->render( 'index', error => "Got no results for '$station'", );
+ $self->render( 'multi', error => "Got no results for '$station'" );
return;
}
@@ -71,75 +66,22 @@ get '/:station' => sub {
version => $VERSION,
title => "departures for ${station}"
);
-};
+}
-get '/multi/:station' => sub {
+get '/_redirect' => sub {
my $self = shift;
- my $station = $self->stash('station');
+ my $station = $self->param('station');
$self->redirect_to("/${station}");
};
+get '/' => \&handle_request;
+get '/:station' => \&handle_request;
+get '/multi/:station' => \&handle_request;
+
app->start();
__DATA__
-@@ index.html.ep
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
-<head>
- <title>DB Fakedisplay</title>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
- <style type="text/css">
-
-body {
- font-family: Sans-Serif;
-}
-
-p.about {
- color: #666666;
-}
-
-p.about a {
- color: #000066;
- text-decoration: none;
-}
-
- </style>
-</head>
-<body>
-<div>
-<p>
-DB-Fakedisplay displays the next departures at a DB station, just like the big
-LC display in the station itself.
-</p>
-
-<% if (my $error = stash 'error') { %>
- Error: <%= $error %><br/>
-<% } %>
-<%= form_for index => begin %>
-<p>
- Station name:<br/>
- <%= text_field 'station' %><br/>
- <%= submit_button 'Display' %>
-</p>
-<% end %>
-
-<p>
-(For example: "Koeln Hbf" or "Essen West")
-</p>
-
-<p class="about">
-This is <a
-href="http://finalrewind.org/projects/db-fakedisplay/">db-fakedisplay</a>
-v<%= $version %>
-</p>
-
-</div>
-</body>
-</html>
-
-
@@ multi.html.ep
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@@ -236,6 +178,8 @@ v<%= $version %>
</head>
<body>
+% if (@{$departures}) {
+
<div class="outer">
% my $i = 0;
% for my $departure (@{$departures}) {
@@ -279,6 +223,34 @@ v<%= $version %>
</div> <!-- outer -->
+% }
+% else {
+
+<p>
+DB-Fakedisplay displays the next departures at a DB station, just like the big
+LC display in the station itself.
+</p>
+
+% }
+
+<div class="input-field">
+
+<% if (my $error = stash 'error') { %>
+<p>
+ Error: <%= $error %><br/>
+</p>
+<% } %>
+
+<%= form_for _redirect => begin %>
+<p>
+ Station name:
+ <%= text_field 'station' %>
+ <%= submit_button 'Display' %>
+</p>
+<% end %>
+
+</div>
+
<div class="about">
<a href="http://finalrewind.org/projects/db-fakedisplay/">db-fakedisplay</a>
v<%= $version %>