Skip to content

Commit

Permalink
add template and layout fields to documents
Browse files Browse the repository at this point in the history
This will allow documents to override the template and layout for a
document.

Refs #40
  • Loading branch information
preaction committed May 24, 2015
1 parent e23be13 commit 2b2fbf1
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
32 changes: 32 additions & 0 deletions lib/Statocles/Document.pm
Expand Up @@ -107,6 +107,38 @@ has date => (
predicate => 'has_date',
);

=attr template
A template override for this document.
=cut

has template => (
is => 'rw',
isa => Maybe[ArrayRef[Str]],
coerce => sub {
return $_[0] if ref $_[0];
return [ grep { $_ ne '' } split m{/}, $_[0] ];
},
predicate => 'has_template',
);

=attr layout
A layout override for this document.
=cut

has layout => (
is => 'rw',
isa => Maybe[ArrayRef[Str]],
coerce => sub {
return $_[0] if ref $_[0];
return [ grep { $_ ne '' } split m{/}, $_[0] ];
},
predicate => 'has_layout',
);

1;
__END__
Expand Down
6 changes: 6 additions & 0 deletions t/share/store/docs/template/basic.markdown
@@ -0,0 +1,6 @@
---
title: Template document
template: document/basic.html.ep
layout: site/basic.html.ep
---
This document has a template
6 changes: 6 additions & 0 deletions t/share/store/docs/template/leading-slash.markdown
@@ -0,0 +1,6 @@
---
title: Template (Slash) document
template: /document/slash.html.ep
layout: /site/slash.html.ep
---
This document has a template with a leading slash
18 changes: 18 additions & 0 deletions t/store/file/document.t
Expand Up @@ -87,6 +87,24 @@ my @exp_docs = (
content => "This document has multiple tags separated by commas\n",
),


Statocles::Document->new(
path => '/template/basic.markdown',
title => 'Template document',
content => "This document has a template\n",
template => [qw( document basic.html.ep )],
layout => [qw( site basic.html.ep )],
),

Statocles::Document->new(
path => '/template/leading-slash.markdown',
title => 'Template (Slash) document',
content => "This document has a template with a leading slash\n",
template => [qw( document slash.html.ep )],
layout => [qw( site slash.html.ep )],
),


);

my @ignored_docs = (
Expand Down

0 comments on commit 2b2fbf1

Please sign in to comment.