| 1 | # ABSTRACT: Example generator to create tagged pages | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | package HiD::Generator::TagPages; | ||||||||||||||||||||
| 5 | 1 | our $AUTHORITY = 'cpan:GENEHACK'; | |||||||||||||||||||
| 6 | 1 | $HiD::Generator::TagPages::VERSION = '1.96'; | |||||||||||||||||||
| 7 | 1 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | with 'HiD::Generator'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 1 | ▶ | use 5.014; # strict, unicode_strings | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 1 | ▶ | use HiD::Page; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | sub generate { | ||||||||||||||||||||
| 16 | 0 | ▶ | my( $self , $site ) = @_; | ||||||||||||||||||
|
Subroutine
generate: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 0 | ▶ | return unless $site->config->{tags}{generate}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 0 | ▶ | if ( exists $site->config->{tags}{input} ){ | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 21 | 0 | $site->WARN("Using deprecated tags.input key. Please convert to tags.layout!" ); | |||||||||||||||||||
| 22 | 0 | $site->config->{tags}{layout} = $site->config->{tags}{input}; | |||||||||||||||||||
| 23 | } | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | my $input_file = $site->config->{tags}{layout} | ||||||||||||||||||||
| 26 | 0 | ▶ | or die "Must define tags.layout in config if tags.generate is enabled"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | ▶ | my $destination = $site->config->{tags}{destination} // $site->destination; | ||||||||||||||||||
|
Condition0%0/3
$site->config->{"tags"}{"destination"} // $site->destination
MC/DC0%0/2
$site->config->{"tags"}{"destination"} // $site->destination
$site->config->{"tags"}{"destination"}
$site->destination
Truth table0%0/3
A // B
A= $site->config->{"tags"}{"destination"}B= $site->destination
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | $self->_create_destination_directory_if_needed( $destination ); | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | foreach my $tag ( keys %{ $site->tags } ) { | |||||||||||||||||||
| 33 | 0 | my $page = HiD::Page->new({ | |||||||||||||||||||
| 34 | dest_dir => $destination , | ||||||||||||||||||||
| 35 | hid => $site , | ||||||||||||||||||||
| 36 | url => "tags/$tag/" , | ||||||||||||||||||||
| 37 | input_filename => $input_file , | ||||||||||||||||||||
| 38 | layouts => $site->layouts , | ||||||||||||||||||||
| 39 | }); | ||||||||||||||||||||
| 40 | 0 | $page->metadata->{tag} = $tag; | |||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | $site->add_input( "Tag_$tag" => 'page' ); | |||||||||||||||||||
| 43 | 0 | $site->add_object( $page ); | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | 0 | $site->INFO( "* Injected tag page for '$tag'"); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||
| 50 | 1 | 1; | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | __END__ | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =pod | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =encoding UTF-8 | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =head1 NAME | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | HiD::Generator::TagPages - Example generator to create tagged pages | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =head1 DESCRIPTION | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | This is an example of a generator plugin. It generates one page per key in the | ||||||||||||||||||||
| 65 | C<< $site->tags >> hash, and injects that page into the site so that it will | ||||||||||||||||||||
| 66 | be published. | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | To activate this plugin, add a 'tags.generate' key to your config. You should | ||||||||||||||||||||
| 69 | also add a 'tags.layout' key that provides a template file to use. Finally, | ||||||||||||||||||||
| 70 | you may also set a 'tags.destination' key to indicate an output directory for | ||||||||||||||||||||
| 71 | the tag files. If this is not set, it will default to the normal site-wise | ||||||||||||||||||||
| 72 | destination. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head1 METHODS | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =head2 generate | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =head1 VERSION | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | version 1.96 | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | =head1 AUTHOR | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | John SJ Anderson <genehack@genehack.org> | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | This software is copyright (c) 2015 by John SJ Anderson. | ||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 91 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||