line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Iconify; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69441
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
195167
|
|
|
2
|
|
|
|
|
26
|
|
4
|
2
|
|
|
2
|
|
1668
|
use Mojo::DOM::HTML; |
|
2
|
|
|
|
|
3356
|
|
|
2
|
|
|
|
|
99
|
|
5
|
2
|
|
|
2
|
|
471
|
use Mojo::ByteStream; |
|
2
|
|
|
|
|
3879
|
|
|
2
|
|
|
|
|
1497
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.20'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
1
|
50
|
my ( $self, $app, $config ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
10
|
$app->helper( 'iconify_icon' => \&_iconify_icon ); |
14
|
1
|
|
|
|
|
168
|
$app->helper( 'iconify_js' => \&_iconify_js ); |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
85
|
$app->helper( 'icon' => \&_iconify_icon ); # Alias |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _iconify_icon { |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
47758
|
my ( $self, $icon, %params ) = @_; |
23
|
3
|
50
|
|
|
|
13
|
return if ( !$icon ); |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
12
|
my %iconify_params = ( |
26
|
|
|
|
|
|
|
'class' => 'iconify', |
27
|
|
|
|
|
|
|
'data-icon' => $icon, |
28
|
|
|
|
|
|
|
); |
29
|
|
|
|
|
|
|
|
30
|
3
|
|
|
|
|
10
|
foreach my $param ( keys %params ) { |
31
|
|
|
|
|
|
|
|
32
|
2
|
|
|
|
|
5
|
my $value = $params{$param}; |
33
|
|
|
|
|
|
|
|
34
|
2
|
100
|
|
|
|
8
|
if ( $param eq 'size' ) { |
35
|
1
|
|
|
|
|
3
|
$iconify_params{'data-width'} = $value; |
36
|
1
|
|
|
|
|
3
|
$iconify_params{'data-height'} = $value; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
|
|
|
6
|
if ( $param eq 'inline' ) { |
40
|
0
|
0
|
|
|
|
0
|
$iconify_params{'data-inline'} = ( $value == 0 ) ? 'false' : 'true'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
50
|
|
|
|
7
|
if ( $param eq 'block' ) { |
44
|
0
|
0
|
|
|
|
0
|
$iconify_params{'data-inline'} = ( $value == 0 ) ? 'true' : 'false'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
50
|
33
|
|
|
18
|
if ( $param eq 'width' || $param eq 'height' || $param eq 'flip' || $param eq 'align' ) { |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
48
|
0
|
|
|
|
|
0
|
$iconify_params{"data-$param"} = $value; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
6
|
$iconify_params{'data-flip'} .= 'horizontal ' if ( $param eq 'flip_horizontal' ); |
52
|
2
|
50
|
|
|
|
5
|
$iconify_params{'data-flip'} .= 'vertical ' if ( $param eq 'flip_vertical' ); |
53
|
2
|
50
|
|
|
|
6
|
$iconify_params{'data-rotate'} = $value . 'deg' if ( $param eq 'rotate' ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Core HTML attributes |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
7
|
if ( $param eq 'class' ) { |
58
|
0
|
|
|
|
|
0
|
$iconify_params{'class'} .= " $value"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2
|
50
|
66
|
|
|
11
|
if ( $param eq 'id' || $param eq 'title' || $param eq 'style' ) { |
|
|
|
66
|
|
|
|
|
62
|
1
|
|
|
|
|
6
|
$iconify_params{$param} = $value; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
50
|
|
|
|
10
|
if ( defined $iconify_params{'data-flip'} ) { |
68
|
0
|
|
|
|
|
0
|
$iconify_params{'data-flip'} =~ s/\s$//; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
15
|
return _tag( 'span', %iconify_params ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub _iconify_js { |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
|
0
|
my ( $self, $url ) = @_; |
78
|
|
|
|
|
|
|
|
79
|
0
|
|
|
|
|
0
|
my $iconify_version = '3.0.1'; |
80
|
0
|
|
|
|
|
0
|
my $iconify_release = substr $iconify_version, 0, 1; |
81
|
0
|
|
0
|
|
|
0
|
my $iconify_js_url = $url || "https://code.iconify.design/$iconify_release/$iconify_version/iconify.min.js"; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
0
|
return _tag( 'script', 'src' => $iconify_js_url ); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
3
|
|
|
3
|
|
13
|
sub _tag { Mojo::ByteStream->new( Mojo::DOM::HTML::tag_to_html(@_) ) } |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |