| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright (C) 2010, Yaroslav Korshak. |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Mojolicious::Plugin::LinkedContent; |
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
627756
|
use warnings; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
78
|
|
|
6
|
2
|
|
|
2
|
|
13
|
use strict; |
|
|
2
|
|
|
|
|
5
|
|
|
|
2
|
|
|
|
|
95
|
|
|
7
|
|
|
|
|
|
|
require Mojo::URL; |
|
8
|
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
11
|
use base 'Mojolicious::Plugin'; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
1865
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
my %defaults = ( |
|
14
|
|
|
|
|
|
|
'js_base' => '/js', |
|
15
|
|
|
|
|
|
|
'css_base' => '/css', |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $reverse = 0; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $stashkey = '$linked_store'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub register { |
|
23
|
1
|
|
|
1
|
1
|
19428
|
my ($self, $app, $params) = @_; |
|
24
|
1
|
|
|
|
|
4
|
for (qw/js_base css_base/) { |
|
25
|
2
|
50
|
|
|
|
70
|
$self->{$_} = |
|
26
|
|
|
|
|
|
|
defined($params->{$_}) ? delete($params->{$_}) : $defaults{$_}; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
4
|
push @{$app->renderer->classes}, __PACKAGE__; |
|
|
1
|
|
|
|
|
35
|
|
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
$app->renderer->add_helper( |
|
32
|
|
|
|
|
|
|
require_js => sub { |
|
33
|
3
|
|
|
3
|
|
5383
|
$self->store_items('js', @_); |
|
34
|
|
|
|
|
|
|
} |
|
35
|
1
|
|
|
|
|
63
|
); |
|
36
|
|
|
|
|
|
|
$app->renderer->add_helper( |
|
37
|
|
|
|
|
|
|
require_css => sub { |
|
38
|
3
|
|
|
3
|
|
4049
|
$self->store_items('css', @_); |
|
39
|
|
|
|
|
|
|
} |
|
40
|
1
|
|
|
|
|
73
|
); |
|
41
|
|
|
|
|
|
|
$app->renderer->add_helper( |
|
42
|
|
|
|
|
|
|
include_css => sub { |
|
43
|
3
|
|
|
3
|
|
63
|
$self->include_css(@_); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
1
|
|
|
|
|
66
|
); |
|
46
|
|
|
|
|
|
|
$app->renderer->add_helper( |
|
47
|
|
|
|
|
|
|
include_js => sub { |
|
48
|
3
|
|
|
3
|
|
68
|
$self->include_js(@_); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
1
|
|
|
|
|
63
|
); |
|
51
|
|
|
|
|
|
|
|
|
52
|
1
|
|
|
|
|
60
|
$app->log->debug("Plugin " . __PACKAGE__ . " registred!"); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub store_items { |
|
56
|
6
|
|
|
6
|
1
|
20
|
my ($self, $target, $c, @items) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
6
|
|
|
|
|
12
|
my $upd; |
|
59
|
6
|
|
100
|
|
|
28
|
my $store = $c->stash($stashkey) || {}; |
|
60
|
6
|
50
|
|
|
|
127
|
for ($reverse ? reverse(@items) : @items) { |
|
61
|
6
|
50
|
|
|
|
39
|
if (exists $store->{'garage'}{$target}{$_}) { |
|
62
|
0
|
0
|
|
|
|
0
|
next unless $reverse; |
|
63
|
0
|
|
|
|
|
0
|
my $x = $_; |
|
64
|
0
|
|
|
|
|
0
|
@{$store->{'box'}{$target}} = grep $_ ne $x, |
|
|
0
|
|
|
|
|
0
|
|
|
65
|
0
|
|
|
|
|
0
|
@{$store->{'box'}{$target}}; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
6
|
|
|
|
|
21
|
$store->{'garage'}{$target}{$_} = 1; |
|
68
|
6
|
50
|
|
|
|
15
|
if (!$reverse) { push(@{$store->{'box'}{$target}}, $_) } |
|
|
6
|
|
|
|
|
7
|
|
|
|
6
|
|
|
|
|
30
|
|
|
69
|
0
|
|
|
|
|
0
|
else { unshift(@{$store->{'box'}{$target}}, $_); } |
|
|
0
|
|
|
|
|
0
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
6
|
|
|
|
|
23
|
$c->stash($stashkey => $store); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub include_js { |
|
75
|
3
|
|
|
3
|
1
|
6
|
my $self = shift; |
|
76
|
3
|
|
|
|
|
6
|
my $c = shift; |
|
77
|
3
|
|
|
|
|
7
|
local $reverse = 1; |
|
78
|
3
|
50
|
|
|
|
14
|
$self->store_items('js', $c, @_) if @_; |
|
79
|
3
|
|
|
|
|
11
|
my $store = $c->stash($stashkey); |
|
80
|
3
|
50
|
|
|
|
37
|
return '' unless $store->{'box'}{'js'}; |
|
81
|
3
|
|
|
|
|
5
|
my @ct; |
|
82
|
3
|
|
|
|
|
5
|
for (@{$store->{'box'}{'js'}}) { |
|
|
3
|
|
|
|
|
9
|
|
|
83
|
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
15
|
$c->stash('$linked_item' => $self->_prepend_path($_, 'js_base')); |
|
85
|
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
443
|
push @ct, $c->render( |
|
87
|
|
|
|
|
|
|
template => 'LinkedContent/js', |
|
88
|
|
|
|
|
|
|
format => 'html', |
|
89
|
|
|
|
|
|
|
handler => 'ep', |
|
90
|
|
|
|
|
|
|
partial => 1, |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
# template_class is deprecated since Mojolicious 2.62 |
|
93
|
|
|
|
|
|
|
# was removed at some point which broke my code. |
|
94
|
|
|
|
|
|
|
# But it'll live here for a while |
|
95
|
|
|
|
|
|
|
template_class => __PACKAGE__ |
|
96
|
|
|
|
|
|
|
); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
3
|
|
|
|
|
9044
|
$c->stash('$linked_item', undef); |
|
99
|
3
|
|
|
|
|
58
|
return join '', @ct; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub include_css { |
|
103
|
3
|
|
|
3
|
1
|
7
|
my $self = shift; |
|
104
|
3
|
|
|
|
|
3
|
my $c = shift; |
|
105
|
3
|
|
|
|
|
7
|
local $reverse = 1; |
|
106
|
3
|
50
|
|
|
|
18
|
$self->store_items('css', $c, @_) if @_; |
|
107
|
3
|
|
|
|
|
11
|
my $store = $c->stash($stashkey); |
|
108
|
3
|
50
|
|
|
|
38
|
return '' unless $store->{'box'}{'css'}; |
|
109
|
3
|
|
|
|
|
6
|
my @ct; |
|
110
|
3
|
|
|
|
|
6
|
for (@{$store->{'box'}{'css'}}) { |
|
|
3
|
|
|
|
|
9
|
|
|
111
|
|
|
|
|
|
|
|
|
112
|
3
|
|
|
|
|
11
|
$c->stash('$linked_item' => $self->_prepend_path($_, 'css_base')); |
|
113
|
|
|
|
|
|
|
|
|
114
|
3
|
|
|
|
|
337
|
push @ct, $c->render( |
|
115
|
|
|
|
|
|
|
template => 'LinkedContent/css', |
|
116
|
|
|
|
|
|
|
format => 'html', |
|
117
|
|
|
|
|
|
|
handler => 'ep', |
|
118
|
|
|
|
|
|
|
partial => 1, |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
# template_class is deprecated since Mojolicious 2.62 |
|
121
|
|
|
|
|
|
|
# was removed at some point which broke my code. |
|
122
|
|
|
|
|
|
|
# But it'll live here for a while |
|
123
|
|
|
|
|
|
|
template_class => __PACKAGE__ |
|
124
|
|
|
|
|
|
|
); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
3
|
|
|
|
|
5712
|
$c->stash('$linked_item', undef); |
|
127
|
3
|
|
|
|
|
57
|
return join '', @ct; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub _prepend_path { |
|
131
|
6
|
|
|
6
|
|
12
|
my ($self, $path, $base) = @_; |
|
132
|
|
|
|
|
|
|
|
|
133
|
6
|
|
|
|
|
43
|
my $url = Mojo::URL->new($path); |
|
134
|
6
|
100
|
100
|
|
|
2424
|
if ($url->is_abs || $url->path->leading_slash) { |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# Absolute path or absolute url returned as is |
|
137
|
4
|
|
|
|
|
434
|
return $path; |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Basepath not defined |
|
141
|
2
|
50
|
|
|
|
116
|
return unless $self->{$base}; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Prepend path with base |
|
144
|
2
|
|
|
|
|
12
|
my $basepath = Mojo::Path->new($self->{$base}); |
|
145
|
2
|
|
|
|
|
30
|
unshift @{$url->path->parts}, @{$basepath->parts}; |
|
|
2
|
|
|
|
|
7
|
|
|
|
2
|
|
|
|
|
39
|
|
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# Inherit leading slash from basepath |
|
148
|
2
|
|
|
|
|
149
|
$url->path->leading_slash($basepath->leading_slash); |
|
149
|
|
|
|
|
|
|
|
|
150
|
2
|
|
|
|
|
160
|
return $url->to_string; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__DATA__ |