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.5 by root, Sun Aug 13 03:20: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
13my $MA_BEG = "\x{fcd0}";
14my $MA_SEP = "\x{fcd1}";
15my $MA_END = "\x{fcd2}";
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
11*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}
12 35
13sub is_prefix_of($@) { 36sub is_prefix_of($@) {
14 my ($node, @path) = @_; 37 my ($node, @path) = @_;
15 38
16 return 1 unless @path; 39 return 1 unless @path;
17 40
18 my $kw = pop @path; 41 my $kw = lc pop @path;
19 42
20 $node = $node->{parent} 43 $node = $node->[N_PARENT]
21 or return 0; 44 or return 0;
22 45
23 return ! ! grep $_ eq $kw, @{ $node->{kw} }; 46 return scalar grep $_ eq $kw, @{ $node->[N_KW] };
24} 47}
25 48
26sub find(@) { 49sub find(@) {
27 my (@path) = @_; 50 my (@path) = @_;
28 51
29 return unless @path; 52 return unless @path;
30 53
31 my $kw = pop @path; 54 my $kw = lc pop @path;
32 55
33 # TODO: make sure results are unique 56 # TODO: make sure results are unique
34 57
35 grep { is_prefix_of $_, @path } 58 grep { is_prefix_of $_, @path }
36 map @$_, 59 map @$_,
37 $kw eq "*" ? @wiki{sort keys %wiki} 60 $kw eq "*" ? @wiki{sort keys %wiki}
38 : grep $_, $wiki{$kw} 61 : $wiki{$kw} || ()
39} 62}
40 63
41sub full_path_of($) { 64sub full_path_of($) {
42 my ($node) = @_; 65 my ($node) = @_;
43 66
44 my $path = $node->{kw}[0]; 67 my @path;
45 $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
46 $path 75 @path
76}
77
78sub full_path($) {
79 join "/", map $_->[N_KW][0], &full_path_of
47} 80}
48 81
49sub section_of($) { 82sub section_of($) {
50 my ($node) = @_; 83 my ($node) = @_;
51 84
52 my $doc = $node->{doc}; 85 my $doc = $node->[N_DOC];
53 my $par = $node->{par}; 86 my $par = $node->[N_PAR];
54 my $lvl = $node->{level}; 87 my $lvl = $node->[N_LEVEL];
55 88
56 my @res; 89 my @res;
57 90
58 do { 91 do {
59 my $p = $doc->[$par]; 92 my $p = $doc->[$par];
60 93
61 if (exists $p->{markup}) { 94 if (length $p->[P_MARKUP]) {
62 my %para = ( 95 push @res, {
63 markup => $p->{markup}, 96 markup => $p->[P_MARKUP],
64 indent => $p->{indent}, 97 indent => $p->[P_INDENT],
65 );
66
67 for (@{ $p->{widget} || [] }) {
68 my ($class, @args) = @$_;
69 push @{ $para{widget} }, $class->new (@args);
70 } 98 };
71
72 push @res, \%para;
73 } 99 }
74 } while $doc->[++$par]{level} > $lvl; 100 } while $doc->[++$par][P_LEVEL] > $lvl;
75 101
76 @res 102 @res
77} 103}
78 104
79sub section(@) { 105sub section(@) {
80 map section_of $_, &find 106 map section_of $_, &find
81} 107}
82 108
109sub thaw_section(\@\%) {
110 for (@{$_[0]}) {
111 $_->{markup} =~ s{
112 $MA_BEG
113 ([^$MA_END]+)
114 $MA_END
115 }{
116 my ($type, @arg) = split /$MA_SEP/o, $1;
117
118 $_[1]{$type}($_, @arg)
119 }ogex;
120 }
121}
122
123my %as_label = (
124 image => sub {
125 my ($par, $path) = @_;
126
127 "<small>img</small>"
128 },
129 link => sub {
130 my ($par, $text, $link) = @_;
131
132 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (DC::asxml $text) . "</span>"
133 },
134);
135
83sub as_label(@) { 136sub as_label(@) {
137 thaw_section @_, %as_label;
138
139 my $text =
84 join "\n", 140 join "\n",
85 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, 141 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
86 @_ 142 @_;
143
144 $text =~ s/^\s+//;
145 $text =~ s/\s+$//;
146
147 $text
148}
149
150my %as_paragraphs = (
151 image => sub {
152 my ($par, $path, $flags) = @_;
153
154 push @{ $par->{widget} }, new DC::UI::Image path => $path,
155 $flags & 1 ? (max_h => $::FONTSIZE) : ();
156
157 "\x{fffc}"
158 },
159 link => sub {
160 my ($par, $text, $link) = @_;
161
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}"
175 },
176);
177
178sub as_paragraphs(@) {
179 thaw_section @_, %as_paragraphs;
180
181 @_
182}
183
184sub section_paragraphs(@) {
185 as_paragraphs &section
186}
187
188sub section_label(@) {
189 as_label &section
87} 190}
88 191
891 1921

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines