File Coverage

blib/lib/App/Embra/Plugin/Sitemap.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 4 50.0
condition n/a
subroutine 10 10 100.0
pod n/a
total 44 46 95.6


line stmt bran cond sub pod time code
1 3     3   4196 use strict;
  3         6  
  3         153  
2 3     3   15 use warnings;
  3         4  
  3         163  
3              
4             package App::Embra::Plugin::Sitemap;
5             $App::Embra::Plugin::Sitemap::VERSION = '0.001'; # TRIAL
6             # ABSTRACT: adds a file which lists the pages in the site
7              
8 3     3   1128 use Method::Signatures;
  3         126327  
  3         22  
9 3     3   7552 use Template;
  3         78351  
  3         129  
10              
11 3     3   1124 use App::Embra::File;
  3         9  
  3         139  
12 3     3   25 use Moo;
  3         6  
  3         20  
13              
14              
15              
16             has 'filename' => (
17             is => 'ro',
18             default => 'sitemap.html',
19             );
20              
21              
22             has 'sitemap_file' => (
23             is => 'lazy',
24             default => method { App::Embra::File->new( name => $self->filename ) },
25             );
26              
27             # not sure about this, might remove
28             has 'template' => (
29             is => 'lazy',
30             default => method { Template->new },
31             );
32              
33             # not sure about this, might remove
34             has 'sitemap_template' => (
35 3 50   3   6915 is => 'ro',
  3     3   140  
  3         29  
36 3         24 default => '<ul>[% FOREACH page IN pages %]<li><a href="[% page.name %]">[% page.notes.title or page.name %]</a></li>[% END %]</ul>',
37             );
38              
39 3 50   3   2020 method gather_files {
  2     2   85  
  2         9  
40 2         5 $self->add_file( $self->sitemap_file );
  6         154  
  2         12  
41 2         5 }
42 2         10  
43 2         14 method transform_files {
44 2         2884544 my @html_files = grep { $_->ext eq 'html' } @{ $self->embra->files };
45             my $sm;
46             my $vars = { pages => \@html_files };
47             $self->template->process( \ $self->sitemap_template, $vars, \$sm );
48             $self->sitemap_file->content( $sm );
49             }
50              
51             with 'App::Embra::Role::FileGatherer';
52             with 'App::Embra::Role::FileTransformer';
53              
54             1;
55              
56             __END__
57              
58             =pod
59              
60             =encoding UTF-8
61              
62             =head1 NAME
63              
64             App::Embra::Plugin::Sitemap - adds a file which lists the pages in the site
65              
66             =head1 VERSION
67              
68             version 0.001
69              
70             =head1 DESCRIPTION
71              
72             This plugin will add a F<sitemap.html> file to the site, with a list of links to all the HTML pages in your site.
73              
74             =head1 ATTRIBUTES
75              
76             =head2 filename
77              
78             Name of the name to store the sitemap in. Defaults to F<sitemap.html>.
79              
80             =head2 sitemap_file
81              
82             The L<App::Embra::File> for the sitemap. It will be created automatically with the name given in L</filename>.
83              
84             =head1 AUTHOR
85              
86             Daniel Holz <dgholz@gmail.com>
87              
88             =head1 COPYRIGHT AND LICENSE
89              
90             This software is copyright (c) 2015 by Daniel Holz.
91              
92             This is free software; you can redistribute it and/or modify it under
93             the same terms as the Perl 5 programming language system itself.
94              
95             =cut