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.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;
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
15*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}
16 39
17sub is_prefix_of($@) { 40sub is_prefix_of($@) {
18 my ($node, @path) = @_; 41 my ($node, @path) = @_;
19 42
20 return 1 unless @path; 43 return 1 unless @path;
21 44
22 my $kw = pop @path; 45 my $kw = pop @path;
23 46
24 $node = $node->{parent} 47 $node = $node->[N_PARENT]
25 or return 0; 48 or return 0;
26 49
27 return ! ! grep $_ eq $kw, @{ $node->{kw} }; 50 return scalar grep $_ eq $kw, @{ $node->[N_KW] };
28} 51}
29 52
30sub find(@) { 53sub find(@) {
31 my (@path) = @_; 54 my (@path) = @_;
32 55
33 return unless @path; 56 return unless @path;
34 57
35 my $kw = pop @path; 58 my $kw = pop @path;
36 59
37 # TODO: make sure results are unique 60 my %res = map +($_, $_),
38
39 grep { is_prefix_of $_, @path } 61 grep { is_prefix_of $_, @path }
40 map @$_, 62 map @$_,
41 $kw eq "*" ? @wiki{sort keys %wiki} 63 $kw eq "*" ? values %wiki
42 : grep $_, $wiki{$kw} 64 : $wiki{$kw} || ();
65
66 values %res
43} 67}
44 68
45sub full_path_of($) { 69sub full_path_of($) {
46 my ($node) = @_; 70 my ($node) = @_;
47 71
48 my $path = $node->{kw}[0]; 72 my @path;
49 $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; 73
74 while ($node) {
75 unshift @path, $node;
76 $node = $node->[N_PARENT];
77 }
78
50 $path 79 @path
80}
81
82sub full_path($) {
83 join "/", map $_->[N_KW][0], &full_path_of
51} 84}
52 85
53sub section_of($) { 86sub section_of($) {
54 my ($node) = @_; 87 my ($node) = @_;
55 88
56 my $doc = $node->{doc}; 89 my $doc = $node->[N_DOC];
57 my $par = $node->{par}; 90 my $par = $node->[N_PAR];
58 my $lvl = $node->{level}; 91 my $lvl = $node->[N_LEVEL];
59 92
60 my @res; 93 my @res;
61 94
62 do { 95 do {
63 my $p = $doc->[$par]; 96 my $p = $doc->[$par];
64 97
65 if (length $p->{markup}) { 98 if (length $p->[P_MARKUP]) {
66 push @res, { 99 push @res, {
67 markup => $p->{markup}, 100 markup => $p->[P_MARKUP],
68 indent => $p->{indent}, 101 indent => $p->[P_INDENT],
69 }; 102 };
70 } 103 }
71 } while $doc->[++$par]{level} > $lvl; 104 } while $doc->[++$par][P_LEVEL] > $lvl;
72 105
73 @res 106 @res
74} 107}
75 108
76sub section(@) { 109sub section(@) {
89 $_[1]{$type}($_, @arg) 122 $_[1]{$type}($_, @arg)
90 }ogex; 123 }ogex;
91 } 124 }
92} 125}
93 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
94my %as_label = ( 139my %as_label = (
140 %as_common,
95 image => sub { 141 image => sub {
96 my ($par, $path) = @_; 142 my ($par, $path) = @_;
97 143
98 "<small>img</small>" 144 "<small>img</small>"
99 }, 145 },
100 link => sub { 146 link => sub {
101 my ($par, $link) = @_; 147 my ($par, $text, $link) = @_;
102 148
103 "<big>" . (CFPlus::asxml $link) . "</big>" 149 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>"
104 }, 150 },
105); 151);
106 152
107sub as_label(@) { 153sub as_label(@) {
108 thaw_section @_, %as_label; 154 thaw_section @_, %as_label;
117 163
118 $text 164 $text
119} 165}
120 166
121my %as_paragraphs = ( 167my %as_paragraphs = (
168 %as_common,
122 image => sub { 169 image => sub {
123 my ($par, $path) = @_; 170 my ($par, $path, $flags) = @_;
124 171
125 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; 172 push @{ $par->{widget} }, new DC::UI::Image path => $path,
173 $flags & 1 ? (max_h => $::FONTSIZE) : ();
126 174
127 "\x{FFFC}" 175 "\x{fffc}"
128 }, 176 },
129 link => sub { 177 link => sub {
130 my ($par, $link) = @_; 178 my ($par, $text, $link) = @_;
131 179
132 "<big>" . (CFPlus::asxml $link) . "</big>" 180 push @{ $par->{widget} }, new DC::UI::Label
181 markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>",
182 fontsize => 0.8,
183 can_hover => 1,
184 can_events => 1,
185 padding_x => 0,
186 padding_y => 0,
187 tooltip => "Go to <i>" . (DC::asxml $link) . "</i>",
188 on_button_up => sub {
189 goto_document $link;
190 };
191
192 "\x{fffc}"
133 }, 193 },
134); 194);
135 195
136sub as_paragraphs(@) { 196sub as_paragraphs(@) {
137 thaw_section @_, %as_paragraphs; 197 thaw_section @_, %as_paragraphs;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines