ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
Revision: 1.4
Committed: Sun Aug 13 02:43:22 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Changes since 1.3: +51 -205 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.3 package CFPlus::Pod;
2 root 1.1
3     use strict;
4    
5 root 1.4 use Storable;
6 root 1.1
7 root 1.3 use CFPlus::UI;
8 root 1.1
9 root 1.4 our $VERSION = 1;
10 root 1.1
11 root 1.4 our %wiki;
12 root 1.1
13 root 1.4 *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
14 root 1.1
15 root 1.4 sub is_prefix_of($@) {
16     my ($node, @path) = @_;
17 root 1.1
18 root 1.4 return 1 unless @path;
19 root 1.1
20 root 1.4 my $kw = pop @path;
21 root 1.1
22 root 1.4 $node = $node->{parent}
23     or return 0;
24 root 1.2
25 root 1.4 return ! ! grep $_ eq $kw, @{ $node->{kw} };
26 root 1.2 }
27    
28 root 1.4 sub find(@) {
29     my (@path) = @_;
30 root 1.1
31 root 1.4 return unless @path;
32 root 1.1
33 root 1.4 my $kw = pop @path;
34 root 1.1
35 root 1.4 # TODO: make sure results are unique
36 root 1.1
37 root 1.4 grep { is_prefix_of $_, @path }
38     map @$_,
39     $kw eq "*" ? @wiki{sort keys %wiki}
40     : grep $_, $wiki{$kw}
41 root 1.1 }
42    
43 root 1.4 sub full_path_of($) {
44     my ($node) = @_;
45 root 1.1
46 root 1.4 my $path = $node->{kw}[0];
47     $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
48     $path
49 root 1.1 }
50    
51 root 1.4 sub section_of($) {
52     my ($node) = @_;
53 root 1.1
54 root 1.4 my $doc = $node->{doc};
55     my $par = $node->{par};
56     my $lvl = $node->{level};
57 root 1.1
58 root 1.4 my @res;
59 root 1.1
60 root 1.4 do {
61     my $p = $doc->[$par];
62 root 1.1
63 root 1.4 my %para = (
64     markup => $p->{markup},
65     indent => $p->{indent},
66     );
67 root 1.1
68 root 1.4 for (@{ $p->{widget} || [] }) {
69     my ($class, @args) = @$_;
70     push @{ $para{widget} }, $class->new (@args);
71     }
72 root 1.1
73 root 1.4 push @res, \%para;
74     } while $doc->[++$par]{level} > $lvl;
75 root 1.1
76 root 1.4 @res
77 root 1.1 }
78    
79 root 1.4 sub section(@) {
80     map section_of $_, &find
81 root 1.2 }
82    
83 root 1.4 sub as_label(@) {
84     join "\n",
85     map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
86     @_
87 root 1.1 }
88    
89 root 1.4 1