summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-08-19 01:00:47 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-08-19 01:00:47 +0200
commit224bdfc68ee626995dbfec357be1268177d02cc9 (patch)
tree2047f1415650cafcf8fe482cd707498cbb79775c
parent867d3514e483231d51e5b0a409674cccf9b9e180 (diff)
Remove script, convert template from HTML::Template to Mojolicious .ep template
-rwxr-xr-xBuild.PL25
-rw-r--r--README13
-rwxr-xr-xbin/db-fakedisplay246
-rw-r--r--cgi/index.pl175
4 files changed, 160 insertions, 299 deletions
diff --git a/Build.PL b/Build.PL
deleted file mode 100755
index 747146d..0000000
--- a/Build.PL
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use Module::Build;
-
-Module::Build->new(
-
- build_requires => {
- 'Module::Build' => '0.36',
- },
- dist_name => 'db-fakedisplay',
- dist_version_from => 'bin/db-fakedisplay',
- license => 'unrestricted',
- requires => {
- 'perl' => '5.10.0',
- 'File::ShareDir' => 0,
- 'HTML::Template' => 0,
- 'List::Util' => 0,
- 'Travel::Status::DE::DeutscheBahn' => '0.04',
- },
- share_dir => 'share',
- sign => 1,
-
-)->create_build_script();
diff --git a/README b/README
index 9ca21a4..a42bcd0 100644
--- a/README
+++ b/README
@@ -7,16 +7,5 @@ Dependencies
------------
* perl >= 5.10
- * File::ShareDir
- * Module::Build >= 0.36
- * HTML::Template
+ * Mojolicious
* Travel::Status::DE::DeutscheBahn >= 0.04
-
-Installation
-------------
-
-$ perl Build.PL
-$ perl Build
-$ sudo perl Build install
-
-You can then run 'man db-fakedisplay' for more information
diff --git a/bin/db-fakedisplay b/bin/db-fakedisplay
deleted file mode 100755
index 3a3b0f9..0000000
--- a/bin/db-fakedisplay
+++ /dev/null
@@ -1,246 +0,0 @@
-#!/usr/bin/env perl
-
-use strict;
-use warnings;
-use 5.010;
-
-use File::ShareDir qw(dist_file);
-use Getopt::Long qw(:config no_ignore_case);
-use HTML::Template;
-use List::Util qw(first);
-use Travel::Status::DE::DeutscheBahn;
-
-our $VERSION = '0.00';
-
-my @params;
-my ( $station, @platforms );
-my $mode = 'single';
-my $template_file;
-my $template;
-
-GetOptions(
-
- 'h|help' => sub { show_help(0) },
- 'm|mode=s' => \$mode,
- 't|template=s' => \&handle_template,
- 'V|version' => sub { say "db-fakedisplay version ${VERSION}"; exit 0 },
-
-) or show_help(1);
-
-if ( $mode eq 'single' and not $template_file ) {
- $template_file = dist_file( 'db-fakedisplay', 'single-lcd.html' );
-}
-
-( $station, @platforms ) = @ARGV;
-$template_file //= dist_file( 'db-fakedisplay', 'multi-lcd.html' );
-$template = HTML::Template->new(
- filename => $template_file,
- loop_context_vars => 1
-);
-
-if ( not defined $station ) {
- show_help(1);
-}
-
-my $status = Travel::Status::DE::DeutscheBahn->new( station => $station );
-
-sub handle_template {
- my ( undef, $template_name ) = @_;
-
- if ( -e $template_name ) {
- $template_file = $template_name;
- }
- else {
- $template_file = dist_file( 'db-fakedisplay', $template_name );
- }
-
- return;
-}
-
-sub show_help {
- my ($exit_status) = @_;
-
- say 'Usage: db-fakedisplay [-t template] <station> [platforms ...]';
- say 'See also: man db-fakedisplay';
-
- exit $exit_status;
-}
-
-sub add_result {
- my ($result) = @_;
-
- push(
- @params,
- {
- time => $result->time,
- train => $result->train,
- via => [ map { { stop => $_ } } $result->route_interesting(3) ],
- destination => $result->destination,
- platform => ( split( / /, $result->platform ) )[0],
- info => $result->info,
- }
- );
-
- return;
-}
-
-if ( $mode eq 'single' ) {
- if ( not @platforms ) {
- for my $result ( $status->results ) {
- if ( $result->platform ~~ \@platforms ) {
- next;
- }
- push( @platforms, $result->platform );
- }
- @platforms = sort { $a <=> $b } @platforms;
- }
-
- for my $platform (@platforms) {
- my $result = first { $_->platform =~ m{ ^ $platform (?: \s | $ )}x }
- $status->results;
-
- if ( not defined $result ) {
- push( @params, { platform => $platform } );
- }
- else {
- add_result($result);
- }
- }
-}
-else {
- for my $result ( $status->results ) {
- add_result($result);
- }
-}
-
-$template->param(
- departures => \@params,
- version => $VERSION
-);
-
-say $template->output;
-
-__END__
-
-=head1 NAME
-
-db-fakedisplay - Show train departures, as seen on the displays on most main stations
-
-=head1 SYNOPSIS
-
-B<db-fakedisplay> [-t I<template>] I<station> [I<platforms ...>]
-
-=head1 VERSION
-
-version 0.00
-
-=head1 DESCRIPTION
-
-B<db-fakedisplay> outputs HTML showing the next departure for every
-I<platform> on I<station> on stdout. The HTML is styled to look like the LCDs
-installed on most (major) stations.
-
-If no I<platforms> were specified, B<db-fakedisplay> shows all platforms for
-which departures are reported.
-
-=head1 OPTIONS
-
-=over
-
-=item B<-t>, B<--template> B<single-lcd.html>|I<filename>
-
-Select template. Specify either a I<filename> or one of the templates shipped
-with B<db-fakedisplay> (right now only B<single-lcd.html> is available, which
-is also the default).
-
-=item B<-V>, B<--version>
-
-Show version information.
-
-=back
-
-=head1 TEMPLATES
-
-B<db-fakedisplay> uses HTML::Template(3pm) to create the display. In case you
-want to create a custom template, the following variables are available:
-
-=head2 departures
-
-This is a loop variable, use it with C<< <TMPL_LOOP departures> foo <TMPL_VAR
-bar> ... </TMPL_LOOP> >>.
-
-This loop runs once for each requested platform. Inside it, you can use the
-following variables:
-
-=over
-
-=item platform
-
-The platform from which the train departs
-
-=item time
-
-The departure time (I<HH>:I<MM>)
-
-=item train
-
-The train / line name, something like "RE 10111" or "S 1"
-
-=item via
-
-A loop variable. For each run, the B<stop> variable contains one of the
-interesting stops the train will pass on its route.
-
-By default, it runs three times.
-
-=item destination
-
-The train's destination
-
-=item info
-
-Additional information about the train, such as delays. Unset if no
-information is available (use C<< <TMPL_IF info> ... </TMPL_IF> >>).
-
-=item no-data
-
-Set if no departures were available for the requested platform.
-
-=back
-
-=head1 EXIT STATUS
-
-Zero.
-
-=head1 CONFIGURATION
-
-None.
-
-=head1 DEPENDENCIES
-
-=over
-
-=item * File::ShareDir(3pm)
-
-=item * HTML::Template(3pm)
-
-=item * Travel::Status::DE::DeutscheBahn(3pm)
-
-=back
-
-=head1 BUGS AND LIMITATIONS
-
-Unknown
-
-=head1 SEE ALSO
-
-There is some example output available at
-L<http://finalrewind.org/projects/db-fakedisplay/>.
-
-=head1 AUTHOR
-
-Copyright (C) 2011 by Daniel Friesel E<lt>derf@finalrewind.orgE<gt>
-
-=head1 LICENSE
-
- 0. You just DO WHAT THE FUCK YOU WANT TO.
diff --git a/cgi/index.pl b/cgi/index.pl
index 424f07c..69e4698 100644
--- a/cgi/index.pl
+++ b/cgi/index.pl
@@ -1,8 +1,6 @@
#!/usr/bin/env perl
use Mojolicious::Lite;
use Cache::File;
-use File::ShareDir qw(dist_file);
-use HTML::Template;
use Travel::Status::DE::DeutscheBahn;
our $VERSION = '0.00';
@@ -43,11 +41,7 @@ get '/:station' => sub {
my $self = shift;
my $station = $self->stash('station');
- my @params;
- my $template = HTML::Template->new(
- filename => dist_file( 'db-fakedisplay', 'multi-lcd.html' ),
- loop_context_vars => 1,
- );
+ my @departures;
my @results = get_results_for($station);
$self->stash( 'version', $VERSION );
@@ -59,23 +53,24 @@ get '/:station' => sub {
for my $result (@results) {
push(
- @params,
+ @departures,
{
- time => $result->time,
- train => $result->train,
- via => [ map { { stop => $_ } } $result->route_interesting(3) ],
+ time => $result->time,
+ train => $result->train,
+ via => [ $result->route_interesting(3) ],
destination => $result->destination,
platform => ( split( / /, $result->platform ) )[0],
info => $result->info,
}
);
}
- $template->param(
- departures => \@params,
- version => $VERSION
- );
- $self->render( text => $template->output );
+ $self->render(
+ 'multi',
+ departures => \@departures,
+ version => $VERSION,
+ title => "departures for ${station}"
+ );
};
get '/multi/:station' => sub {
@@ -143,3 +138,151 @@ v<%= $version %>
</div>
</body>
</html>
+
+
+@@ multi.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><%= $title %></title>
+ <meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"/>
+ <style type="text/css">
+
+ div.outer {
+ border: 0.2em solid #000066;
+ width: 55em;
+ }
+
+ div.display {
+ background-color: #0000ff;
+ color: white;
+ font-family: Sans-Serif;
+ font-weight: bold;
+ position: relative;
+ margin-bottom: 0;
+ margin-top: 0;
+ padding-top: 0;
+ padding-bottom: 0;
+ width: 55em;
+ height: 1.4em;
+ }
+
+ div.display div {
+ overflow: hidden;
+ position: absolute;
+ height: 100%;
+ }
+
+ div.time {
+ left: 0;
+ width: 6%;
+ font-size: 95%;
+ }
+
+ div.train {
+ left: 5%;
+ width: 9%;
+ background-color: white;
+ color: #0000ff;
+ font-size: 95%;
+ }
+
+ div.via {
+ left: 15%;
+ width: 35%;
+ }
+
+ div.via span {
+ margin-right: 0.4em;
+ font-size: 80%;
+ }
+
+ div.destination {
+ left: 50%;
+ width: 25%;
+ font-size: 120%;
+ }
+
+ div.platform {
+ left: 75%;
+ width: 5%;
+ }
+
+ div.info {
+ left: 80%;
+ width: 20%;
+ background-color: white;
+ color: #0000ff;
+ font-size: 80%;
+ line-height: 150%;
+ }
+
+ div.separator {
+ border-bottom: 0.1em solid #000066;
+ }
+
+ div.about {
+ text-align: right;;
+ font-family: Sans-Serif;
+ color: #666666;
+ }
+
+ div.about a {
+ color: #000066;
+ }
+
+ </style>
+</head>
+<body>
+
+<div class="outer">
+% my $i = 0;
+% for my $departure (@{$departures}) {
+% $i++;
+
+<div class="display <% if (($i % 2) == 0) { %> separator<% } %>">
+<div class="platform">
+%= $departure->{platform}
+</div>
+
+<div class="time">
+%= $departure->{time}
+</div>
+
+<div class="train">
+%= $departure->{train}
+</div>
+
+<div class="via">
+% my $via_max = @{$departure->{via}};
+% my $via_cur = 0;
+% for my $stop (@{$departure->{via}}) {
+% $via_cur++;
+<span><%= $stop %><% if ($via_cur < $via_max) { %> - <% } %></span>
+% }
+</div>
+
+<div class="destination">
+%= $departure->{destination}
+</div>
+
+% if ($departure->{info}) {
+<div class="info">
+%= $departure->{info}
+</div>
+% }
+
+</div> <!-- display -->
+
+% }
+
+</div> <!-- outer -->
+
+<div class="about">
+<a href="http://finalrewind.org/projects/db-fakedisplay/">db-fakedisplay</a>
+v<%= $version %>
+</div>
+
+</body>
+</html>