line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::BootstrapAlerts; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: Bootstrap alerts for your web app |
4
|
|
|
|
|
|
|
|
5
|
7
|
|
|
7
|
|
5560
|
use strict; |
|
7
|
|
|
|
|
18
|
|
|
7
|
|
|
|
|
269
|
|
6
|
7
|
|
|
7
|
|
41
|
use warnings; |
|
7
|
|
|
|
|
15
|
|
|
7
|
|
|
|
|
253
|
|
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
11730
|
use parent 'Mojolicious::Plugin'; |
|
7
|
|
|
|
|
2324
|
|
|
7
|
|
|
|
|
51
|
|
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
434
|
use Mojo::ByteStream; |
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
4796
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = 0.06; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub register { |
15
|
7
|
|
|
7
|
1
|
6624
|
my ($self, $app, $config) = @_; |
16
|
|
|
|
|
|
|
|
17
|
7
|
|
66
|
|
|
100
|
my $dismissable = !( $config && exists $config->{dismissable} && $config->{dismissable} == 0 ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
$app->helper( notify => sub { |
20
|
17
|
|
|
17
|
|
342276
|
my $c = shift; |
21
|
17
|
|
|
|
|
38
|
push @{ $c->stash->{__NOTIFICATIONS__} }, [ @_ ]; |
|
17
|
|
|
|
|
61
|
|
22
|
7
|
|
|
|
|
89
|
} ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$app->helper( notifications => sub { |
25
|
13
|
|
|
13
|
|
98390
|
my $c = shift; |
26
|
13
|
|
|
|
|
34
|
my $notifications_config = shift; |
27
|
|
|
|
|
|
|
|
28
|
13
|
|
|
|
|
31
|
my $output = ''; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
28
|
for my $notification ( @{ $c->stash('__NOTIFICATIONS__') || [] } ) { |
|
13
|
|
|
|
|
50
|
|
31
|
17
|
|
|
|
|
171
|
my ($type, $message, $config) = @{ $notification }; |
|
17
|
|
|
|
|
42
|
|
32
|
|
|
|
|
|
|
|
33
|
17
|
|
|
|
|
39
|
my ($dismissable_class, $dismissable_button) = ("",""); |
34
|
17
|
100
|
100
|
|
|
160
|
if ( $config->{dismissable} || (!exists $config->{dismissable} && $dismissable) ) { |
|
|
|
33
|
|
|
|
|
35
|
12
|
|
|
|
|
23
|
$dismissable_class = 'alert-dismissable'; |
36
|
12
|
|
|
|
|
20
|
$dismissable_button = ''; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
17
|
100
|
66
|
|
|
94
|
if ( ref $message and ref $message eq 'ARRAY' ) { |
40
|
6
|
|
|
|
|
18
|
my $items = join '', map{ "$_" }@{ $message }; |
|
12
|
|
|
|
|
39
|
|
|
6
|
|
|
|
|
14
|
|
41
|
6
|
100
|
|
|
|
33
|
my $list_type = $config->{ordered_list} ? 'ol' : 'ul'; |
42
|
|
|
|
|
|
|
|
43
|
6
|
|
|
|
|
24
|
$message = "<$list_type>$items$list_type>"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
17
|
100
|
|
|
|
51
|
$type = 'danger' if $type eq 'error'; |
47
|
|
|
|
|
|
|
|
48
|
17
|
|
|
|
|
127
|
$output .= qq~ |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$dismissable_button |
51
|
|
|
|
|
|
|
$message |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
~; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
13
|
|
|
|
|
253
|
return Mojo::ByteStream->new( $output ); |
57
|
7
|
|
|
|
|
919
|
} ); |
58
|
|
|
|
|
|
|
|
59
|
7
|
50
|
66
|
|
|
755
|
if ( $config && $config->{auto_inject} && ($config->{before} || $config->{after}) ) { |
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
60
|
|
|
|
|
|
|
$app->hook( after_render => sub { |
61
|
4
|
|
|
4
|
|
9844
|
my ($c, $content, $format) = @_; |
62
|
|
|
|
|
|
|
|
63
|
4
|
50
|
|
|
|
24
|
return if $format ne 'html'; |
64
|
|
|
|
|
|
|
|
65
|
4
|
|
|
|
|
44
|
my $notifications = $c->notifications->to_string; |
66
|
|
|
|
|
|
|
|
67
|
4
|
50
|
|
|
|
187
|
return if !$notifications; |
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
8
|
my $dom = Mojo::DOM->new( ${$content} ); |
|
4
|
|
|
|
|
34
|
|
70
|
4
|
|
33
|
|
|
1622
|
my $selector = $config->{before} || $config->{after}; |
71
|
4
|
|
|
|
|
19
|
my $element = $dom->at( $selector ); |
72
|
|
|
|
|
|
|
|
73
|
4
|
100
|
|
|
|
1330
|
if ( !$element ) { |
74
|
2
|
|
|
|
|
47
|
$c->app->log->debug( 'no matching element found (' . $selector . ')' ); |
75
|
2
|
|
|
|
|
130
|
return; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
2
|
50
|
|
|
|
27
|
my @elems = $config->{before} ? ($notifications, "$element") : ("$element", $notifications); |
79
|
2
|
|
|
|
|
283
|
my $replacement = sprintf "%s%s", @elems; |
80
|
2
|
|
|
|
|
5
|
my $temp = "$element"; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
197
|
${$content} =~ s/\Q$temp\E/$replacement/; |
|
2
|
|
|
|
|
45
|
|
83
|
2
|
|
|
|
|
36
|
}); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |