line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Bootylicious::Plugin::TocJquery; |
2
|
1
|
|
|
1
|
|
24342
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
7
|
use base 'Mojolicious::Plugin'; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
963
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
__PACKAGE__->attr('toc_tag' => '%TOC%'); |
9
|
|
|
|
|
|
|
__PACKAGE__->attr('toc_js_src' => |
10
|
|
|
|
|
|
|
'http://samaxesjs.googlecode.com/files/jquery.toc-1.0.2.min.js'); |
11
|
|
|
|
|
|
|
__PACKAGE__->attr('toc_exclude' => 'h1,#descr,#title,#footer,#nottoc'); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub register { |
15
|
0
|
|
|
0
|
1
|
|
my ($self, $app, $args) = @_; |
16
|
0
|
|
0
|
|
|
|
$args ||= {}; |
17
|
0
|
0
|
|
|
|
|
$self->toc_tag($args->{'toc_tag'} ) if $args->{'toc_tag'}; |
18
|
0
|
0
|
|
|
|
|
$self->toc_js_src($args->{'toc_js_src'} ) if $args->{'toc_js_src'}; |
19
|
0
|
0
|
|
|
|
|
$self->toc_exclude($args->{'toc_exclude'} ) if $args->{'toc_exclude'}; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
$app->plugins->add_hook(after_dispatch => sub { |
22
|
0
|
|
|
0
|
|
|
shift;#Skip Mojolicious::Plugins obj |
23
|
0
|
|
|
|
|
|
my $c = shift; |
24
|
0
|
|
|
|
|
|
my $path = $c->req->url->path; |
25
|
0
|
|
|
|
|
|
my $body = $c->res->body; |
26
|
0
|
|
|
|
|
|
my $toc_tag = $self->toc_tag; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#cleanup %TOC% if not article |
29
|
0
|
0
|
|
|
|
|
if ($path !~ /^\/articles/) { |
30
|
0
|
|
|
|
|
|
$body =~ s/$toc_tag//g; |
31
|
0
|
|
|
|
|
|
$c->res->body($body); |
32
|
0
|
|
|
|
|
|
return; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $toc_div = $self->_toc_div; |
36
|
0
|
|
|
|
|
|
my $toc_js = $self->_toc_js; |
37
|
0
|
|
|
|
|
|
$body =~ s/<\/[hH][eE][aA][dD]>/$toc_js <\/head>/; |
38
|
0
|
|
|
|
|
|
$body =~ s/$toc_tag/$toc_div/; |
39
|
0
|
|
|
|
|
|
$c->res->body($body); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _toc_div { |
49
|
0
|
|
|
0
|
|
|
my $self = shift; |
50
|
0
|
|
|
|
|
|
return q~~; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _toc_js { |
54
|
0
|
|
|
0
|
|
|
my $self = shift; |
55
|
0
|
|
|
|
|
|
my $src = $self->toc_js_src; |
56
|
0
|
|
|
|
|
|
my $exclude = $self->toc_exclude; |
57
|
0
|
|
|
|
|
|
return qq~ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
~; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Bootylicious::Plugin::TocJquery - load TOC (Table of Contents) jQuery plugin. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 DESCRIPTION |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
L - load TOC (Table of Contents) jQuery plugin for bootylicious articles |
77
|
|
|
|
|
|
|
The TOC plugin dynamically builds a table of contents from the headings in a document and prepends legal-style section numbers to each of the headings: |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
* adds numeration in front of all headings, |
80
|
|
|
|
|
|
|
* generates an HTML table of contents |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 VERSION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
version 0.06 |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 SYNOPSIS |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Register TocJquery and AjaxLibLoader plugins in a configuration file (bootylicious.conf), add line |
89
|
|
|
|
|
|
|
like this: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
"plugins" : [ |
92
|
|
|
|
|
|
|
"ajax_lib_loader" , {"jquery" : "on"}, |
93
|
|
|
|
|
|
|
"toc_jquery", {"toc_tag" : "%TOC%"} |
94
|
|
|
|
|
|
|
] |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Insert into your post tag %TOC%, e.g.: |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 NAME |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Futurama characters |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
%TOC% |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Futurama is essentially a workplace sitcom whose plot revolves around the Planet Express interplanetary delivery company and its employees, |
105
|
|
|
|
|
|
|
a small group that doesn't conform to future society. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
[cut] |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 Philip J. Fry |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Fry is a dim-witted, immature, slovenly pizza delivery boy who falls into a cryogenic pod, |
112
|
|
|
|
|
|
|
causing it to activate and freeze him just after midnight on January 1, 2000, reawakening on New Year's Eve, 2999. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 Bender Bending RodrÃguez |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Bender is a heavy-drinking, cigar-smoking, kleptomaniacal, misanthropic, egocentric, ill-tempered robot. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 Dr. John A. Zoidberg |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Zoidberg is a lobster-like alien from the planet Decapod 10 and is the neurotic staff physician of Planet Express. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head1 TAGS |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
futurama, bender |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 C |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
String that is replaced by the TOC (Table of Contents). |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
default %TOC% |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 C |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
URL to TOC jQuery plugin library |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
default: http://samaxesjs.googlecode.com/files/jquery.toc-1.0.2.min.js |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 C |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
exlude option, see more here L |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
default: "h1,#descr,#title,#footer,#nottoc" |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 METHODS |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 C |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
This method will be called by L at startup time, |
153
|
|
|
|
|
|
|
your plugin should use this to hook into the application. |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 AUTHOR |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Konstantin Kapitanov, C<< >> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L - TOC (Table of Contents) jQuery plugin |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L, L, L, L, L |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright 2009 Konstantin Kapitanov, all rights reserved. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
172
|
|
|
|
|
|
|
under the same terms as Perl itself. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |