line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::Iconify; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
69852
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
194905
|
|
|
2
|
|
|
|
|
15
|
|
4
|
2
|
|
|
2
|
|
1618
|
use Mojo::DOM::HTML; |
|
2
|
|
|
|
|
3172
|
|
|
2
|
|
|
|
|
104
|
|
5
|
2
|
|
|
2
|
|
459
|
use Mojo::ByteStream; |
|
2
|
|
|
|
|
3776
|
|
|
2
|
|
|
|
|
1394
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.10'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub register { |
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
1
|
99
|
my ( $self, $app, $config ) = @_; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
|
|
11
|
$app->helper( 'iconify_icon' => \&_iconify_icon ); |
14
|
1
|
|
|
|
|
158
|
$app->helper( 'iconify_js' => \&_iconify_js ); |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
86
|
$app->helper( 'icon' => \&_iconify_icon ); # Alias |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _iconify_icon { |
21
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
49205
|
my ( $self, $icon, %params ) = @_; |
23
|
3
|
50
|
|
|
|
11
|
return if ( !$icon ); |
24
|
|
|
|
|
|
|
|
25
|
3
|
|
|
|
|
11
|
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
|
|
|
|
6
|
if ( $param eq 'size' ) { |
35
|
1
|
|
|
|
|
3
|
$iconify_params{'data-width'} = $value; |
36
|
1
|
|
|
|
|
2
|
$iconify_params{'data-height'} = $value; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
2
|
50
|
|
|
|
5
|
if ( $param eq 'inline' ) { |
40
|
0
|
0
|
|
|
|
0
|
$iconify_params{'data-inline'} = ( $value == 0 ) ? 'false' : 'true'; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
2
|
50
|
|
|
|
10
|
if ( $param eq 'block' ) { |
44
|
0
|
0
|
|
|
|
0
|
$iconify_params{'data-inline'} = ( $value == 0 ) ? 'true' : 'false'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
2
|
50
|
33
|
|
|
20
|
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
|
|
|
|
4
|
$iconify_params{'data-flip'} .= 'vertical ' if ( $param eq 'flip_vertical' ); |
53
|
2
|
50
|
|
|
|
4
|
$iconify_params{'data-rotate'} = $value . 'deg' if ( $param eq 'rotate' ); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Core HTML attributes |
56
|
|
|
|
|
|
|
|
57
|
2
|
50
|
|
|
|
5
|
if ( $param eq 'class' ) { |
58
|
0
|
|
|
|
|
0
|
$iconify_params{'class'} .= " $value"; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
2
|
50
|
66
|
|
|
9
|
if ( $param eq 'id' || $param eq 'title' || $param eq 'style' ) { |
|
|
|
66
|
|
|
|
|
62
|
1
|
|
|
|
|
3
|
$iconify_params{$param} = $value; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
3
|
50
|
|
|
|
17
|
if ( defined $iconify_params{'data-flip'} ) { |
68
|
0
|
|
|
|
|
0
|
$iconify_params{'data-flip'} =~ s/\s$//; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
10
|
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 = '1.0.7'; |
80
|
0
|
|
0
|
|
|
0
|
my $iconify_js_url = $url || "https://code.iconify.design/1/$iconify_version/iconify.min.js"; |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
0
|
return _tag( 'script', 'src' => $iconify_js_url ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
3
|
|
12
|
sub _tag { Mojo::ByteStream->new( Mojo::DOM::HTML::tag_to_html(@_) ) } |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |