From 2b2fbf129f3124b6644d57dd93e82c33313a9ef4 Mon Sep 17 00:00:00 2001 From: Doug Bell Date: Sun, 24 May 2015 16:50:17 -0500 Subject: [PATCH] add template and layout fields to documents This will allow documents to override the template and layout for a document. Refs #40 --- lib/Statocles/Document.pm | 32 +++++++++++++++++++ t/share/store/docs/template/basic.markdown | 6 ++++ .../docs/template/leading-slash.markdown | 6 ++++ t/store/file/document.t | 18 +++++++++++ 4 files changed, 62 insertions(+) create mode 100644 t/share/store/docs/template/basic.markdown create mode 100644 t/share/store/docs/template/leading-slash.markdown diff --git a/lib/Statocles/Document.pm b/lib/Statocles/Document.pm index 2101ce76..7739bc1f 100644 --- a/lib/Statocles/Document.pm +++ b/lib/Statocles/Document.pm @@ -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__ diff --git a/t/share/store/docs/template/basic.markdown b/t/share/store/docs/template/basic.markdown new file mode 100644 index 00000000..d259bea7 --- /dev/null +++ b/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 diff --git a/t/share/store/docs/template/leading-slash.markdown b/t/share/store/docs/template/leading-slash.markdown new file mode 100644 index 00000000..c3ad500c --- /dev/null +++ b/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 diff --git a/t/store/file/document.t b/t/store/file/document.t index b3450ab5..ad0bfa37 100644 --- a/t/store/file/document.t +++ b/t/store/file/document.t @@ -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 = (