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.19 by root, Tue Mar 25 02:12:35 2008 UTC vs.
Revision 1.24 by root, Sat Apr 3 02:58:25 2010 UTC

1package DC::Pod; 1package DC::Pod;
2 2
3use strict; 3use common::sense;
4use utf8;
5 4
6use Storable; 5use Storable;
7 6
8our $VERSION = 1.03; 7our $VERSION = 1.03;
9 8
25sub P_INDENT (){ 0 } 24sub P_INDENT (){ 0 }
26sub P_LEVEL (){ 1 } 25sub P_LEVEL (){ 1 }
27sub P_MARKUP (){ 2 } 26sub P_MARKUP (){ 2 }
28sub P_INDEX (){ 3 } 27sub P_INDEX (){ 3 }
29 28
30*wiki = Storable::retrieve DC::find_rcfile "docwiki.pst"; 29our %wiki;
30
31sub load_docwiki {
32 *wiki = Storable::retrieve $_[0];
33}
31 34
32sub goto_document($) { 35sub goto_document($) {
33 $goto_document->(split /\//, $_[0]); 36 $goto_document->(split /\//, $_[0]);
34} 37}
35 38
36sub is_prefix_of($@) { 39sub is_prefix_of($@) {
37 my ($node, @path) = @_; 40 my ($node, @path) = @_;
38 41
39 return 1 unless @path; 42 return 1 unless @path;
40 43
41 my $kw = lc pop @path; 44 my $kw = pop @path;
42 45
43 $node = $node->[N_PARENT] 46 $node = $node->[N_PARENT]
44 or return 0; 47 or return 0;
45 48
46 return scalar grep $_ eq $kw, @{ $node->[N_KW] }; 49 return scalar grep $_ eq $kw, @{ $node->[N_KW] };
49sub find(@) { 52sub find(@) {
50 my (@path) = @_; 53 my (@path) = @_;
51 54
52 return unless @path; 55 return unless @path;
53 56
54 my $kw = lc pop @path; 57 my $kw = pop @path;
55 58
56 # TODO: make sure results are unique 59 my %res = map +($_, $_),
57
58 grep { is_prefix_of $_, @path } 60 grep { is_prefix_of $_, @path }
59 map @$_, 61 map @$_,
60 $kw eq "*" ? @wiki{sort keys %wiki} 62 $kw eq "*" ? values %wiki
61 : $wiki{$kw} || () 63 : $wiki{$kw} || ();
64
65 values %res
62} 66}
63 67
64sub full_path_of($) { 68sub full_path_of($) {
65 my ($node) = @_; 69 my ($node) = @_;
66 70
67 my @path; 71 my @path;
68 72
69 # skip toplevel hierarchy pod/, because its not a document
70 while ($node->[N_PARENT]) { 73 while ($node) {
71 unshift @path, $node; 74 unshift @path, $node;
72 $node = $node->[N_PARENT]; 75 $node = $node->[N_PARENT];
73 } 76 }
74 77
75 @path 78 @path
118 $_[1]{$type}($_, @arg) 121 $_[1]{$type}($_, @arg)
119 }ogex; 122 }ogex;
120 } 123 }
121} 124}
122 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
123my %as_label = ( 138my %as_label = (
139 %as_common,
124 image => sub { 140 image => sub {
125 my ($par, $path) = @_; 141 my ($par, $path) = @_;
126 142
127 "<small>img</small>" 143 "<small>img</small>"
128 }, 144 },
146 162
147 $text 163 $text
148} 164}
149 165
150my %as_paragraphs = ( 166my %as_paragraphs = (
167 %as_common,
151 image => sub { 168 image => sub {
152 my ($par, $path, $flags) = @_; 169 my ($par, $path, $flags) = @_;
153 170
154 push @{ $par->{widget} }, new DC::UI::Image path => $path, 171 push @{ $par->{widget} }, new DC::UI::Image path => $path,
155 $flags & 1 ? (max_h => $::FONTSIZE) : (); 172 $flags & 1 ? (max_h => $::FONTSIZE) : ();

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines