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.4 by root, Sun Aug 13 02:43:22 2006 UTC vs.
Revision 1.8 by root, Sun Aug 13 19:47:05 2006 UTC

1package CFPlus::Pod; 1package CFPlus::Pod;
2 2
3use strict; 3use strict;
4use utf8;
4 5
5use Storable; 6use Storable;
6 7
7use CFPlus::UI;
8
9our $VERSION = 1; 8our $VERSION = 1;
10 9
10our $on_link = sub { };
11our %wiki; 11our %wiki;
12
13my $MA_BEG = "\x{fcd0}";
14my $MA_SEP = "\x{fcd1}";
15my $MA_END = "\x{fcd2}";
12 16
13*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; 17*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
14 18
15sub is_prefix_of($@) { 19sub is_prefix_of($@) {
16 my ($node, @path) = @_; 20 my ($node, @path) = @_;
58 my @res; 62 my @res;
59 63
60 do { 64 do {
61 my $p = $doc->[$par]; 65 my $p = $doc->[$par];
62 66
63 my %para = ( 67 if (length $p->{markup}) {
68 push @res, {
64 markup => $p->{markup}, 69 markup => $p->{markup},
65 indent => $p->{indent}, 70 indent => $p->{indent},
66 ); 71 };
67
68 for (@{ $p->{widget} || [] }) {
69 my ($class, @args) = @$_;
70 push @{ $para{widget} }, $class->new (@args);
71 } 72 }
72
73 push @res, \%para;
74 } while $doc->[++$par]{level} > $lvl; 73 } while $doc->[++$par]{level} > $lvl;
75 74
76 @res 75 @res
77} 76}
78 77
79sub section(@) { 78sub section(@) {
80 map section_of $_, &find 79 map section_of $_, &find
81} 80}
82 81
82sub 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
96my %as_label = (
97 image => sub {
98 my ($par, $path) = @_;
99
100 "<small>img</small>"
101 },
102 link => sub {
103 my ($par, $text, $link) = @_;
104
105 "<span foreground='#ffff00'>↺</span><span foreground='#c0c0ff' underline='single'>" . (CFPlus::asxml $text) . "</span>"
106 },
107);
108
83sub as_label(@) { 109sub as_label(@) {
110 thaw_section @_, %as_label;
111
112 my $text =
84 join "\n", 113 join "\n",
85 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, 114 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
86 @_ 115 @_;
116
117 $text =~ s/^\s+//;
118 $text =~ s/\s+$//;
119
120 $text
121}
122
123my %as_paragraphs = (
124 image => sub {
125 my ($par, $path) = @_;
126
127 push @{ $par->{widget} }, new CFPlus::UI::Image path => $path;
128
129 "\x{fffc}"
130 },
131 link => sub {
132 my ($par, $text, $link) = @_;
133
134 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 },
147);
148
149sub as_paragraphs(@) {
150 thaw_section @_, %as_paragraphs;
151
152 @_
153}
154
155sub section_paragraphs(@) {
156 as_paragraphs &section
157}
158
159sub section_label(@) {
160 as_label &section
87} 161}
88 162
891 1631

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines