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 | *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; |
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 | |
|
|
30 | our %wiki; |
|
|
31 | |
|
|
32 | sub load_docwiki { |
|
|
33 | *wiki = Storable::retrieve $_[0]; |
|
|
34 | } |
18 | |
35 | |
19 | sub goto_document($) { |
36 | sub goto_document($) { |
20 | $goto_document->(split /\//, $_[0]); |
37 | $goto_document->(split /\//, $_[0]); |
21 | } |
38 | } |
22 | |
39 | |
… | |
… | |
25 | |
42 | |
26 | return 1 unless @path; |
43 | return 1 unless @path; |
27 | |
44 | |
28 | my $kw = lc pop @path; |
45 | my $kw = lc pop @path; |
29 | |
46 | |
30 | $node = $node->{parent} |
47 | $node = $node->[N_PARENT] |
31 | or return 0; |
48 | or return 0; |
32 | |
49 | |
|
|
50 | #TODO: maybe get rid of lowercasing? |
33 | return ! ! grep $_ eq $kw, @{ $node->{kw} }; |
51 | return scalar grep lc eq $kw, @{ $node->[N_KW] }; |
34 | } |
52 | } |
35 | |
53 | |
36 | sub find(@) { |
54 | sub find(@) { |
37 | my (@path) = @_; |
55 | my (@path) = @_; |
38 | |
56 | |
… | |
… | |
43 | # TODO: make sure results are unique |
61 | # TODO: make sure results are unique |
44 | |
62 | |
45 | grep { is_prefix_of $_, @path } |
63 | grep { is_prefix_of $_, @path } |
46 | map @$_, |
64 | map @$_, |
47 | $kw eq "*" ? @wiki{sort keys %wiki} |
65 | $kw eq "*" ? @wiki{sort keys %wiki} |
48 | : grep $_, $wiki{$kw} |
66 | : $wiki{$kw} || () |
49 | } |
67 | } |
50 | |
68 | |
51 | sub full_path_of($) { |
69 | sub full_path_of($) { |
52 | my ($node) = @_; |
70 | my ($node) = @_; |
53 | |
71 | |
54 | my @path; |
72 | my @path; |
55 | |
73 | |
56 | # skip toplevel hierarchy pod/, because its not a document |
74 | # skip toplevel hierarchy pod/, because its not a document |
57 | while ($node->{parent}) { |
75 | while ($node->[N_PARENT]) { |
58 | unshift @path, $node; |
76 | unshift @path, $node; |
59 | $node = $node->{parent}; |
77 | $node = $node->[N_PARENT]; |
60 | } |
78 | } |
61 | |
79 | |
62 | @path |
80 | @path |
63 | } |
81 | } |
64 | |
82 | |
65 | sub full_path($) { |
83 | sub full_path($) { |
66 | join "/", map $_->{kw}[0], &full_path_of |
84 | join "/", map $_->[N_KW][0], &full_path_of |
67 | } |
85 | } |
68 | |
86 | |
69 | sub section_of($) { |
87 | sub section_of($) { |
70 | my ($node) = @_; |
88 | my ($node) = @_; |
71 | |
89 | |
72 | my $doc = $node->{doc}; |
90 | my $doc = $node->[N_DOC]; |
73 | my $par = $node->{par}; |
91 | my $par = $node->[N_PAR]; |
74 | my $lvl = $node->{level}; |
92 | my $lvl = $node->[N_LEVEL]; |
75 | |
93 | |
76 | my @res; |
94 | my @res; |
77 | |
95 | |
78 | do { |
96 | do { |
79 | my $p = $doc->[$par]; |
97 | my $p = $doc->[$par]; |
80 | |
98 | |
81 | if (length $p->{markup}) { |
99 | if (length $p->[P_MARKUP]) { |
82 | push @res, { |
100 | push @res, { |
83 | markup => $p->{markup}, |
101 | markup => $p->[P_MARKUP], |
84 | indent => $p->{indent}, |
102 | indent => $p->[P_INDENT], |
85 | }; |
103 | }; |
86 | } |
104 | } |
87 | } while $doc->[++$par]{level} > $lvl; |
105 | } while $doc->[++$par][P_LEVEL] > $lvl; |
88 | |
106 | |
89 | @res |
107 | @res |
90 | } |
108 | } |
91 | |
109 | |
92 | sub section(@) { |
110 | sub section(@) { |
… | |
… | |
105 | $_[1]{$type}($_, @arg) |
123 | $_[1]{$type}($_, @arg) |
106 | }ogex; |
124 | }ogex; |
107 | } |
125 | } |
108 | } |
126 | } |
109 | |
127 | |
|
|
128 | my %as_common = ( |
|
|
129 | h1 => sub { |
|
|
130 | "\n\n<span foreground='#ffff00' size='x-large'>$_[1]</span>\n" |
|
|
131 | }, |
|
|
132 | h2 => sub { |
|
|
133 | "\n\n<span foreground='#ccccff' size='large'>$_[1]</span>\n" |
|
|
134 | }, |
|
|
135 | h3 => sub { |
|
|
136 | "\n\n<span size='large'>$_[1]</span>\n" |
|
|
137 | }, |
|
|
138 | ); |
|
|
139 | |
110 | my %as_label = ( |
140 | my %as_label = ( |
|
|
141 | %as_common, |
111 | image => sub { |
142 | image => sub { |
112 | my ($par, $path) = @_; |
143 | my ($par, $path) = @_; |
113 | |
144 | |
114 | "<small>img</small>" |
145 | "<small>img</small>" |
115 | }, |
146 | }, |
116 | link => sub { |
147 | link => sub { |
117 | my ($par, $text, $link) = @_; |
148 | my ($par, $text, $link) = @_; |
118 | |
149 | |
119 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>" |
150 | "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>" |
120 | }, |
151 | }, |
121 | ); |
152 | ); |
122 | |
153 | |
123 | sub as_label(@) { |
154 | sub as_label(@) { |
124 | thaw_section @_, %as_label; |
155 | thaw_section @_, %as_label; |
… | |
… | |
133 | |
164 | |
134 | $text |
165 | $text |
135 | } |
166 | } |
136 | |
167 | |
137 | my %as_paragraphs = ( |
168 | my %as_paragraphs = ( |
|
|
169 | %as_common, |
138 | image => sub { |
170 | image => sub { |
139 | my ($par, $path) = @_; |
171 | my ($par, $path, $flags) = @_; |
140 | |
172 | |
141 | push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; |
173 | push @{ $par->{widget} }, new DC::UI::Image path => $path, |
|
|
174 | $flags & 1 ? (max_h => $::FONTSIZE) : (); |
142 | |
175 | |
143 | "\x{fffc}" |
176 | "\x{fffc}" |
144 | }, |
177 | }, |
145 | link => sub { |
178 | link => sub { |
146 | my ($par, $text, $link) = @_; |
179 | my ($par, $text, $link) = @_; |
147 | |
180 | |
148 | push @{ $par->{widget} }, new CFPlus::UI::Label |
181 | push @{ $par->{widget} }, new DC::UI::Label |
149 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>", |
182 | markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>", |
150 | size => 0.8, |
183 | fontsize => 0.8, |
151 | can_hover => 1, |
184 | can_hover => 1, |
152 | can_events => 1, |
185 | can_events => 1, |
153 | padding_x => 0, |
186 | padding_x => 0, |
154 | padding_y => 0, |
187 | padding_y => 0, |
155 | tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", |
188 | tooltip => "Go to <i>" . (DC::asxml $link) . "</i>", |
156 | on_button_up => sub { |
189 | on_button_up => sub { |
157 | goto_document $link; |
190 | goto_document $link; |
158 | }; |
191 | }; |
159 | |
192 | |
160 | "\x{fffc}" |
193 | "\x{fffc}" |