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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines