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 $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 | # 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"; |
|
|
31 | |
|
|
32 | sub goto_document($) { |
|
|
33 | $goto_document->(split /\//, $_[0]); |
|
|
34 | } |
18 | |
35 | |
19 | sub is_prefix_of($@) { |
36 | sub is_prefix_of($@) { |
20 | my ($node, @path) = @_; |
37 | my ($node, @path) = @_; |
21 | |
38 | |
22 | return 1 unless @path; |
39 | return 1 unless @path; |
23 | |
40 | |
24 | my $kw = pop @path; |
41 | my $kw = lc pop @path; |
25 | |
42 | |
26 | $node = $node->{parent} |
43 | $node = $node->{parent} |
27 | or return 0; |
44 | or return 0; |
28 | |
45 | |
29 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
46 | return scalar grep $_ eq $kw, @{ $node->{kw} }; |
30 | } |
47 | } |
31 | |
48 | |
32 | sub find(@) { |
49 | sub find(@) { |
33 | my (@path) = @_; |
50 | my (@path) = @_; |
34 | |
51 | |
35 | return unless @path; |
52 | return unless @path; |
36 | |
53 | |
37 | my $kw = pop @path; |
54 | my $kw = lc pop @path; |
38 | |
55 | |
39 | # TODO: make sure results are unique |
56 | # TODO: make sure results are unique |
40 | |
57 | |
41 | grep { is_prefix_of $_, @path } |
58 | grep { is_prefix_of $_, @path } |
42 | map @$_, |
59 | map @$_, |
43 | $kw eq "*" ? @wiki{sort keys %wiki} |
60 | $kw eq "*" ? @wiki{sort keys %wiki} |
44 | : grep $_, $wiki{$kw} |
61 | : $wiki{$kw} || () |
45 | } |
62 | } |
46 | |
63 | |
47 | sub full_path_of($) { |
64 | sub full_path_of($) { |
48 | my ($node) = @_; |
65 | my ($node) = @_; |
49 | |
66 | |
50 | my $path = $node->{kw}[0]; |
67 | my @path; |
51 | $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 | |
52 | $path |
75 | @path |
|
|
76 | } |
|
|
77 | |
|
|
78 | sub full_path($) { |
|
|
79 | join "/", map $_->{kw}[0], &full_path_of |
53 | } |
80 | } |
54 | |
81 | |
55 | sub section_of($) { |
82 | sub section_of($) { |
56 | my ($node) = @_; |
83 | my ($node) = @_; |
57 | |
84 | |
… | |
… | |
62 | my @res; |
89 | my @res; |
63 | |
90 | |
64 | do { |
91 | do { |
65 | my $p = $doc->[$par]; |
92 | my $p = $doc->[$par]; |
66 | |
93 | |
67 | if (length $p->{markup}) { |
94 | if (length $p->[P_MARKUP]) { |
68 | push @res, { |
95 | push @res, { |
69 | markup => $p->{markup}, |
96 | markup => $p->[P_MARKUP], |
70 | indent => $p->{indent}, |
97 | indent => $p->[P_INDENT], |
71 | }; |
98 | }; |
72 | } |
99 | } |
73 | } while $doc->[++$par]{level} > $lvl; |
100 | } while $doc->[++$par][P_LEVEL] > $lvl; |
74 | |
101 | |
75 | @res |
102 | @res |
76 | } |
103 | } |
77 | |
104 | |
78 | sub section(@) { |
105 | sub section(@) { |
… | |
… | |
100 | "<small>img</small>" |
127 | "<small>img</small>" |
101 | }, |
128 | }, |
102 | link => sub { |
129 | link => sub { |
103 | my ($par, $text, $link) = @_; |
130 | my ($par, $text, $link) = @_; |
104 | |
131 | |
105 | "<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>" |
106 | }, |
133 | }, |
107 | ); |
134 | ); |
108 | |
135 | |
109 | sub as_label(@) { |
136 | sub as_label(@) { |
110 | thaw_section @_, %as_label; |
137 | thaw_section @_, %as_label; |
… | |
… | |
120 | $text |
147 | $text |
121 | } |
148 | } |
122 | |
149 | |
123 | my %as_paragraphs = ( |
150 | my %as_paragraphs = ( |
124 | image => sub { |
151 | image => sub { |
125 | my ($par, $path) = @_; |
152 | my ($par, $path, $flags) = @_; |
126 | |
153 | |
127 | 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) : (); |
128 | |
156 | |
129 | "\x{fffc}" |
157 | "\x{fffc}" |
130 | }, |
158 | }, |
131 | link => sub { |
159 | link => sub { |
132 | my ($par, $text, $link) = @_; |
160 | my ($par, $text, $link) = @_; |
133 | |
161 | |
134 | push @{ $par->{widget} }, new CFPlus::UI::Label |
162 | push @{ $par->{widget} }, new DC::UI::Label |
135 | 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>", |
136 | size => 0.8, |
164 | fontsize => 0.8, |
137 | can_hover => 1, |
165 | can_hover => 1, |
138 | can_events => 1, |
166 | can_events => 1, |
139 | padding_x => 0, |
167 | padding_x => 0, |
140 | padding_y => 0, |
168 | padding_y => 0, |
|
|
169 | tooltip => "Go to <i>" . (DC::asxml $link) . "</i>", |
141 | on_button_up => sub { |
170 | on_button_up => sub { |
142 | $on_link->(split /\//, $link); |
171 | goto_document $link; |
143 | }; |
172 | }; |
144 | |
173 | |
145 | "\x{fffc}" |
174 | "\x{fffc}" |
146 | }, |
175 | }, |
147 | ); |
176 | ); |