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.24 by root, Sat Apr 3 02:58:25 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines