| 1 | package Statocles::App::Role::Store; | ||||||||||
| 2 | 1 | our $VERSION = '0.099'; | |||||||||
| 3 | # ABSTRACT: Role for applications using files | ||||||||||
| 4 | |||||||||||
| 5 | #pod =head1 SYNOPSIS | ||||||||||
| 6 | #pod | ||||||||||
| 7 | #pod package MyApp; | ||||||||||
| 8 | #pod use Statocles::Base 'Class'; | ||||||||||
| 9 | #pod with 'Statocles::App::Role::Store'; | ||||||||||
| 10 | #pod | ||||||||||
| 11 | #pod around pages => sub { | ||||||||||
| 12 | #pod my ( $orig, $self, %options ) = @_; | ||||||||||
| 13 | #pod my @pages = $self->$orig( %options ); | ||||||||||
| 14 | #pod | ||||||||||
| 15 | #pod # ... Add/remove pages | ||||||||||
| 16 | #pod | ||||||||||
| 17 | #pod return @pages; | ||||||||||
| 18 | #pod }; | ||||||||||
| 19 | #pod | ||||||||||
| 20 | #pod =head1 DESCRIPTION | ||||||||||
| 21 | #pod | ||||||||||
| 22 | #pod This role provides some basic functionality for those applications that want | ||||||||||
| 23 | #pod to use L<store objects|Statocles::Store> to manage content with Markdown files. | ||||||||||
| 24 | #pod | ||||||||||
| 25 | #pod =cut | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | use Statocles::Base 'Role'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 1 | ▶ | use Statocles::Page::Document; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 1 | ▶ | use Statocles::Page::File; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 1 | with 'Statocles::App'; | |||||||||
| 31 | |||||||||||
| 32 | #pod =attr store | ||||||||||
| 33 | #pod | ||||||||||
| 34 | #pod The directory path or L<store object|Statocles::Store> containing this app's | ||||||||||
| 35 | #pod documents. Required. | ||||||||||
| 36 | #pod | ||||||||||
| 37 | #pod =cut | ||||||||||
| 38 | |||||||||||
| 39 | 1 | has store => ( | |||||||||
| 40 | is => 'ro', | ||||||||||
| 41 | isa => StoreType, | ||||||||||
| 42 | required => 1, | ||||||||||
| 43 | coerce => StoreType->coercion, | ||||||||||
| 44 | ); | ||||||||||
| 45 | |||||||||||
| 46 | #pod =method pages | ||||||||||
| 47 | #pod | ||||||||||
| 48 | #pod my @pages = $app->pages; | ||||||||||
| 49 | #pod | ||||||||||
| 50 | #pod Get all the pages for this application. Markdown documents are wrapped | ||||||||||
| 51 | #pod in L<Statocles::Page::Document> objects, and everything else is wrapped in | ||||||||||
| 52 | #pod L<Statocles::Page::File> objects. | ||||||||||
| 53 | #pod | ||||||||||
| 54 | #pod =cut | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub pages { | ||||||||
|
Subroutine
pages: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||
| 57 | 0 | my ( $self, %options ) = @_; | |||||||||
| 58 | 0 | my @pages; | |||||||||
| 59 | 0 | my $iter = $self->store->iterator; | |||||||||
| 60 | 0 | ▶ | while ( my $obj = $iter->() ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | if ( $obj->isa( 'Statocles::Document' ) ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | my $page_path = $obj->path.''; | |||||||||
| 64 | 0 | $page_path =~ s{[.]\w+$}{.html}; | |||||||||
| 65 | |||||||||||
| 66 | 0 | my %args = ( | |||||||||
| 67 | path => $page_path, | ||||||||||
| 68 | app => $self, | ||||||||||
| 69 | layout => $self->template( 'layout.html' ), | ||||||||||
| 70 | document => $obj, | ||||||||||
| 71 | ); | ||||||||||
| 72 | |||||||||||
| 73 | 0 | push @pages, Statocles::Page::Document->new( %args ); | |||||||||
| 74 | } | ||||||||||
| 75 | else { | ||||||||||
| 76 | # If there's a markdown file, don't keep the html file, since | ||||||||||
| 77 | # we'll be building it from the markdown | ||||||||||
| 78 | 0 | ▶ | if ( $obj->path =~ /[.]html$/ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | my $doc_path = $obj->path.""; | |||||||||
| 80 | 0 | $doc_path =~ s/[.]html$/.markdown/; | |||||||||
| 81 | 0 | ▶ | next if $self->store->has_file( $doc_path ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 0 | push @pages, Statocles::Page::File->new( | |||||||||
| 85 | app => $self, | ||||||||||
| 86 | path => $obj->path->stringify, | ||||||||||
| 87 | file_path => $self->store->path->child( $obj->path ), | ||||||||||
| 88 | ); | ||||||||||
| 89 | } | ||||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | return @pages; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | 1 | 1; | |||||||||
| 96 | |||||||||||
| 97 | __END__ | ||||||||||