line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::SimpleSlides; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1555
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
15
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
6
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
512
|
use File::Spec; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
56
|
|
9
|
3
|
|
|
3
|
|
15
|
use File::Basename (); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
29
|
|
10
|
3
|
|
|
3
|
|
1247
|
use File::ShareDir (); |
|
3
|
|
|
|
|
11745
|
|
|
3
|
|
|
|
|
2061
|
|
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
|
97
|
my ($plugin, $app, $conf) = @_; |
39
|
|
|
|
|
|
|
|
40
|
3
|
50
|
|
|
|
9
|
if (my $slides = $conf->{slides}) { |
41
|
0
|
|
|
|
|
0
|
$plugin->slides($slides); |
42
|
0
|
|
|
|
|
0
|
$plugin->last_slide(scalar @$slides); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
3
|
50
|
|
|
|
8
|
if (defined $conf->{first_slide}) { |
46
|
0
|
|
|
|
|
0
|
$plugin->first_slide($conf->{first_slide}); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
3
|
50
|
|
|
|
7
|
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
|
|
|
|
|
13
|
|
54
|
3
|
|
|
|
|
46
|
push @{ $app->static->paths }, $plugin->static_path; |
|
3
|
|
|
|
|
11
|
|
55
|
|
|
|
|
|
|
|
56
|
3
|
|
|
41
|
|
21
|
$app->helper( simple_slides => sub { $plugin } ); |
|
41
|
|
|
|
|
22251
|
|
57
|
|
|
|
|
|
|
|
58
|
3
|
|
|
|
|
53
|
$app->helper( column => \&_column ); |
59
|
3
|
|
|
|
|
46
|
$app->helper( columns => \&_columns ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$app->helper( prev_slide => sub { |
62
|
10
|
|
|
10
|
|
4017
|
my $c = shift; |
63
|
10
|
|
|
|
|
43
|
return $c->simple_slides->prev_slide($c->stash('slide')); |
64
|
3
|
|
|
|
|
33
|
}); |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$app->helper( next_slide => sub { |
67
|
10
|
|
|
10
|
|
3965
|
my $c = shift; |
68
|
10
|
|
|
|
|
42
|
return $c->simple_slides->next_slide($c->stash('slide')); |
69
|
3
|
|
|
|
|
29
|
}); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$app->helper( code_line => sub { |
72
|
0
|
|
|
0
|
|
0
|
shift->tag('pre' => class => 'code-line' => @_); |
73
|
3
|
|
|
|
|
28
|
}); |
74
|
|
|
|
|
|
|
|
75
|
3
|
|
|
|
|
30
|
$app->routes->any( |
76
|
|
|
|
|
|
|
'/:slide', |
77
|
|
|
|
|
|
|
{ slide => $plugin->first_slide }, |
78
|
|
|
|
|
|
|
[ slide => qr/\b\d+\b/ ], |
79
|
|
|
|
|
|
|
\&_action, |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
775
|
return $plugin; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub template_for_slide { |
86
|
10
|
|
|
10
|
0
|
79
|
my ($self, $num) = @_; |
87
|
10
|
50
|
|
|
|
24
|
return "$num" unless my $slides = $self->slides; |
88
|
0
|
|
|
|
|
0
|
return $slides->[$num-1]; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub prev_slide { |
92
|
10
|
|
|
10
|
0
|
65
|
my ($self, $current) = @_; |
93
|
10
|
100
|
|
|
|
43
|
return $current == $self->first_slide ? $current : $current - 1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub next_slide { |
97
|
10
|
|
|
10
|
0
|
73
|
my ($self, $current) = @_; |
98
|
10
|
100
|
|
|
|
18
|
return $current == $self->last_slide ? $current : $current + 1; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# controller action callback |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub _action { |
104
|
10
|
|
|
10
|
|
144216
|
my $c = shift; |
105
|
10
|
|
|
|
|
58
|
my $plugin = $c->simple_slides; |
106
|
10
|
100
|
|
|
|
20
|
my $slide = $plugin->template_for_slide($c->stash( 'slide' )) |
107
|
|
|
|
|
|
|
or return $c->reply->not_found; |
108
|
8
|
|
|
|
|
56
|
$c->layout( $plugin->layout ); |
109
|
8
|
100
|
|
|
|
266
|
$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
|
|
|
|
|
|
|
__DATA__ |