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.16 by root, Wed Dec 26 20:46:39 2007 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*wiki = Storable::retrieve dc::find_rcfile "docwiki.pst";
18
19sub goto_document($) {
20 $goto_document->(split /\//, $_[0]);
21}
16 22
17sub is_prefix_of($@) { 23sub is_prefix_of($@) {
18 my ($node, @path) = @_; 24 my ($node, @path) = @_;
19 25
20 return 1 unless @path; 26 return 1 unless @path;
21 27
22 my $kw = pop @path; 28 my $kw = lc pop @path;
23 29
24 $node = $node->{parent} 30 $node = $node->{parent}
25 or return 0; 31 or return 0;
26 32
27 return ! ! grep $_ eq $kw, @{ $node->{kw} }; 33 return ! ! grep $_ eq $kw, @{ $node->{kw} };
30sub find(@) { 36sub find(@) {
31 my (@path) = @_; 37 my (@path) = @_;
32 38
33 return unless @path; 39 return unless @path;
34 40
35 my $kw = pop @path; 41 my $kw = lc pop @path;
36 42
37 # TODO: make sure results are unique 43 # TODO: make sure results are unique
38 44
39 grep { is_prefix_of $_, @path } 45 grep { is_prefix_of $_, @path }
40 map @$_, 46 map @$_,
41 $kw eq "*" ? @wiki{sort keys %wiki} 47 $kw eq "*" ? @wiki{sort keys %wiki}
42 : grep $_, $wiki{$kw} 48 : $wiki{$kw} || ()
43} 49}
44 50
45sub full_path_of($) { 51sub full_path_of($) {
46 my ($node) = @_; 52 my ($node) = @_;
47 53
48 my $path = $node->{kw}[0]; 54 my @path;
49 $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; 55
56 # skip toplevel hierarchy pod/, because its not a document
57 while ($node->{parent}) {
58 unshift @path, $node;
59 $node = $node->{parent};
60 }
61
50 $path 62 @path
63}
64
65sub full_path($) {
66 join "/", map $_->{kw}[0], &full_path_of
51} 67}
52 68
53sub section_of($) { 69sub section_of($) {
54 my ($node) = @_; 70 my ($node) = @_;
55 71
96 my ($par, $path) = @_; 112 my ($par, $path) = @_;
97 113
98 "<small>img</small>" 114 "<small>img</small>"
99 }, 115 },
100 link => sub { 116 link => sub {
101 my ($par, $link) = @_; 117 my ($par, $text, $link) = @_;
102 118
103 "<big>" . (CFPlus::asxml $link) . "</big>" 119 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (dc::asxml $text) . "</span>"
104 }, 120 },
105); 121);
106 122
107sub as_label(@) { 123sub as_label(@) {
108 thaw_section @_, %as_label; 124 thaw_section @_, %as_label;
118 $text 134 $text
119} 135}
120 136
121my %as_paragraphs = ( 137my %as_paragraphs = (
122 image => sub { 138 image => sub {
123 my ($par, $path) = @_; 139 my ($par, $path, $flags) = @_;
124 140
125 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path; 141 push @{ $par->{widget} }, new dc::UI::Image path => $path,
142 $flags & 1 ? (max_h => $::FONTSIZE) : ();
126 143
127 "\x{FFFC}" 144 "\x{fffc}"
128 }, 145 },
129 link => sub { 146 link => sub {
130 my ($par, $link) = @_; 147 my ($par, $text, $link) = @_;
131 148
132 "<big>" . (CFPlus::asxml $link) . "</big>" 149 push @{ $par->{widget} }, new dc::UI::Label
150 markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (dc::asxml $text) . "</span>",
151 fontsize => 0.8,
152 can_hover => 1,
153 can_events => 1,
154 padding_x => 0,
155 padding_y => 0,
156 tooltip => "Go to <i>" . (dc::asxml $link) . "</i>",
157 on_button_up => sub {
158 goto_document $link;
159 };
160
161 "\x{fffc}"
133 }, 162 },
134); 163);
135 164
136sub as_paragraphs(@) { 165sub as_paragraphs(@) {
137 thaw_section @_, %as_paragraphs; 166 thaw_section @_, %as_paragraphs;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines