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.7 by root, Sun Aug 13 18:48:56 2006 UTC vs.
Revision 1.19 by root, Tue Mar 25 02:12:35 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines