File Coverage

blib/lib/Mojolicious/Plugin/SimpleSlides.pm
Criterion Covered Total %
statement 41 63 65.0
branch 12 24 50.0
condition 0 8 0.0
subroutine 11 14 78.5
pod 1 4 25.0
total 65 113 57.5


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