From 6bdb9c63e7fd0dea505d124c21eb9fdc4f8f02e6 Mon Sep 17 00:00:00 2001 From: Dave Cross Date: Thu, 1 Oct 2015 20:30:37 +0100 Subject: [PATCH] Added all the default views --- Literature/lib/Literature.pm | 23 +++++++++++++++--- Literature/views/actor.tt | 19 +++++++++++++++ Literature/views/actors.tt | 8 ++++++ Literature/views/authors.tt | 2 +- Literature/views/fictional_character.tt | 31 ++++++++++++++++++++++++ Literature/views/fictional_characters.tt | 8 ++++++ Literature/views/index.tt | 2 +- Literature/views/production.tt | 28 +++++++++++++++++++++ Literature/views/productions.tt | 8 ++++++ Literature/views/work.tt | 28 +++++++++++++++++++++ Literature/views/works.tt | 13 ++++++++++ 11 files changed, 164 insertions(+), 6 deletions(-) create mode 100644 Literature/views/actor.tt create mode 100644 Literature/views/actors.tt create mode 100644 Literature/views/fictional_character.tt create mode 100644 Literature/views/fictional_characters.tt create mode 100644 Literature/views/production.tt create mode 100644 Literature/views/productions.tt create mode 100644 Literature/views/work.tt create mode 100644 Literature/views/works.tt diff --git a/Literature/lib/Literature.pm b/Literature/lib/Literature.pm index a2bea24..83a8135 100644 --- a/Literature/lib/Literature.pm +++ b/Literature/lib/Literature.pm @@ -8,16 +8,31 @@ my $cfg = dancer_app->config; $cfg->{plugins}{DBIC}{default}{user} = $ENV{LIT_USER}; $cfg->{plugins}{DBIC}{default}{pass} = $ENV{LIT_PASS}; +my %resources = qw[ + actors Actor + authors Author + productions Production + works Work + fictional_characters FictionalCharacter +]; + +my $route_re = '/(' . join('|', keys %resources) . ')/'; +my $id_re = $route_re . '(\d+)'; + get '/' => sub { template 'index'; }; -get '/authors/' => sub { - template 'authors', { authors => resultset('Author') }; +get qr{^$route_re$} => sub { + my ($resource) = splat; + template $resource, + { $resource => resultset($resources{$resource}) }; }; -get '/authors/:id' => sub { - template 'author', { author => resultset('Author')->find(param('id')) }; +get qr{$id_re} => sub { + my ($resource, $id) = splat; + template substr($resource, 0, -1), + { lc $resources{$resource} => resultset($resources{$resource})->find($id) }; }; true; diff --git a/Literature/views/actor.tt b/Literature/views/actor.tt new file mode 100644 index 0000000..e95d5a2 --- /dev/null +++ b/Literature/views/actor.tt @@ -0,0 +1,19 @@ +[% META title = 'Actor' %] + +

[% actor.name %]

+[% IF actor.born OR actor.died %] +

[% IF actor.born %]Born: [% actor.born.strftime('%m %B %Y'); END -%] +[% IF actor.born AND actor.died %], [% END %] +[% IF actor.died %]Died: [% actor.died.strftime('%m %B %Y'); END %]

+[% END %] +

[% actor.name %] on IMDB

+[% IF actor.actor_roles.size %] + +[% ELSE %] +

No roles found.

+[% END %] diff --git a/Literature/views/actors.tt b/Literature/views/actors.tt new file mode 100644 index 0000000..bd1c40f --- /dev/null +++ b/Literature/views/actors.tt @@ -0,0 +1,8 @@ +[% # Provide a title -%] +[% META title = 'List of Actors' -%] + + diff --git a/Literature/views/authors.tt b/Literature/views/authors.tt index fe05d29..37ce22c 100644 --- a/Literature/views/authors.tt +++ b/Literature/views/authors.tt @@ -1,5 +1,5 @@ diff --git a/Literature/views/fictional_character.tt b/Literature/views/fictional_character.tt new file mode 100644 index 0000000..e1473dd --- /dev/null +++ b/Literature/views/fictional_character.tt @@ -0,0 +1,31 @@ +[% META title = 'Character' %] + +

[% fictionalcharacter.name %]

+[% IF fictionalcharacter.imdb %]

[% fictionalcharacter.name %] on IMDB

[% END %] +

Appearances

+[% IF fictionalcharacter.fictional_character_appearances.size %] + +[% ELSE %] +

No appearances found.

+[% END %] + +

Played By

+[% IF fictionalcharacter.actor_roles.size %] +