ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/Deliantra-Client/DC/Pod.pm
Revision: 1.7
Committed: Sun Aug 13 18:48:56 2006 UTC (17 years, 10 months ago) by root
Branch: MAIN
Changes since 1.6: +61 -10 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.4 our $VERSION = 1;
8 root 1.1
9 root 1.4 our %wiki;
10 root 1.1
11 root 1.7 my $MA_BEG = "\x{fcd0}";
12     my $MA_SEP = "\x{fcd1}";
13     my $MA_END = "\x{fcd2}";
14    
15 root 1.4 *wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
16 root 1.1
17 root 1.4 sub is_prefix_of($@) {
18     my ($node, @path) = @_;
19 root 1.1
20 root 1.4 return 1 unless @path;
21 root 1.1
22 root 1.4 my $kw = pop @path;
23 root 1.1
24 root 1.4 $node = $node->{parent}
25     or return 0;
26 root 1.2
27 root 1.4 return ! ! grep $_ eq $kw, @{ $node->{kw} };
28 root 1.2 }
29    
30 root 1.4 sub find(@) {
31     my (@path) = @_;
32 root 1.1
33 root 1.4 return unless @path;
34 root 1.1
35 root 1.4 my $kw = pop @path;
36 root 1.1
37 root 1.4 # TODO: make sure results are unique
38 root 1.1
39 root 1.4 grep { is_prefix_of $_, @path }
40     map @$_,
41     $kw eq "*" ? @wiki{sort keys %wiki}
42     : grep $_, $wiki{$kw}
43 root 1.1 }
44    
45 root 1.4 sub full_path_of($) {
46     my ($node) = @_;
47 root 1.1
48 root 1.4 my $path = $node->{kw}[0];
49     $path = "$node->{kw}[0]/$path" while $node = $node->{parent};
50     $path
51 root 1.1 }
52    
53 root 1.4 sub section_of($) {
54     my ($node) = @_;
55 root 1.1
56 root 1.4 my $doc = $node->{doc};
57     my $par = $node->{par};
58     my $lvl = $node->{level};
59 root 1.1
60 root 1.4 my @res;
61 root 1.1
62 root 1.4 do {
63     my $p = $doc->[$par];
64 root 1.1
65 root 1.7 if (length $p->{markup}) {
66     push @res, {
67 root 1.5 markup => $p->{markup},
68     indent => $p->{indent},
69 root 1.7 };
70 root 1.4 }
71     } while $doc->[++$par]{level} > $lvl;
72 root 1.1
73 root 1.4 @res
74 root 1.1 }
75    
76 root 1.4 sub section(@) {
77     map section_of $_, &find
78 root 1.2 }
79    
80 root 1.7 sub thaw_section(\@\%) {
81     for (@{$_[0]}) {
82     $_->{markup} =~ s{
83     $MA_BEG
84     ([^$MA_END]+)
85     $MA_END
86     }{
87     my ($type, @arg) = split /$MA_SEP/o, $1;
88    
89     $_[1]{$type}($_, @arg)
90     }ogex;
91     }
92     }
93    
94     my %as_label = (
95     image => sub {
96     my ($par, $path) = @_;
97    
98     "<small>img</small>"
99     },
100     link => sub {
101     my ($par, $link) = @_;
102    
103     "<big>" . (CFPlus::asxml $link) . "</big>"
104     },
105     );
106    
107 root 1.4 sub as_label(@) {
108 root 1.7 thaw_section @_, %as_label;
109    
110 root 1.6 my $text =
111     join "\n",
112     map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
113     @_;
114    
115     $text =~ s/^\s+//;
116     $text =~ s/\s+$//;
117    
118     $text
119     }
120    
121 root 1.7 my %as_paragraphs = (
122     image => sub {
123     my ($par, $path) = @_;
124    
125     push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
126    
127     "\x{FFFC}"
128     },
129     link => sub {
130     my ($par, $link) = @_;
131    
132     "<big>" . (CFPlus::asxml $link) . "</big>"
133     },
134     );
135    
136     sub as_paragraphs(@) {
137     thaw_section @_, %as_paragraphs;
138    
139     @_
140     }
141    
142     sub section_paragraphs(@) {
143     as_paragraphs &section
144     }
145    
146 root 1.6 sub section_label(@) {
147     as_label &section
148 root 1.1 }
149    
150 root 1.4 1