1 | package CFPlus::Pod; |
1 | package DC::Pod; |
2 | |
2 | |
3 | use strict; |
3 | use strict; |
4 | use utf8; |
4 | use utf8; |
5 | |
5 | |
6 | use Storable; |
6 | use Storable; |
7 | |
7 | |
8 | our $VERSION = 1; |
8 | our $VERSION = 1.03; |
9 | |
9 | |
10 | our $goto_document = 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 | # 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 | |
17 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
30 | *wiki = Storable::retrieve DC::find_rcfile "docwiki.pst"; |
18 | |
31 | |
19 | sub goto_document($) { |
32 | sub goto_document($) { |
20 | $goto_document->(split /\//, $_[0]); |
33 | $goto_document->(split /\//, $_[0]); |
21 | } |
34 | } |
22 | |
35 | |
23 | sub is_prefix_of($@) { |
36 | sub is_prefix_of($@) { |
24 | my ($node, @path) = @_; |
37 | my ($node, @path) = @_; |
25 | |
38 | |
26 | return 1 unless @path; |
39 | return 1 unless @path; |
27 | |
40 | |
28 | my $kw = pop @path; |
41 | my $kw = lc pop @path; |
29 | |
42 | |
30 | $node = $node->{parent} |
43 | $node = $node->{parent} |
31 | or return 0; |
44 | or return 0; |
32 | |
45 | |
33 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
46 | return scalar grep $_ eq $kw, @{ $node->{kw} }; |
34 | } |
47 | } |
35 | |
48 | |
36 | sub find(@) { |
49 | sub find(@) { |
37 | my (@path) = @_; |
50 | my (@path) = @_; |
38 | |
51 | |
39 | return unless @path; |
52 | return unless @path; |
40 | |
53 | |
41 | my $kw = pop @path; |
54 | my $kw = lc pop @path; |
42 | |
55 | |
43 | # TODO: make sure results are unique |
56 | # TODO: make sure results are unique |
44 | |
57 | |
45 | grep { is_prefix_of $_, @path } |
58 | grep { is_prefix_of $_, @path } |
46 | map @$_, |
59 | map @$_, |
47 | $kw eq "*" ? @wiki{sort keys %wiki} |
60 | $kw eq "*" ? @wiki{sort keys %wiki} |
48 | : grep $_, $wiki{$kw} |
61 | : $wiki{$kw} || () |
49 | } |
62 | } |
50 | |
63 | |
51 | sub full_path_of($) { |
64 | sub full_path_of($) { |
52 | my ($node) = @_; |
65 | my ($node) = @_; |
53 | |
66 | |
… | |
… | |
76 | my @res; |
89 | my @res; |
77 | |
90 | |
78 | do { |
91 | do { |
79 | my $p = $doc->[$par]; |
92 | my $p = $doc->[$par]; |
80 | |
93 | |
81 | if (length $p->{markup}) { |
94 | if (length $p->[P_MARKUP]) { |
82 | push @res, { |
95 | push @res, { |
83 | markup => $p->{markup}, |
96 | markup => $p->[P_MARKUP], |
84 | indent => $p->{indent}, |
97 | indent => $p->[P_INDENT], |
85 | }; |
98 | }; |
86 | } |
99 | } |
87 | } while $doc->[++$par]{level} > $lvl; |
100 | } while $doc->[++$par][P_LEVEL] > $lvl; |
88 | |
101 | |
89 | @res |
102 | @res |
90 | } |
103 | } |
91 | |
104 | |
92 | sub section(@) { |
105 | sub section(@) { |
… | |
… | |
114 | "<small>img</small>" |
127 | "<small>img</small>" |
115 | }, |
128 | }, |
116 | link => sub { |
129 | link => sub { |
117 | my ($par, $text, $link) = @_; |
130 | my ($par, $text, $link) = @_; |
118 | |
131 | |
119 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>" |
132 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>" |
120 | }, |
133 | }, |
121 | ); |
134 | ); |
122 | |
135 | |
123 | sub as_label(@) { |
136 | sub as_label(@) { |
124 | thaw_section @_, %as_label; |
137 | thaw_section @_, %as_label; |
… | |
… | |
134 | $text |
147 | $text |
135 | } |
148 | } |
136 | |
149 | |
137 | my %as_paragraphs = ( |
150 | my %as_paragraphs = ( |
138 | image => sub { |
151 | image => sub { |
139 | my ($par, $path) = @_; |
152 | my ($par, $path, $flags) = @_; |
140 | |
153 | |
141 | 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) : (); |
142 | |
156 | |
143 | "\x{fffc}" |
157 | "\x{fffc}" |
144 | }, |
158 | }, |
145 | link => sub { |
159 | link => sub { |
146 | my ($par, $text, $link) = @_; |
160 | my ($par, $text, $link) = @_; |
147 | |
161 | |
148 | push @{ $par->{widget} }, new CFPlus::UI::Label |
162 | push @{ $par->{widget} }, new DC::UI::Label |
149 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>", |
163 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>", |
150 | size => 0.8, |
164 | fontsize => 0.8, |
151 | can_hover => 1, |
165 | can_hover => 1, |
152 | can_events => 1, |
166 | can_events => 1, |
153 | padding_x => 0, |
167 | padding_x => 0, |
154 | padding_y => 0, |
168 | padding_y => 0, |
155 | tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", |
169 | tooltip => "Go to <i>" . (DC::asxml $link) . "</i>", |
156 | on_button_up => sub { |
170 | on_button_up => sub { |
157 | goto_document $link; |
171 | goto_document $link; |
158 | }; |
172 | }; |
159 | |
173 | |
160 | "\x{fffc}" |
174 | "\x{fffc}" |