1 | package DC::Pod; |
1 | package DC::Pod; |
2 | |
2 | |
3 | use strict; |
3 | use common::sense; |
4 | use utf8; |
|
|
5 | |
4 | |
6 | use Storable; |
5 | use Storable; |
7 | |
6 | |
8 | our $VERSION = 1.03; |
7 | our $VERSION = 1.03; |
9 | |
8 | |
… | |
… | |
25 | sub P_INDENT (){ 0 } |
24 | sub P_INDENT (){ 0 } |
26 | sub P_LEVEL (){ 1 } |
25 | sub P_LEVEL (){ 1 } |
27 | sub P_MARKUP (){ 2 } |
26 | sub P_MARKUP (){ 2 } |
28 | sub P_INDEX (){ 3 } |
27 | sub P_INDEX (){ 3 } |
29 | |
28 | |
30 | *wiki = Storable::retrieve DC::find_rcfile "docwiki.pst"; |
29 | our %wiki; |
|
|
30 | |
|
|
31 | sub load_docwiki { |
|
|
32 | *wiki = Storable::retrieve $_[0]; |
|
|
33 | } |
31 | |
34 | |
32 | sub goto_document($) { |
35 | sub goto_document($) { |
33 | $goto_document->(split /\//, $_[0]); |
36 | $goto_document->(split /\//, $_[0]); |
34 | } |
37 | } |
35 | |
38 | |
36 | sub is_prefix_of($@) { |
39 | sub is_prefix_of($@) { |
37 | my ($node, @path) = @_; |
40 | my ($node, @path) = @_; |
38 | |
41 | |
39 | return 1 unless @path; |
42 | return 1 unless @path; |
40 | |
43 | |
41 | my $kw = lc pop @path; |
44 | my $kw = pop @path; |
42 | |
45 | |
43 | $node = $node->[N_PARENT] |
46 | $node = $node->[N_PARENT] |
44 | or return 0; |
47 | or return 0; |
45 | |
48 | |
46 | return scalar grep $_ eq $kw, @{ $node->[N_KW] }; |
49 | return scalar grep $_ eq $kw, @{ $node->[N_KW] }; |
… | |
… | |
49 | sub find(@) { |
52 | sub find(@) { |
50 | my (@path) = @_; |
53 | my (@path) = @_; |
51 | |
54 | |
52 | return unless @path; |
55 | return unless @path; |
53 | |
56 | |
54 | my $kw = lc pop @path; |
57 | my $kw = pop @path; |
55 | |
58 | |
56 | # TODO: make sure results are unique |
59 | my %res = map +($_, $_), |
57 | |
|
|
58 | grep { is_prefix_of $_, @path } |
60 | grep { is_prefix_of $_, @path } |
59 | map @$_, |
61 | map @$_, |
60 | $kw eq "*" ? @wiki{sort keys %wiki} |
62 | $kw eq "*" ? values %wiki |
61 | : $wiki{$kw} || () |
63 | : $wiki{$kw} || (); |
|
|
64 | |
|
|
65 | values %res |
62 | } |
66 | } |
63 | |
67 | |
64 | sub full_path_of($) { |
68 | sub full_path_of($) { |
65 | my ($node) = @_; |
69 | my ($node) = @_; |
66 | |
70 | |
67 | my @path; |
71 | my @path; |
68 | |
72 | |
69 | # skip toplevel hierarchy pod/, because its not a document |
|
|
70 | while ($node->[N_PARENT]) { |
73 | while ($node) { |
71 | unshift @path, $node; |
74 | unshift @path, $node; |
72 | $node = $node->[N_PARENT]; |
75 | $node = $node->[N_PARENT]; |
73 | } |
76 | } |
74 | |
77 | |
75 | @path |
78 | @path |
… | |
… | |
118 | $_[1]{$type}($_, @arg) |
121 | $_[1]{$type}($_, @arg) |
119 | }ogex; |
122 | }ogex; |
120 | } |
123 | } |
121 | } |
124 | } |
122 | |
125 | |
|
|
126 | my %as_common = ( |
|
|
127 | h1 => sub { |
|
|
128 | "\n\n<span foreground='#ffff00' size='x-large'>$_[1]</span>\n" |
|
|
129 | }, |
|
|
130 | h2 => sub { |
|
|
131 | "\n\n<span foreground='#ccccff' size='large'>$_[1]</span>\n" |
|
|
132 | }, |
|
|
133 | h3 => sub { |
|
|
134 | "\n\n<span size='large'>$_[1]</span>\n" |
|
|
135 | }, |
|
|
136 | ); |
|
|
137 | |
123 | my %as_label = ( |
138 | my %as_label = ( |
|
|
139 | %as_common, |
124 | image => sub { |
140 | image => sub { |
125 | my ($par, $path) = @_; |
141 | my ($par, $path) = @_; |
126 | |
142 | |
127 | "<small>img</small>" |
143 | "<small>img</small>" |
128 | }, |
144 | }, |
… | |
… | |
146 | |
162 | |
147 | $text |
163 | $text |
148 | } |
164 | } |
149 | |
165 | |
150 | my %as_paragraphs = ( |
166 | my %as_paragraphs = ( |
|
|
167 | %as_common, |
151 | image => sub { |
168 | image => sub { |
152 | my ($par, $path, $flags) = @_; |
169 | my ($par, $path, $flags) = @_; |
153 | |
170 | |
154 | push @{ $par->{widget} }, new DC::UI::Image path => $path, |
171 | push @{ $par->{widget} }, new DC::UI::Image path => $path, |
155 | $flags & 1 ? (max_h => $::FONTSIZE) : (); |
172 | $flags & 1 ? (max_h => $::FONTSIZE) : (); |