Skip to content

Commit

Permalink
Added all the default views
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Oct 1, 2015
1 parent 8550ea3 commit 6bdb9c6
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 6 deletions.
23 changes: 19 additions & 4 deletions Literature/lib/Literature.pm
Expand Up @@ -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;
19 changes: 19 additions & 0 deletions Literature/views/actor.tt
@@ -0,0 +1,19 @@
[% META title = 'Actor' %]

<h2>[% actor.name %]</h2>
[% IF actor.born OR actor.died %]
<p>[% 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 %]</p>
[% END %]
<p><a href="http://imdb.com/name/[% actor.imdb %]">[% actor.name %] on IMDB</a></p>
[% IF actor.actor_roles.size %]
<ul>
[% FOREACH r IN actor.actor_roles %]
<li>Played <a href="/characters/[% r.fictional_character.id %]">[% r.fictional_character.name %]</a> in
<a href="/productions/[% r.production.id %]">[% r.production.title %]</a> ([% r.production.made_by %] - [% r.production.year %])</li>
[% END %]
</ul>
[% ELSE %]
<p>No roles found.</p>
[% END %]
8 changes: 8 additions & 0 deletions Literature/views/actors.tt
@@ -0,0 +1,8 @@
[% # Provide a title -%]
[% META title = 'List of Actors' -%]

<ul>
[% FOREACH a IN actors.all.sort('name')-%]
<li><a href="/actors/[% a.id %]">[% a.name %]</a></li>
[% END -%]
</ul>
2 changes: 1 addition & 1 deletion Literature/views/authors.tt
@@ -1,5 +1,5 @@
<ul>
[% FOREACH author IN authors.all -%]
[% FOREACH author IN authors.all.sort('name') -%]
<li><a href="/authors/[% author.id %]">[% author.name %]</a></li>
[% END -%]
</ul>
31 changes: 31 additions & 0 deletions Literature/views/fictional_character.tt
@@ -0,0 +1,31 @@
[% META title = 'Character' %]

<h2>[% fictionalcharacter.name %]</h2>
[% IF fictionalcharacter.imdb %]<p><a href="http://imdb.com/character/[% fictionalcharacter.imdb %]">[% fictionalcharacter.name %] on IMDB</a></p>[% END %]
<h3>Appearances</h3>
[% IF fictionalcharacter.fictional_character_appearances.size %]
<ul>
[% FOR a IN fictionalcharacter.fictional_character_appearances %]
<li><a href="/works/[% a.work.id %]">[% a.work.title %]</a>
by
[% FOR au IN a.work.authors %]
<a href="/authors/[% au.id %]">[% au.name %]</a>
[% END %]
</li>
[% END %]
</ul>
[% ELSE %]
<p>No appearances found.</p>
[% END %]

<h3>Played By</h3>
[% IF fictionalcharacter.actor_roles.size %]
<ul>
[% FOR r IN fictionalcharacter.actor_roles %]
<li><a href="/actors/[% r.actor.id %]">[% r.actor.name %]</a> in
<a href="/productions/[% r.production.id %]">[% r.production.title %] ([% r.production.made_by %]
- [% r.production.year %])</a></li>
[% END %]
[% ELSE %]
<p>No-one</p>
[% END %]
8 changes: 8 additions & 0 deletions Literature/views/fictional_characters.tt
@@ -0,0 +1,8 @@
[% # Provide a title -%]
[% META title = 'List of Characters' -%]

<ul>
[% FOREACH ch IN fictional_characters.all.sort('name')-%]
<li><a href="/fictional_characters/[% ch.id %]">[% ch.name %]</a></li>
[% END -%]
</ul>
2 changes: 1 addition & 1 deletion Literature/views/index.tt
Expand Up @@ -4,7 +4,7 @@
<ul>
<li>By <a href="/authors/">author</a></li>
<li>By <a href="/works/">works</a></li>
<li>By <a href="/characters/">characters</a></li>
<li>By <a href="/fictional_characters/">characters</a></li>
<li>By <a href="/productions/">productions</a></li>
<li>By <a href="/actors/">actors</a></li>
</ul>
Expand Down
28 changes: 28 additions & 0 deletions Literature/views/production.tt
@@ -0,0 +1,28 @@
[% META title = 'Production' %]

<h2>[% production.title %]</h2>
<p>[% production.made_by %] [% production.year %]<p>
<p>Based on
<a href="/works/[% production.work.id %]">[% production.work.title %]</a> by
[% FOR a IN production.work.authors %]
<a href="/authors/[% a.id %]">[% a.name %]</a>
[% END %]</p>

<p><a href="http://imdb.com/title/[% production.imdb %]">[% production.title %] on IMDB</a></p>

<h3>Cast</h3>
[% IF production.actor_roles.size %]
<ul>
[% FOR a IN production.actor_roles %]
<li><a href="/actors/[% a.actor.id %]">[% a.actor.name %]</a>
as <a href="/fictional_characters/[% a.fictional_character.id %]">[% a.fictional_character.name %]</a></li>
[% END %]
</ul>
[% ELSE %]
<p>No cast found.</p>
[% END %]
<h3>Buy the DVD/BluRay</h3>
[% FOR p IN production.production_products %]
<iframe src="http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&bc1=FFFFFF&IS2=1&nou=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=davblog-21&o=2&p=8&l=as1&m=amazon&f=ifr&asins=[% p.asin %]" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
[% END %]

8 changes: 8 additions & 0 deletions Literature/views/productions.tt
@@ -0,0 +1,8 @@
[% # Provide a title -%]
[% META title = 'List of Productions' -%]
<ul>
[% FOREACH p IN productions.all.sort('title')-%]
<li><a href="/productions/[% p.id %]">[% p.title %]</a>
([% p.made_by %] - [% p.year %])</li>
[% END -%]
</ul>
28 changes: 28 additions & 0 deletions Literature/views/work.tt
@@ -0,0 +1,28 @@
[% META title = 'Work' %]

<h2>[% work.title %]</h2>
<p>By [% FOR a IN work.authors; '<a href="/authors/'; a.id; '">'; a.name; '</a> '; END %]</p>
<h3>Characters</h3>
[% IF work.fictional_character_appearances.size %]
<ul>
[% FOR ch IN work.fictional_character_appearances %]
<li><a href="/fictional_characters/[% ch.fictional_character.id %]">[% ch.fictional_character.name %]</a></li>
[% END %]
</ul>
[% ELSE %]
<p>No characters found.</p>
[% END %]
<h3>Productions</h3>
[% IF work.productions.size %]
<ul>
[% FOR p IN work.productions %]
<li><a href="/productions/[% p.id %]">[% p.made_by %] ([% p.year %])</a></li>
[% END %]
</ul>
[% ELSE %]
<p>No productions found</p>
[% END %]
<h3>Buy the Book</h3>
[% FOR p IN work.work_products %]
<iframe src="http://rcm-uk.amazon.co.uk/e/cm?lt1=_blank&bc1=FFFFFF&IS2=1&nou=1&bg1=FFFFFF&fc1=000000&lc1=0000FF&t=davblog-21&o=2&p=8&l=as1&m=amazon&f=ifr&asins=[% p.asin %]" style="width:120px;height:240px;" scrolling="no" marginwidth="0" marginheight="0" frameborder="0"></iframe>
[% END %]
13 changes: 13 additions & 0 deletions Literature/views/works.tt
@@ -0,0 +1,13 @@
[% # Provide a title -%]
[% META title = 'List of Works' -%]

<table>
<tr><th>Title</th><th>Author(s)</th></tr>
[% # Display each book in a table row %]
[% FOREACH work IN works.all.sort('title')-%]
<tr>
<td><a href="/works/[% work.id %]">[% work.title %]</a></td>
<td>[% FOREACH a IN work.authors; a.name; ' '; END %]</td>
</tr>
[% END -%]
</table>

0 comments on commit 6bdb9c6

Please sign in to comment.