blib/lib/Yukki/Web/Plugin/Viewer.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 55 SCAR 24.8
CC
3
Cov
0%
show_view_link
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.0
1 package Yukki::Web::Plugin::Viewer;
2 $Yukki::Web::Plugin::Viewer::VERSION = '0.991_002'; # TRIAL
3  
4 $Yukki::Web::Plugin::Viewer::VERSION = '0.991002';use v5.24;
5 use utf8;
6 use Moo;
7  
8 use Types::Standard qw( HashRef Str );
9  
10 extends 'Yukki::Web::Plugin';
11  
12 use Yukki::Error qw( http_throw );
13  
14 use namespace::clean;
15  
16 # ABSTRACT: plugin for custom page viewers
17  
18  
19 has format_helpers => (
20 is => 'ro',
21 isa => HashRef[Str],
22 required => 1,
23 default => sub { +{
24 'show view' => 'show_view_link',
25 } },
26 );
27  
28 with 'Yukki::Web::Plugin::Role::FormatHelper';
29  
30  
31 sub show_view_link {
32 my ($self, $params) = @_;
33  
34 my $ctx = $params->{context};
35 my $file = $params->{file};
36 my $view = $params->{arg};
37  
38 my $repo = $file->repository_name;
39 my $page = $file->full_path;
40  
41 my $view_info = $self->app->settings->page_views->{$view};
42  
43 unless ($view_info) {
44 warn "no such view as '$view' configured in yukki.conf";
45 return '';
46 }
47  
48 my $args = "?view=$view";
49 $args = '' if $view eq 'default';
50  
51 $ctx->response->add_navigation_item([ qw( page page_bottom ) ] => {
52 label => $view_info->{label},
53 href => join('/', 'page/view', $repo, $page)
54 . $args,
55 sort => $view_info->{sort},
56 });
57  
58 return '';
59 }
60  
61 1;
62  
63 __END__
64  
65 =pod
66  
67 =encoding UTF-8
68  
69 =head1 NAME
70  
71 Yukki::Web::Plugin::Viewer - plugin for custom page viewers
72  
73 =head1 VERSION
74  
75 version 0.991_002
76  
77 =head1 SYNOPSIS
78  
79 {{show view:slides}}
80  
81 =head1 DESCRIPTION
82  
83 This allows the author to create links to custom views that inject additional scripts and/or stylesheets into the view page.
84  
85 =head1 ATTRIBUTES
86  
87 =head2 format_helpers
88  
89 Provides the viewer link.
90  
91 =head1 METHODS
92  
93 =head2 show_view_link
94  
95 Adds the view back into navigation if it is normally hidden.
96  
97 =head1 AUTHOR
98  
99 Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
100  
101 =head1 COPYRIGHT AND LICENSE
102  
103 This software is copyright (c) 2017 by Qubling Software LLC.
104  
105 This is free software; you can redistribute it and/or modify it under
106 the same terms as the Perl 5 programming language system itself.
107  
108 =cut