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.23 by root, Sun Mar 30 13:02:26 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
23sub is_prefix_of($@) { 40sub is_prefix_of($@) {
24 my ($node, @path) = @_; 41 my ($node, @path) = @_;
25 42
26 return 1 unless @path; 43 return 1 unless @path;
27 44
28 my $kw = lc pop @path; 45 my $kw = 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
39 return unless @path; 56 return unless @path;
40 57
41 my $kw = lc pop @path; 58 my $kw = pop @path;
42 59
43 # TODO: make sure results are unique 60 my %res = map +($_, $_),
44
45 grep { is_prefix_of $_, @path } 61 grep { is_prefix_of $_, @path }
46 map @$_, 62 map @$_,
47 $kw eq "*" ? @wiki{sort keys %wiki} 63 $kw eq "*" ? values %wiki
48 : grep $_, $wiki{$kw} 64 : $wiki{$kw} || ();
65
66 values %res
49} 67}
50 68
51sub full_path_of($) { 69sub 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 while ($node) {
57 while ($node->{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(@) {
105 $_[1]{$type}($_, @arg) 122 $_[1]{$type}($_, @arg)
106 }ogex; 123 }ogex;
107 } 124 }
108} 125}
109 126
127my %as_common = (
128 h1 => sub {
129 "\n\n<span foreground='#ffff00' size='x-large'>$_[1]</span>\n"
130 },
131 h2 => sub {
132 "\n\n<span foreground='#ccccff' size='large'>$_[1]</span>\n"
133 },
134 h3 => sub {
135 "\n\n<span size='large'>$_[1]</span>\n"
136 },
137);
138
110my %as_label = ( 139my %as_label = (
140 %as_common,
111 image => sub { 141 image => sub {
112 my ($par, $path) = @_; 142 my ($par, $path) = @_;
113 143
114 "<small>img</small>" 144 "<small>img</small>"
115 }, 145 },
116 link => sub { 146 link => sub {
117 my ($par, $text, $link) = @_; 147 my ($par, $text, $link) = @_;
118 148
119 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>" 149 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>"
120 }, 150 },
121); 151);
122 152
123sub as_label(@) { 153sub as_label(@) {
124 thaw_section @_, %as_label; 154 thaw_section @_, %as_label;
133 163
134 $text 164 $text
135} 165}
136 166
137my %as_paragraphs = ( 167my %as_paragraphs = (
168 %as_common,
138 image => sub { 169 image => sub {
139 my ($par, $path, $flags) = @_; 170 my ($par, $path, $flags) = @_;
140 171
141 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path, 172 push @{ $par->{widget} }, new DC::UI::Image path => $path,
142 $flags & 1 ? (max_h => $::FONTSIZE) : (); 173 $flags & 1 ? (max_h => $::FONTSIZE) : ();
143 174
144 "\x{fffc}" 175 "\x{fffc}"
145 }, 176 },
146 link => sub { 177 link => sub {
147 my ($par, $text, $link) = @_; 178 my ($par, $text, $link) = @_;
148 179
149 push @{ $par->{widget} }, new CFPlus::UI::Label 180 push @{ $par->{widget} }, new DC::UI::Label
150 markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>", 181 markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>",
151 fontsize => 0.8, 182 fontsize => 0.8,
152 can_hover => 1, 183 can_hover => 1,
153 can_events => 1, 184 can_events => 1,
154 padding_x => 0, 185 padding_x => 0,
155 padding_y => 0, 186 padding_y => 0,
156 tooltip => "Go to <i>" . (CFPlus::asxml $link) . "</i>", 187 tooltip => "Go to <i>" . (DC::asxml $link) . "</i>",
157 on_button_up => sub { 188 on_button_up => sub {
158 goto_document $link; 189 goto_document $link;
159 }; 190 };
160 191
161 "\x{fffc}" 192 "\x{fffc}"

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines