1 | package CFPlus::Pod; |
1 | package CFPlus::Pod; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
|
|
4 | use utf8; |
4 | |
5 | |
5 | use Storable; |
6 | use Storable; |
6 | |
7 | |
7 | our $VERSION = 1; |
8 | our $VERSION = 1; |
8 | |
9 | |
|
|
10 | our $goto_document = sub { }; |
9 | our %wiki; |
11 | our %wiki; |
10 | |
12 | |
11 | my $MA_BEG = "\x{fcd0}"; |
13 | my $MA_BEG = "\x{fcd0}"; |
12 | my $MA_SEP = "\x{fcd1}"; |
14 | my $MA_SEP = "\x{fcd1}"; |
13 | my $MA_END = "\x{fcd2}"; |
15 | my $MA_END = "\x{fcd2}"; |
14 | |
16 | |
15 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
17 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
16 | |
18 | |
|
|
19 | sub goto_document($) { |
|
|
20 | $goto_document->(split /\//, $_[0]); |
|
|
21 | } |
|
|
22 | |
17 | sub is_prefix_of($@) { |
23 | sub is_prefix_of($@) { |
18 | my ($node, @path) = @_; |
24 | my ($node, @path) = @_; |
19 | |
25 | |
20 | return 1 unless @path; |
26 | return 1 unless @path; |
21 | |
27 | |
22 | my $kw = pop @path; |
28 | my $kw = lc pop @path; |
23 | |
29 | |
24 | $node = $node->{parent} |
30 | $node = $node->{parent} |
25 | or return 0; |
31 | or return 0; |
26 | |
32 | |
27 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
33 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
… | |
… | |
30 | sub find(@) { |
36 | sub find(@) { |
31 | my (@path) = @_; |
37 | my (@path) = @_; |
32 | |
38 | |
33 | return unless @path; |
39 | return unless @path; |
34 | |
40 | |
35 | my $kw = pop @path; |
41 | my $kw = lc pop @path; |
36 | |
42 | |
37 | # TODO: make sure results are unique |
43 | # TODO: make sure results are unique |
38 | |
44 | |
39 | grep { is_prefix_of $_, @path } |
45 | grep { is_prefix_of $_, @path } |
40 | map @$_, |
46 | map @$_, |
… | |
… | |
43 | } |
49 | } |
44 | |
50 | |
45 | sub full_path_of($) { |
51 | sub full_path_of($) { |
46 | my ($node) = @_; |
52 | my ($node) = @_; |
47 | |
53 | |
48 | my $path = $node->{kw}[0]; |
54 | my @path; |
49 | $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 | |
50 | $path |
62 | @path |
|
|
63 | } |
|
|
64 | |
|
|
65 | sub full_path($) { |
|
|
66 | join "/", map $_->{kw}[0], &full_path_of |
51 | } |
67 | } |
52 | |
68 | |
53 | sub section_of($) { |
69 | sub section_of($) { |
54 | my ($node) = @_; |
70 | my ($node) = @_; |
55 | |
71 | |
… | |
… | |
96 | my ($par, $path) = @_; |
112 | my ($par, $path) = @_; |
97 | |
113 | |
98 | "<small>img</small>" |
114 | "<small>img</small>" |
99 | }, |
115 | }, |
100 | link => sub { |
116 | link => sub { |
101 | my ($par, $link) = @_; |
117 | my ($par, $text, $link) = @_; |
102 | |
118 | |
103 | "<big>" . (CFPlus::asxml $link) . "</big>" |
119 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>" |
104 | }, |
120 | }, |
105 | ); |
121 | ); |
106 | |
122 | |
107 | sub as_label(@) { |
123 | sub as_label(@) { |
108 | thaw_section @_, %as_label; |
124 | thaw_section @_, %as_label; |
… | |
… | |
122 | image => sub { |
138 | image => sub { |
123 | my ($par, $path) = @_; |
139 | my ($par, $path) = @_; |
124 | |
140 | |
125 | push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; |
141 | push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; |
126 | |
142 | |
127 | "\x{FFFC}" |
143 | "\x{fffc}" |
128 | }, |
144 | }, |
129 | link => sub { |
145 | link => sub { |
130 | my ($par, $link) = @_; |
146 | my ($par, $text, $link) = @_; |
131 | |
147 | |
|
|
148 | push @{ $par->{widget} }, new CFPlus::UI::Label |
|
|
149 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>", |
|
|
150 | size => 0.8, |
|
|
151 | can_hover => 1, |
|
|
152 | can_events => 1, |
|
|
153 | padding_x => 0, |
|
|
154 | padding_y => 0, |
132 | "<big>" . (CFPlus::asxml $link) . "</big>" |
155 | tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", |
|
|
156 | on_button_up => sub { |
|
|
157 | goto_document $link; |
|
|
158 | }; |
|
|
159 | |
|
|
160 | "\x{fffc}" |
133 | }, |
161 | }, |
134 | ); |
162 | ); |
135 | |
163 | |
136 | sub as_paragraphs(@) { |
164 | sub as_paragraphs(@) { |
137 | thaw_section @_, %as_paragraphs; |
165 | thaw_section @_, %as_paragraphs; |