line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Humane; |
2
|
2
|
|
|
2
|
|
2640
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
18
|
|
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
478
|
use File::Spec; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
57
|
|
5
|
2
|
|
|
2
|
|
23
|
use File::Basename (); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
49
|
|
6
|
2
|
|
|
2
|
|
2037
|
use File::ShareDir (); |
|
2
|
|
|
|
|
14954
|
|
|
2
|
|
|
|
|
2155
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
9
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has 'humane_version' => '3.2.0'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'static_path' => sub { |
14
|
|
|
|
|
|
|
my $self = shift; |
15
|
|
|
|
|
|
|
$self->path('humane-' . $self->humane_version); |
16
|
|
|
|
|
|
|
}; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'template' => 'humane_template'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has 'theme' => 'libnotify'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub path { |
23
|
2
|
|
|
2
|
1
|
19
|
my $self = shift; |
24
|
2
|
|
|
|
|
4
|
my $folder = shift; |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
|
|
|
168
|
my $local = File::Spec->catdir( File::Basename::dirname(__FILE__), 'Humane', 'files', $folder ); |
27
|
2
|
50
|
|
|
|
98
|
return $local if -d $local; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
11
|
my $share = File::Spec->catdir( File::ShareDir::dist_dir('Mojolicious-Plugin-Humane'), $folder ); |
30
|
2
|
50
|
|
|
|
320
|
return $share if -d $share; |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
0
|
die "Cannot find files. Tried '$local' and '$share'.\n"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub register { |
36
|
2
|
|
|
2
|
1
|
120
|
my ($plugin, $app) = (shift, shift); |
37
|
2
|
50
|
|
|
|
10
|
my %conf = ref $_[0] ? %{ shift() } : @_; |
|
2
|
|
|
|
|
10
|
|
38
|
|
|
|
|
|
|
|
39
|
2
|
|
100
|
|
|
17
|
$conf{auto} //= 1; #/# highlight fix |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# Append static to directories |
42
|
2
|
|
|
|
|
3
|
push @{$app->static->paths}, $plugin->static_path; |
|
2
|
|
|
|
|
59
|
|
43
|
2
|
|
|
|
|
7
|
push @{$app->renderer->classes}, __PACKAGE__; |
|
2
|
|
|
|
|
67
|
|
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
12
|
|
116
|
$app->helper( humane => sub { $plugin } ); |
|
12
|
|
|
|
|
20731
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$app->helper( humane_stash => sub { |
48
|
15
|
|
|
15
|
|
76490
|
my $self = shift; |
49
|
15
|
|
|
|
|
42
|
my $key = 'humane.stash'; |
50
|
15
|
|
100
|
|
|
51
|
my $stash = $self->stash($key) || []; |
51
|
|
|
|
|
|
|
|
52
|
15
|
100
|
|
|
|
289
|
if ( @_ ) { |
53
|
3
|
|
|
|
|
10
|
push @$stash, @_; |
54
|
3
|
|
|
|
|
14
|
$self->stash( $key => $stash ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
15
|
|
|
|
|
129
|
return $stash; |
58
|
2
|
|
|
|
|
247
|
}); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
$app->helper( humane_flash => sub { |
61
|
15
|
|
|
15
|
|
86704
|
my $self = shift; |
62
|
15
|
|
|
|
|
49
|
my $key = 'humane.flash'; |
63
|
15
|
|
100
|
|
|
112
|
my $flash = $self->flash($key) || []; |
64
|
|
|
|
|
|
|
|
65
|
15
|
100
|
|
|
|
473
|
if ( @_ ) { |
66
|
3
|
|
|
|
|
10
|
push @$flash, @_; |
67
|
3
|
|
|
|
|
15
|
$self->flash( $key => $flash ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
15
|
|
|
|
|
146
|
return $flash; |
71
|
2
|
|
|
|
|
260
|
}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$app->helper( humane_include => sub { |
74
|
6
|
|
|
6
|
|
81017
|
my $self = shift; |
75
|
6
|
|
|
|
|
98
|
$self->include( #TODO use render_to_string once Mojo 5.00 is required |
76
|
|
|
|
|
|
|
template => $self->humane->template, |
77
|
|
|
|
|
|
|
); |
78
|
2
|
|
|
|
|
187
|
}); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
$app->helper( humane_messages => sub { |
81
|
12
|
|
|
12
|
|
36845
|
my $self = shift; |
82
|
12
|
|
|
|
|
223
|
my @messages = ( |
83
|
12
|
|
|
|
|
90
|
@{ $self->humane_flash }, |
84
|
12
|
|
|
|
|
38
|
@{ $self->humane_stash }, |
85
|
|
|
|
|
|
|
); |
86
|
12
|
|
|
|
|
53
|
return @messages; |
87
|
2
|
|
|
|
|
175
|
}); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$app->hook( after_dispatch => sub { |
90
|
6
|
|
|
6
|
|
83642
|
my $c = shift; |
91
|
6
|
|
|
|
|
65
|
my @messages = $c->humane_messages; |
92
|
6
|
100
|
|
|
|
22
|
return unless @messages; |
93
|
|
|
|
|
|
|
|
94
|
3
|
|
|
|
|
15
|
my $dom = $c->res->dom; |
95
|
3
|
50
|
|
|
|
2639
|
my $head = $dom->at('head') or return; |
96
|
|
|
|
|
|
|
|
97
|
3
|
|
|
|
|
1390
|
my $append = $c->humane_include; |
98
|
3
|
|
|
|
|
437
|
$head->append_content( $append ); |
99
|
3
|
|
|
|
|
2071
|
$c->tx->res->body( $dom->to_string ); |
100
|
2
|
100
|
|
|
|
188
|
} ) if $conf{auto}; |
101
|
|
|
|
|
|
|
|
102
|
2
|
|
|
|
|
60
|
return $plugin; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub all_themes { |
106
|
2
|
|
|
2
|
1
|
1771
|
my $self = shift; |
107
|
2
|
|
|
|
|
50
|
my $path = $self->static_path; |
108
|
2
|
50
|
|
|
|
148
|
opendir my $dh, $path or die "Cannot open $path\n"; |
109
|
2
|
100
|
|
|
|
46
|
return map { s/\.css$// ? $_ : () } readdir $dh; |
|
20
|
|
|
|
|
112
|
|
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
__DATA__ |