ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
Revision: 1.8
Committed: Sun Aug 13 19:47:05 2006 UTC (17 years, 9 months ago) by root
Branch: MAIN
Changes since 1.7: +18 -5 lines
Log Message:
docviewer psrtial rewrite

File Contents

# User Rev Content
1 root 1.3 package CFPlus::Pod;
2 root 1.1
3     use strict;
4 root 1.8 use utf8;
5 root 1.1
6 root 1.4 use Storable;
7 root 1.1
8 root 1.4 our $VERSION = 1;
9 root 1.1
10 root 1.8 our $on_link = sub { };
11 root 1.4 our %wiki;
12 root 1.1
13 root 1.7 my $MA_BEG = "\x{fcd0}";
14     my $MA_SEP = "\x{fcd1}";
15     my $MA_END = "\x{fcd2}";
16    
17 root 1.4 *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
18 root 1.1
19 root 1.4 sub is_prefix_of($@) {
20     my ($node, @path) = @_;
21 root 1.1
22 root 1.4 return 1 unless @path;
23 root 1.1
24 root 1.4 my $kw = pop @path;
25 root 1.1
26 root 1.4 $node = $node->{parent}
27     or return 0;
28 root 1.2
29 root 1.4 return ! ! grep $_ eq $kw, @{ $node->{kw} };
30 root 1.2 }
31    
32 root 1.4 sub find(@) {
33     my (@path) = @_;
34 root 1.1
35 root 1.4 return unless @path;
36 root 1.1
37 root 1.4 my $kw = pop @path;
38 root 1.1
39 root 1.4 # TODO: make sure results are unique
40 root 1.1
41 root 1.4 grep { is_prefix_of $_, @path }
42     map @$_,
43     $kw eq "*" ? @wiki{sort keys %wiki}
44     : grep $_, $wiki{$kw}
45 root 1.1 }
46    
47 root 1.4 sub full_path_of($) {
48     my ($node) = @_;
49 root 1.1
50 root 1.4 my $path = $node->{kw}[0];
51     $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
52     $path
53 root 1.1 }
54    
55 root 1.4 sub section_of($) {
56     my ($node) = @_;
57 root 1.1
58 root 1.4 my $doc = $node->{doc};
59     my $par = $node->{par};
60     my $lvl = $node->{level};
61 root 1.1
62 root 1.4 my @res;
63 root 1.1
64 root 1.4 do {
65     my $p = $doc->[$par];
66 root 1.1
67 root 1.7 if (length $p->{markup}) {
68     push @res, {
69 root 1.5 markup => $p->{markup},
70     indent => $p->{indent},
71 root 1.7 };
72 root 1.4 }
73     } while $doc->[++$par]{level} > $lvl;
74 root 1.1
75 root 1.4 @res
76 root 1.1 }
77    
78 root 1.4 sub section(@) {
79     map section_of $_, &find
80 root 1.2 }
81    
82 root 1.7 sub thaw_section(\@\%) {
83     for (@{$_[0]}) {
84     $_->{markup} =~ s{
85     $MA_BEG
86     ([^$MA_END]+)
87     $MA_END
88     }{
89     my ($type, @arg) = split /$MA_SEP/o, $1;
90    
91     $_[1]{$type}($_, @arg)
92     }ogex;
93     }
94     }
95    
96     my %as_label = (
97     image => sub {
98     my ($par, $path) = @_;
99    
100     "<small>img</small>"
101     },
102     link => sub {
103 root 1.8 my ($par, $text, $link) = @_;
104 root 1.7
105 root 1.8 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>"
106 root 1.7 },
107     );
108    
109 root 1.4 sub as_label(@) {
110 root 1.7 thaw_section @_, %as_label;
111    
112 root 1.6 my $text =
113     join "\n",
114     map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
115     @_;
116    
117     $text =~ s/^\s+//;
118     $text =~ s/\s+$//;
119    
120     $text
121     }
122    
123 root 1.7 my %as_paragraphs = (
124     image => sub {
125     my ($par, $path) = @_;
126    
127     push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
128    
129 root 1.8 "\x{fffc}"
130 root 1.7 },
131     link => sub {
132 root 1.8 my ($par, $text, $link) = @_;
133 root 1.7
134 root 1.8 push @{ $par->{widget} }, new CFPlus::UI::Label
135     markup => "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>",
136     size => 0.8,
137     can_hover => 1,
138     can_events => 1,
139     padding_x => 0,
140     padding_y => 0,
141     on_button_up => sub {
142     $on_link->(split /\//, $link);
143     };
144    
145     "\x{fffc}"
146 root 1.7 },
147     );
148    
149     sub as_paragraphs(@) {
150     thaw_section @_, %as_paragraphs;
151    
152     @_
153     }
154    
155     sub section_paragraphs(@) {
156     as_paragraphs &section
157     }
158    
159 root 1.6 sub section_label(@) {
160     as_label &section
161 root 1.1 }
162    
163 root 1.4 1