… | |
… | |
5 | |
5 | |
6 | use Storable; |
6 | use Storable; |
7 | |
7 | |
8 | our $VERSION = 1; |
8 | our $VERSION = 1; |
9 | |
9 | |
10 | our $on_link = sub { }; |
10 | our $goto_document = sub { }; |
11 | our %wiki; |
11 | our %wiki; |
12 | |
12 | |
13 | my $MA_BEG = "\x{fcd0}"; |
13 | my $MA_BEG = "\x{fcd0}"; |
14 | my $MA_SEP = "\x{fcd1}"; |
14 | my $MA_SEP = "\x{fcd1}"; |
15 | my $MA_END = "\x{fcd2}"; |
15 | my $MA_END = "\x{fcd2}"; |
16 | |
16 | |
17 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
17 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
18 | |
18 | |
|
|
19 | sub goto_document($) { |
|
|
20 | $goto_document->(split /\//, $_[0]); |
|
|
21 | } |
|
|
22 | |
19 | sub is_prefix_of($@) { |
23 | sub is_prefix_of($@) { |
20 | my ($node, @path) = @_; |
24 | my ($node, @path) = @_; |
21 | |
25 | |
22 | return 1 unless @path; |
26 | return 1 unless @path; |
23 | |
27 | |
24 | my $kw = pop @path; |
28 | my $kw = lc pop @path; |
25 | |
29 | |
26 | $node = $node->{parent} |
30 | $node = $node->{parent} |
27 | or return 0; |
31 | or return 0; |
28 | |
32 | |
29 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
33 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
… | |
… | |
32 | sub find(@) { |
36 | sub find(@) { |
33 | my (@path) = @_; |
37 | my (@path) = @_; |
34 | |
38 | |
35 | return unless @path; |
39 | return unless @path; |
36 | |
40 | |
37 | my $kw = pop @path; |
41 | my $kw = lc pop @path; |
38 | |
42 | |
39 | # TODO: make sure results are unique |
43 | # TODO: make sure results are unique |
40 | |
44 | |
41 | grep { is_prefix_of $_, @path } |
45 | grep { is_prefix_of $_, @path } |
42 | map @$_, |
46 | map @$_, |
… | |
… | |
45 | } |
49 | } |
46 | |
50 | |
47 | sub full_path_of($) { |
51 | sub full_path_of($) { |
48 | my ($node) = @_; |
52 | my ($node) = @_; |
49 | |
53 | |
50 | my $path = $node->{kw}[0]; |
54 | my @path; |
51 | $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; |
55 | |
|
|
56 | # skip toplevel hierarchy pod/, because its not a document |
|
|
57 | while ($node->{parent}) { |
|
|
58 | unshift @path, $node; |
|
|
59 | $node = $node->{parent}; |
|
|
60 | } |
|
|
61 | |
52 | $path |
62 | @path |
|
|
63 | } |
|
|
64 | |
|
|
65 | sub full_path($) { |
|
|
66 | join "/", map $_->{kw}[0], &full_path_of |
53 | } |
67 | } |
54 | |
68 | |
55 | sub section_of($) { |
69 | sub section_of($) { |
56 | my ($node) = @_; |
70 | my ($node) = @_; |
57 | |
71 | |
… | |
… | |
136 | size => 0.8, |
150 | size => 0.8, |
137 | can_hover => 1, |
151 | can_hover => 1, |
138 | can_events => 1, |
152 | can_events => 1, |
139 | padding_x => 0, |
153 | padding_x => 0, |
140 | padding_y => 0, |
154 | padding_y => 0, |
|
|
155 | tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", |
141 | on_button_up => sub { |
156 | on_button_up => sub { |
142 | $on_link->(split /\//, $link); |
157 | goto_document $link; |
143 | }; |
158 | }; |
144 | |
159 | |
145 | "\x{fffc}" |
160 | "\x{fffc}" |
146 | }, |
161 | }, |
147 | ); |
162 | ); |