line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::TableOfContents; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24492
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
443
|
use Kwiki::Plugin '-Base'; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
7
|
|
|
|
|
|
|
use IO::All; |
8
|
|
|
|
|
|
|
use JSON; |
9
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
const class_title => 'Table of Contents'; |
12
|
|
|
|
|
|
|
const class_id => 'toc'; |
13
|
|
|
|
|
|
|
const javascript_file => 'jstree.js'; |
14
|
|
|
|
|
|
|
const css_file => 'jstree.css'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub register { |
17
|
|
|
|
|
|
|
my $registry = shift; |
18
|
|
|
|
|
|
|
$registry->add(prerequisite => 'prototype'); |
19
|
|
|
|
|
|
|
$registry->add(prerequisite => 'scriptaculous'); |
20
|
|
|
|
|
|
|
$registry->add(prerequisite => 'json'); |
21
|
|
|
|
|
|
|
$registry->add(preload => 'toc'); |
22
|
|
|
|
|
|
|
$registry->add(action => 'save_toc'); |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub save_toc { |
26
|
|
|
|
|
|
|
CGI::param('structure') > $self->structure_file; |
27
|
|
|
|
|
|
|
return 'success'; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub structure_file { |
31
|
|
|
|
|
|
|
my $path = $self->plugin_directory; |
32
|
|
|
|
|
|
|
io($path)->mkpath unless io($path)->exists; |
33
|
|
|
|
|
|
|
$path = io->catfile($path, 'structure'); |
34
|
|
|
|
|
|
|
unless($path->exists) { |
35
|
|
|
|
|
|
|
'[]' > $path; |
36
|
|
|
|
|
|
|
$path->close; |
37
|
|
|
|
|
|
|
$path->open; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
return $path; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub html { |
43
|
|
|
|
|
|
|
my $wrap = defined $_[0] |
44
|
|
|
|
|
|
|
? sub { return $_[0]; } |
45
|
|
|
|
|
|
|
: sub { return qq{ |
46
|
|
|
|
|
|
|
style="display: none">$_[0]}}; |
47
|
|
|
|
|
|
|
return $wrap->(join('', map { |
48
|
|
|
|
|
|
|
my $link = $_->{data}->{href}; |
49
|
|
|
|
|
|
|
$link = '#' if $link eq ''; |
50
|
|
|
|
|
|
|
my $class = $link eq '#' ? ' class="category"' : ''; |
51
|
|
|
|
|
|
|
my $text = $_->{data}->{text}; |
52
|
|
|
|
|
|
|
my $subtree = @{$_->{subtree}} > 0 |
53
|
|
|
|
|
|
|
? ''.$self->html($_->{subtree}).' ' |
54
|
|
|
|
|
|
|
: ''; |
55
|
|
|
|
|
|
|
qq{$text$subtree}; |
56
|
|
|
|
|
|
|
} defined $_[0] ?@{$_[0]}:@{jsonToObj($self->structure_file->slurp)})); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
1; # End of Kwiki::TableOfContents |
60
|
|
|
|
|
|
|
__DATA__ |