File Coverage

blib/lib/Mojolicious/Plugin/SimpleSlides.pm
Criterion Covered Total %
statement 44 66 66.6
branch 12 24 50.0
condition 0 8 0.0
subroutine 12 15 80.0
pod 1 4 25.0
total 69 117 58.9


line stmt bran cond sub pod time code
1             package Mojolicious::Plugin::SimpleSlides;
2              
3 3     3   2023 use Mojo::Base 'Mojolicious::Plugin';
  3         6  
  3         20  
4              
5             our $VERSION = '0.05';
6             $VERSION = eval $VERSION;
7              
8 3     3   736 use File::Spec;
  3         5  
  3         73  
9 3     3   25 use File::Basename ();
  3         5  
  3         37  
10 3     3   1330 use File::ShareDir ();
  3         12985  
  3         2406  
11              
12             has 'base_href';
13              
14             has 'column_align' => 'top';
15              
16             has 'column_template' => 'simple_slides_column';
17             has 'columns_template' => 'simple_slides_columns';
18              
19             has 'column_width';
20              
21             has [qw/first_slide last_slide/] => 1;
22              
23             has 'layout' => 'simple_slides';
24              
25             has 'slides';
26              
27             has 'static_path' => sub {
28             my $local = File::Spec->catdir(File::Basename::dirname(__FILE__), 'SimpleSlides', 'public');
29             return $local if -d $local;
30              
31             my $share = File::ShareDir::dist_dir('Mojolicious-Plugin-SimpleSlides');
32             return $share if -d $share;
33              
34             warn "Cannot find static content for Mojolicious::Plugin::SimpleSlides, (checked $local and $share). The bundled javascript and css files will not work correctly.\n";
35             };
36              
37             sub register {
38 3     3 1 168 my ($plugin, $app, $conf) = @_;
39              
40 3 50       14 if (my $slides = $conf->{slides}) {
41 0         0 $plugin->slides($slides);
42 0         0 $plugin->last_slide(scalar @$slides);
43             }
44              
45 3 50       19 if (defined $conf->{first_slide}) {
46 0         0 $plugin->first_slide($conf->{first_slide});
47             }
48              
49 3 50       14 if (defined $conf->{last_slide}) {
50 0         0 $plugin->last_slide($conf->{last_slide});
51             }
52              
53 3         4 push @{ $app->renderer->classes }, __PACKAGE__;
  3         20  
54 3         52 push @{ $app->static->paths }, $plugin->static_path;
  3         12  
55              
56 3     41   30 $app->helper( simple_slides => sub { $plugin } );
  41         36361  
57              
58 3         65 $app->helper( column => \&_column );
59 3         33 $app->helper( columns => \&_columns );
60              
61             $app->helper( prev_slide => sub {
62 10     10   5559 my $c = shift;
63 10         105 return $c->simple_slides->prev_slide($c->stash('slide'));
64 3         31 });
65              
66             $app->helper( next_slide => sub {
67 10     10   5823 my $c = shift;
68 10         60 return $c->simple_slides->next_slide($c->stash('slide'));
69 3         35 });
70              
71             $app->helper( code_line => sub {
72 0     0   0 shift->tag('pre' => class => 'code-line' => @_);
73 3         29 });
74              
75 3         31 $app->routes->any(
76             '/:slide',
77             { slide => $plugin->first_slide },
78             [ slide => qr/\b\d+\b/ ],
79             \&_action,
80             );
81              
82 3         932 return $plugin;
83             }
84              
85             sub template_for_slide {
86 10     10 0 106 my ($self, $num) = @_;
87 10 50       37 return "$num" unless my $slides = $self->slides;
88 0         0 return $slides->[$num-1];
89             }
90              
91             sub prev_slide {
92 10     10 0 94 my ($self, $current) = @_;
93 10 100       29 return $current == $self->first_slide ? $current : $current - 1;
94             }
95              
96             sub next_slide {
97 10     10 0 95 my ($self, $current) = @_;
98 10 100       31 return $current == $self->last_slide ? $current : $current + 1;
99             }
100              
101             # controller action callback
102              
103             sub _action {
104 10     10   199383 my $c = shift;
105 10         94 my $plugin = $c->simple_slides;
106 10 100       37 my $slide = $plugin->template_for_slide($c->stash( 'slide' ))
107             or return $c->reply->not_found;
108 8         94 $c->layout( $plugin->layout );
109 8 100       379 $c->render( $slide ) || $c->reply->not_found;
110             }
111              
112             # helpers
113              
114             sub _column {
115 0     0     my $c = shift;
116 0           my $plugin = $c->simple_slides;
117 0   0       my $content = pop || return;
118 0 0         $content = ref $content ? $content->() : $content;
119              
120 0           my %args = @_;
121 0           my $style = '';
122              
123 0   0       my $width = delete $args{width} // $plugin->column_width; #/# highlight fix
124 0 0         if ( $width ) {
125 0           $style .= "width: $width%;";
126             }
127              
128 0 0 0       if ( my $align = delete $args{align} || $plugin->column_align ) {
129 0           $style .= "vertical-align: $align;";
130             }
131            
132 0           return $c->render(
133             partial => 1,
134             'columns.style' => $style,
135             'columns.column' => $content,
136             template => $plugin->column_template,
137             );
138             }
139              
140             sub _columns {
141 0     0     my $c = shift;
142 0 0         return unless @_;
143 0           my $content = shift->();
144 0           return $c->render(
145             partial => 1,
146             'columns.content' => $content,
147             template => $c->simple_slides->columns_template,
148             );
149             }
150              
151             1;
152              
153             =head1 NAME
154              
155             Mojolicious::Plugin::SimpleSlides - DEPRECATED Create a presentation using Mojolicious
156              
157             =head1 DESCRIPTION
158              
159             This module has been extracted from a talk gave at Chicago.pm. I have rushed it out before the talk, it has almost no tests or documentation. For the moment its use is at your own risk.
160              
161             Indeed it never really got better than this, that's why:
162              
163             =head1 DEPRECATED
164              
165             This module is now officially deprecated.
166             I will give it no further effort.
167             If someone would like to adopt it, please contact me.
168              
169             =head1 SEE ALSO
170              
171             L, L
172              
173             =head1 SOURCE REPOSITORY
174              
175             L
176              
177             =head1 AUTHOR
178              
179             Joel Berger, Ejoel.a.berger@gmail.comE
180              
181             =head1 COPYRIGHT AND LICENSE
182              
183             Copyright (C) 2013 by Joel Berger
184              
185             This library is free software; you can redistribute it and/or modify
186             it under the same terms as Perl itself.
187              
188             =cut
189              
190             __DATA__