1 | package CFPlus::Pod; |
1 | package DC::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.03; |
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 | |
|
|
17 | # nodes (order must stay as it is) |
|
|
18 | sub N_PARENT (){ 0 } |
|
|
19 | sub N_PAR (){ 1 } |
|
|
20 | sub N_LEVEL (){ 2 } |
|
|
21 | sub N_KW (){ 3 } |
|
|
22 | sub N_DOC (){ 4 } |
|
|
23 | |
|
|
24 | # paragraphs (order must stay as it is) |
|
|
25 | sub P_INDENT (){ 0 } |
|
|
26 | sub P_LEVEL (){ 1 } |
|
|
27 | sub P_MARKUP (){ 2 } |
|
|
28 | sub P_INDEX (){ 3 } |
|
|
29 | |
15 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
30 | *wiki = Storable::retrieve DC::find_rcfile "docwiki.pst"; |
|
|
31 | |
|
|
32 | sub goto_document($) { |
|
|
33 | $goto_document->(split /\//, $_[0]); |
|
|
34 | } |
16 | |
35 | |
17 | sub is_prefix_of($@) { |
36 | sub is_prefix_of($@) { |
18 | my ($node, @path) = @_; |
37 | my ($node, @path) = @_; |
19 | |
38 | |
20 | return 1 unless @path; |
39 | return 1 unless @path; |
21 | |
40 | |
22 | my $kw = pop @path; |
41 | my $kw = lc pop @path; |
23 | |
42 | |
24 | $node = $node->{parent} |
43 | $node = $node->{parent} |
25 | or return 0; |
44 | or return 0; |
26 | |
45 | |
27 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
46 | return scalar grep $_ eq $kw, @{ $node->{kw} }; |
28 | } |
47 | } |
29 | |
48 | |
30 | sub find(@) { |
49 | sub find(@) { |
31 | my (@path) = @_; |
50 | my (@path) = @_; |
32 | |
51 | |
33 | return unless @path; |
52 | return unless @path; |
34 | |
53 | |
35 | my $kw = pop @path; |
54 | my $kw = lc pop @path; |
36 | |
55 | |
37 | # TODO: make sure results are unique |
56 | # TODO: make sure results are unique |
38 | |
57 | |
39 | grep { is_prefix_of $_, @path } |
58 | grep { is_prefix_of $_, @path } |
40 | map @$_, |
59 | map @$_, |
41 | $kw eq "*" ? @wiki{sort keys %wiki} |
60 | $kw eq "*" ? @wiki{sort keys %wiki} |
42 | : grep $_, $wiki{$kw} |
61 | : $wiki{$kw} || () |
43 | } |
62 | } |
44 | |
63 | |
45 | sub full_path_of($) { |
64 | sub full_path_of($) { |
46 | my ($node) = @_; |
65 | my ($node) = @_; |
47 | |
66 | |
48 | my $path = $node->{kw}[0]; |
67 | my @path; |
49 | $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; |
68 | |
|
|
69 | # skip toplevel hierarchy pod/, because its not a document |
|
|
70 | while ($node->{parent}) { |
|
|
71 | unshift @path, $node; |
|
|
72 | $node = $node->{parent}; |
|
|
73 | } |
|
|
74 | |
50 | $path |
75 | @path |
|
|
76 | } |
|
|
77 | |
|
|
78 | sub full_path($) { |
|
|
79 | join "/", map $_->{kw}[0], &full_path_of |
51 | } |
80 | } |
52 | |
81 | |
53 | sub section_of($) { |
82 | sub section_of($) { |
54 | my ($node) = @_; |
83 | my ($node) = @_; |
55 | |
84 | |
… | |
… | |
60 | my @res; |
89 | my @res; |
61 | |
90 | |
62 | do { |
91 | do { |
63 | my $p = $doc->[$par]; |
92 | my $p = $doc->[$par]; |
64 | |
93 | |
65 | if (length $p->{markup}) { |
94 | if (length $p->[P_MARKUP]) { |
66 | push @res, { |
95 | push @res, { |
67 | markup => $p->{markup}, |
96 | markup => $p->[P_MARKUP], |
68 | indent => $p->{indent}, |
97 | indent => $p->[P_INDENT], |
69 | }; |
98 | }; |
70 | } |
99 | } |
71 | } while $doc->[++$par]{level} > $lvl; |
100 | } while $doc->[++$par][P_LEVEL] > $lvl; |
72 | |
101 | |
73 | @res |
102 | @res |
74 | } |
103 | } |
75 | |
104 | |
76 | sub section(@) { |
105 | sub section(@) { |
… | |
… | |
96 | my ($par, $path) = @_; |
125 | my ($par, $path) = @_; |
97 | |
126 | |
98 | "<small>img</small>" |
127 | "<small>img</small>" |
99 | }, |
128 | }, |
100 | link => sub { |
129 | link => sub { |
101 | my ($par, $link) = @_; |
130 | my ($par, $text, $link) = @_; |
102 | |
131 | |
103 | "<big>" . (CFPlus::asxml $link) . "</big>" |
132 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>" |
104 | }, |
133 | }, |
105 | ); |
134 | ); |
106 | |
135 | |
107 | sub as_label(@) { |
136 | sub as_label(@) { |
108 | thaw_section @_, %as_label; |
137 | thaw_section @_, %as_label; |
… | |
… | |
118 | $text |
147 | $text |
119 | } |
148 | } |
120 | |
149 | |
121 | my %as_paragraphs = ( |
150 | my %as_paragraphs = ( |
122 | image => sub { |
151 | image => sub { |
123 | my ($par, $path) = @_; |
152 | my ($par, $path, $flags) = @_; |
124 | |
153 | |
125 | push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; |
154 | push @{ $par->{widget} }, new DC::UI::Image path => $path, |
|
|
155 | $flags & 1 ? (max_h => $::FONTSIZE) : (); |
126 | |
156 | |
127 | "\x{FFFC}" |
157 | "\x{fffc}" |
128 | }, |
158 | }, |
129 | link => sub { |
159 | link => sub { |
130 | my ($par, $link) = @_; |
160 | my ($par, $text, $link) = @_; |
131 | |
161 | |
132 | "<big>" . (CFPlus::asxml $link) . "</big>" |
162 | push @{ $par->{widget} }, new DC::UI::Label |
|
|
163 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>", |
|
|
164 | fontsize => 0.8, |
|
|
165 | can_hover => 1, |
|
|
166 | can_events => 1, |
|
|
167 | padding_x => 0, |
|
|
168 | padding_y => 0, |
|
|
169 | tooltip => "Go to <i>" . (DC::asxml $link) . "</i>", |
|
|
170 | on_button_up => sub { |
|
|
171 | goto_document $link; |
|
|
172 | }; |
|
|
173 | |
|
|
174 | "\x{fffc}" |
133 | }, |
175 | }, |
134 | ); |
176 | ); |
135 | |
177 | |
136 | sub as_paragraphs(@) { |
178 | sub as_paragraphs(@) { |
137 | thaw_section @_, %as_paragraphs; |
179 | thaw_section @_, %as_paragraphs; |