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.13 by root, Mon Aug 14 19:17:09 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 $goto_document = 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}
18 35
19sub goto_document($) { 36sub 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
33 return ! ! grep $_ eq $kw, @{ $node->{kw} }; 50 return scalar grep $_ eq $kw, @{ $node->[N_KW] };
34} 51}
35 52
36sub find(@) { 53sub find(@) {
37 my (@path) = @_; 54 my (@path) = @_;
38 55
43 # TODO: make sure results are unique 60 # TODO: make sure results are unique
44 61
45 grep { is_prefix_of $_, @path } 62 grep { is_prefix_of $_, @path }
46 map @$_, 63 map @$_,
47 $kw eq "*" ? @wiki{sort keys %wiki} 64 $kw eq "*" ? @wiki{sort keys %wiki}
48 : grep $_, $wiki{$kw} 65 : $wiki{$kw} || ()
49} 66}
50 67
51sub full_path_of($) { 68sub full_path_of($) {
52 my ($node) = @_; 69 my ($node) = @_;
53 70
54 my @path; 71 my @path;
55 72
56 # skip toplevel hierarchy pod/, because its not a document 73 # skip toplevel hierarchy pod/, because its not a document
57 while ($node->{parent}) { 74 while ($node->[N_PARENT]) {
58 unshift @path, $node; 75 unshift @path, $node;
59 $node = $node->{parent}; 76 $node = $node->[N_PARENT];
60 } 77 }
61 78
62 @path 79 @path
63} 80}
64 81
65sub full_path($) { 82sub full_path($) {
66 join "/", map $_->{kw}[0], &full_path_of 83 join "/", map $_->[N_KW][0], &full_path_of
67} 84}
68 85
69sub section_of($) { 86sub section_of($) {
70 my ($node) = @_; 87 my ($node) = @_;
71 88
72 my $doc = $node->{doc}; 89 my $doc = $node->[N_DOC];
73 my $par = $node->{par}; 90 my $par = $node->[N_PAR];
74 my $lvl = $node->{level}; 91 my $lvl = $node->[N_LEVEL];
75 92
76 my @res; 93 my @res;
77 94
78 do { 95 do {
79 my $p = $doc->[$par]; 96 my $p = $doc->[$par];
80 97
81 if (length $p->{markup}) { 98 if (length $p->[P_MARKUP]) {
82 push @res, { 99 push @res, {
83 markup => $p->{markup}, 100 markup => $p->[P_MARKUP],
84 indent => $p->{indent}, 101 indent => $p->[P_INDENT],
85 }; 102 };
86 } 103 }
87 } while $doc->[++$par]{level} > $lvl; 104 } while $doc->[++$par][P_LEVEL] > $lvl;
88 105
89 @res 106 @res
90} 107}
91 108
92sub section(@) { 109sub section(@) {
114 "<small>img</small>" 131 "<small>img</small>"
115 }, 132 },
116 link => sub { 133 link => sub {
117 my ($par, $text, $link) = @_; 134 my ($par, $text, $link) = @_;
118 135
119 "<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>"
120 }, 137 },
121); 138);
122 139
123sub as_label(@) { 140sub as_label(@) {
124 thaw_section @_, %as_label; 141 thaw_section @_, %as_label;
136 153
137my %as_paragraphs = ( 154my %as_paragraphs = (
138 image => sub { 155 image => sub {
139 my ($par, $path, $flags) = @_; 156 my ($par, $path, $flags) = @_;
140 157
141 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path, 158 push @{ $par->{widget} }, new DC::UI::Image path => $path,
142 $flags & 1 ? (max_h => $::FONTSIZE) : (); 159 $flags & 1 ? (max_h => $::FONTSIZE) : ();
143 160
144 "\x{fffc}" 161 "\x{fffc}"
145 }, 162 },
146 link => sub { 163 link => sub {
147 my ($par, $text, $link) = @_; 164 my ($par, $text, $link) = @_;
148 165
149 push @{ $par->{widget} }, new CFPlus::UI::Label 166 push @{ $par->{widget} }, new DC::UI::Label
150 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>",
151 fontsize => 0.8, 168 fontsize => 0.8,
152 can_hover => 1, 169 can_hover => 1,
153 can_events => 1, 170 can_events => 1,
154 padding_x => 0, 171 padding_x => 0,
155 padding_y => 0, 172 padding_y => 0,
156 tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", 173 tooltip => "Go to <i>" . (DC::asxml $link) . "</i>",
157 on_button_up => sub { 174 on_button_up => sub {
158 goto_document $link; 175 goto_document $link;
159 }; 176 };
160 177
161 "\x{fffc}" 178 "\x{fffc}"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines