line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kwiki::BreadCrumbs; |
2
|
1
|
|
|
1
|
|
33558
|
use Kwiki::Plugin -Base; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
4
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
const class_id => 'bread_crumbs'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
field trail => []; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub init { |
11
|
|
|
|
|
|
|
return unless $self->is_in_cgi; |
12
|
|
|
|
|
|
|
super; |
13
|
|
|
|
|
|
|
my $bread_crumbs = $self->hub->cookie->jar->{bread_crumbs} || []; |
14
|
|
|
|
|
|
|
if ($self->hub->action eq 'display') { |
15
|
|
|
|
|
|
|
my $page_id = $self->pages->current->id; |
16
|
|
|
|
|
|
|
@$bread_crumbs = grep { $_ ne $page_id } @$bread_crumbs; |
17
|
|
|
|
|
|
|
unshift @$bread_crumbs, $page_id; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
splice @$bread_crumbs, 10 |
20
|
|
|
|
|
|
|
if @$bread_crumbs > 10; |
21
|
|
|
|
|
|
|
$self->trail($bread_crumbs); |
22
|
|
|
|
|
|
|
$self->hub->cookie->jar->{bread_crumbs} = $bread_crumbs; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub register { |
26
|
|
|
|
|
|
|
my $registry = shift; |
27
|
|
|
|
|
|
|
$registry->add(status => 'bread_crumbs', |
28
|
|
|
|
|
|
|
template => 'bread_crumbs.html', |
29
|
|
|
|
|
|
|
show_if_preference => 'show_bread_crumbs', |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
$registry->add(preference => $self->show_bread_crumbs); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub show_bread_crumbs { |
35
|
|
|
|
|
|
|
my $p = $self->new_preference('show_bread_crumbs'); |
36
|
|
|
|
|
|
|
$p->query('Show How Many Bread Crumbs?'); |
37
|
|
|
|
|
|
|
$p->type('pulldown'); |
38
|
|
|
|
|
|
|
my $choices = [ |
39
|
|
|
|
|
|
|
0 => 0, |
40
|
|
|
|
|
|
|
4 => 4, |
41
|
|
|
|
|
|
|
6 => 6, |
42
|
|
|
|
|
|
|
8 => 8, |
43
|
|
|
|
|
|
|
10 => 10, |
44
|
|
|
|
|
|
|
]; |
45
|
|
|
|
|
|
|
$p->choices($choices); |
46
|
|
|
|
|
|
|
$p->default(0); |
47
|
|
|
|
|
|
|
return $p; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub html { |
51
|
|
|
|
|
|
|
my @trail = @{$self->trail}; |
52
|
|
|
|
|
|
|
my $show = $self->preferences->show_bread_crumbs->value; |
53
|
|
|
|
|
|
|
splice @trail, $show |
54
|
|
|
|
|
|
|
if @trail > $show; |
55
|
|
|
|
|
|
|
my $script_name = $self->config->script_name; |
56
|
|
|
|
|
|
|
my $pages = $self->hub->pages; |
57
|
|
|
|
|
|
|
" " . join ' < ', |
58
|
|
|
|
|
|
|
map { |
59
|
|
|
|
|
|
|
my $page = $pages->new_page($_); |
60
|
|
|
|
|
|
|
sprintf "%s\n", |
61
|
|
|
|
|
|
|
$script_name, |
62
|
|
|
|
|
|
|
$page->uri, |
63
|
|
|
|
|
|
|
$page->title; |
64
|
|
|
|
|
|
|
} @trail; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__DATA__ |