Skip to content

Commit

Permalink
remove all uses of document in templates
Browse files Browse the repository at this point in the history
The only reason to use the document is for something that is not
normally part of a page, like extra data.

Fixes #220
  • Loading branch information
preaction committed Jan 19, 2015
1 parent 059d0d6 commit 7b647f2
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 52 deletions.
26 changes: 26 additions & 0 deletions lib/Statocles/Page/Document.pm
Expand Up @@ -18,6 +18,32 @@ has document => (
required => 1,
);

=attr title
The title of the page.
=cut

has title => (
is => 'ro',
isa => Str,
lazy => 1,
default => sub { $_[0]->document->title },
);

=attr author
The author of the page.
=cut

has author => (
is => 'ro',
isa => Str,
lazy => 1,
default => sub { $_[0]->document->author },
);

=attr tags
The tag links for this document. An array of L<link objects|Statocles::Link>. The
Expand Down
15 changes: 7 additions & 8 deletions share/theme/default/blog/index.atom.ep
Expand Up @@ -7,20 +7,19 @@
<link rel="alternate" href="<%= $site->url( $self->page->path ) %>"/>
<generator version="<%= $Statocles::VERSION %>">Statocles</generator>
% for my $p ( @$pages ) {
% my $doc = $p->document;
<entry>
<id><%= $site->url( $p->path ) %></id>
<title><%= $doc->title %></title>
<author><name><%= $doc->author %></name></author>
<title><%= $p->title %></title>
<author><name><%= $p->author %></name></author>
<link rel="alternate" href="<%= $site->url( $p->path ) %>" />
<content type="html"><![CDATA[
% my @sections = $p->sections;
<%= $sections[0] %>
% if ( $doc->links->{crosspost} ) {
% if ( $p->links( 'crosspost' ) ) {
<ul>
% for my $link ( @{ $doc->links->{crosspost} } ) {
<li><a href="<%= $link->{href} %>">
Continue reading <em><%= $doc->title %></em> on <%= $link->{title} %>...
% for my $link ( $p->links( 'crosspost' ) ) {
<li><a href="<%= $link->href %>">
Continue reading <em><%= $p->title %></em> on <%= $link->title %>...
</a></li>
% }
<li><a href="<%= $site->url( $p->path ) %>#section-2">
Expand All @@ -38,7 +37,7 @@
</p>
]]></content>
<updated><%= $p->published->strftime('%Y-%m-%dT%H:%M:%SZ') %></updated>
% for my $t ( $doc->tags ) {
% for my $t ( $p->tags ) {
<category term="<%= $t %>" />
% }
</entry>
Expand Down
15 changes: 7 additions & 8 deletions share/theme/default/blog/index.html.ep
Expand Up @@ -5,10 +5,9 @@
<main>

% for my $page ( @$pages ) {
% my $doc = $page->document;
<article>
<header>
<h1><a href="<%= $page->path %>"><%= $doc->title %></a></h1>
<h1><a href="<%= $page->path %>"><%= $page->title %></a></h1>

<p class="tags">Tags:
% for my $tag ( $page->tags ) {
Expand All @@ -20,14 +19,14 @@
<p><time datetime="<%= $page->published->strftime('%Y-%m-%d') %>">
Posted on <%= $page->published->strftime('%Y-%m-%d') %>
</time>
by <%= $doc->author %></p>
by <%= $page->author %></p>
</aside>

% if ( $doc->links->{crosspost} ) {
% if ( $page->links( 'crosspost' ) ) {
<p>Originally posted as:
% for my $link ( @{ $doc->links->{crosspost} } ) {
<a href="<%= $link->{href} %>">
<em><%= $doc->title %></em> on <%= $link->{title} %>.
% for my $link ( $page->links( 'crosspost' ) ) {
<a href="<%= $link->href %>">
<em><%= $page->title %></em> on <%= $link->title %>.
</a>
% }
</p>
Expand All @@ -38,7 +37,7 @@
<%= $sections[0] %>

% if ( @sections > 1 ) {
<p><a href="<%= $page->path %>#section-2">Continue reading <%= $doc->title %>...</a></p>
<p><a href="<%= $page->path %>#section-2">Continue reading <%= $page->title %>...</a></p>
% }

</article>
Expand Down
11 changes: 5 additions & 6 deletions share/theme/default/blog/index.rss.ep
Expand Up @@ -12,19 +12,18 @@
<description>Blog feed of <%= $site->title %></description>
<generator>Statocles <%= $Statocles::VERSION %></generator>
% for my $p ( @$pages ) {
% my $doc = $p->document;
<item>
<title><%= $doc->title %></title>
<title><%= $p->title %></title>
<link><%= $site->url( $p->path ) %></link>
<guid><%= $site->url( $p->path ) %></guid>
<description><![CDATA[
% my @sections = $p->sections;
<%= $sections[0] %>
% if ( $doc->links->{crosspost} ) {
% if ( $p->links( 'crosspost' ) ) {
<ul>
% for my $link ( @{ $doc->links->{crosspost} } ) {
<li><a href="<%= $link->{href} %>">
Continue reading <em><%= $doc->title %></em> on <%= $link->{title} %>...
% for my $link ( $p->links( 'crosspost' ) ) {
<li><a href="<%= $link->href %>">
Continue reading <em><%= $p->title %></em> on <%= $link->title %>...
</a></li>
% }
<li><a href="<%= $site->url( $p->path ) %>#section-2">
Expand Down
12 changes: 6 additions & 6 deletions share/theme/default/blog/post.html.ep
Expand Up @@ -3,7 +3,7 @@
<div class="nine columns">
<main>
<header>
<h1><%= $doc->title %></h1>
<h1><%= $self->title %></h1>
<p class="tags">Tags:
% for my $tag ( $self->tags ) {
<a href="<%= $tag->href %>" rel="tag"><%= $tag->text %></a>
Expand All @@ -13,13 +13,13 @@
<p><time datetime="<%= $self->published->strftime('%Y-%m-%d') %>">
Posted on <%= $self->published->strftime('%Y-%m-%d') %>
</time>
by <%= $doc->author %></p>
by <%= $self->author %></p>
</aside>
% if ( $doc->links->{crosspost} ) {
% if ( $self->links( 'crosspost' ) ) {
<p>Originally posted as:
% for my $link ( @{ $doc->links->{crosspost} } ) {
<a class="alert-link" href="<%= $link->{href} %>">
<em><%= $doc->title %></em> on <%= $link->{title} %>.
% for my $link ( $self->links( 'crosspost' ) ) {
<a class="alert-link" href="<%= $link->href %>">
<em><%= $self->title %></em> on <%= $link->title %>.
</a>
% }
</p>
Expand Down
15 changes: 7 additions & 8 deletions t/share/theme/blog/index.atom.ep
Expand Up @@ -8,23 +8,22 @@
<generator version="<%= $Statocles::VERSION %>">Statocles</generator>

% for my $p ( @$pages ) {
% my $doc = $p->document;
<entry>

<id><%= $site->url( $p->path ) %></id>
<title><%= $doc->title %></title>
<author><name><%= $doc->author %></name></author>
<title><%= $p->title %></title>
<author><name><%= $p->author %></name></author>
<link rel="alternate" href="<%= $site->url( $p->path ) %>" />
<updated><%= $p->published->strftime('%Y-%m-%dT%H:%M:%SZ') %></updated>

<content type="html"><![CDATA[
% my @sections = $p->sections;
<%= $sections[0] %>
% if ( $doc->links->{crosspost} ) {
% if ( $p->links( 'crosspost' ) ) {
<ul>
% for my $link ( @{ $doc->links->{crosspost} } ) {
<li><a href="<%= $link->{href} %>">
Continue reading <em><%= $doc->title %></em> on <%= $link->{title} %>...
% for my $link ( $p->links( 'crosspost' ) ) {
<li><a href="<%= $link->href %>">
Continue reading <em><%= $p->title %></em> on <%= $link->title %>...
</a></li>
% }
<li><a href="<%= $site->url( $p->path ) %>#section-2">
Expand All @@ -42,7 +41,7 @@
</p>
]]></content>

% for my $t ( $doc->tags ) {
% for my $t ( $p->tags ) {
<category term="<%= $t %>" />
% }
</entry>
Expand Down
7 changes: 3 additions & 4 deletions t/share/theme/blog/index.html.ep
@@ -1,13 +1,12 @@
% for my $page ( @$pages ) {
<article>
% my $doc = $page->document;
<h1><a href="<%= $page->path %>"><%= $doc->title %></a></h1>
<span class="author"><%= $doc->author %></span>
<h1><a href="<%= $page->path %>"><%= $page->title %></a></h1>
<span class="author"><%= $page->author %></span>
<div class="content">
% my @sections = $page->sections;
<%= $sections[0] %>
% if ( @sections > 1 ) {
<p><a href="<%= $page->path %>#section-2">Continue reading <%= $doc->title %>...</a></p>
<p><a href="<%= $page->path %>#section-2">Continue reading <%= $page->title %>...</a></p>
% }
</div>
</article>
Expand Down
11 changes: 5 additions & 6 deletions t/share/theme/blog/index.rss.ep
Expand Up @@ -12,19 +12,18 @@
<description>Blog feed of <%= $site->title %></description>
<generator>Statocles <%= $Statocles::VERSION %></generator>
% for my $p ( @$pages ) {
% my $doc = $p->document;
<item>
<title><%= $doc->title %></title>
<title><%= $p->title %></title>
<link><%= $site->url( $p->path ) %></link>
<guid><%= $site->url( $p->path ) %></guid>
<description><![CDATA[
% my @sections = $p->sections;
<%= $sections[0] %>
% if ( $doc->links->{crosspost} ) {
% if ( $p->links( 'crosspost' ) ) {
<ul>
% for my $link ( @{ $doc->links->{crosspost} } ) {
<li><a href="<%= $link->{href} %>">
Continue reading <em><%= $doc->title %></em> on <%= $link->{title} %>...
% for my $link ( $p->links( 'crosspost' ) ) {
<li><a href="<%= $link->href %>">
Continue reading <em><%= $p->title %></em> on <%= $link->title %>...
</a></li>
% }
<li><a href="<%= $site->url( $p->path ) %>#section-2">
Expand Down
12 changes: 6 additions & 6 deletions t/share/theme/blog/post.html.ep
@@ -1,6 +1,6 @@
<main>
<header>
<h1><%= $doc->title %></h1>
<h1><%= $self->title %></h1>

<p class="tags">Tags:
% for my $link ( $self->tags ) {
Expand All @@ -12,16 +12,16 @@
<p><time datetime="<%= $self->published->strftime('%Y-%m-%d') %>">
Posted on <%= $self->published->strftime('%Y-%m-%d') %>
</time>
by <span class="author"><%= $doc->author %></span></p>
by <span class="author"><%= $self->author %></span></p>
</aside>

% if ( $doc->links->{crosspost} ) {
% if ( $self->links( 'crosspost' ) ) {
<div class="alert alert-info crosspost">
<p>Originally posted as:</p>
<ul>
% for my $link ( @{ $doc->links->{crosspost} } ) {
<li><a class="alert-link" href="<%= $link->{href} %>">
<em><%= $doc->title %></em> on <%= $link->{title} %>.
% for my $link ( $self->links( 'crosspost' ) ) {
<li><a class="alert-link" href="<%= $link->href %>">
<em><%= $self->title %></em> on <%= $link->title %>.
</a></li>
% }
</ul>
Expand Down

0 comments on commit 7b647f2

Please sign in to comment.