ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
(Generate patch)

Comparing deliantra/Deliantra-Client/DC/Pod.pm (file contents):
Revision 1.8 by root, Sun Aug 13 19:47:05 2006 UTC vs.
Revision 1.20 by root, Sun Mar 30 00:25:11 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines