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.6 by root, Sun Aug 13 14:30:06 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
7our $VERSION = 1; 8our $VERSION = 1;
8 9
10our $on_link = sub { };
9our %wiki; 11our %wiki;
12
13my $MA_BEG = "\x{fcd0}";
14my $MA_SEP = "\x{fcd1}";
15my $MA_END = "\x{fcd2}";
10 16
11*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; 17*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
12 18
13sub is_prefix_of($@) { 19sub is_prefix_of($@) {
14 my ($node, @path) = @_; 20 my ($node, @path) = @_;
56 my @res; 62 my @res;
57 63
58 do { 64 do {
59 my $p = $doc->[$par]; 65 my $p = $doc->[$par];
60 66
61 if (exists $p->{markup}) { 67 if (length $p->{markup}) {
62 my %para = ( 68 push @res, {
63 markup => $p->{markup}, 69 markup => $p->{markup},
64 indent => $p->{indent}, 70 indent => $p->{indent},
65 );
66
67 for (@{ $p->{widget} || [] }) {
68 my ($class, @args) = @$_;
69 push @{ $para{widget} }, $class->new (@args);
70 } 71 };
71
72 push @res, \%para;
73 } 72 }
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
84 my $text = 112 my $text =
85 join "\n", 113 join "\n",
86 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, 114 map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
87 @_; 115 @_;
88 116
90 $text =~ s/\s+$//; 118 $text =~ s/\s+$//;
91 119
92 $text 120 $text
93} 121}
94 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
95sub section_label(@) { 159sub section_label(@) {
96 as_label &section 160 as_label &section
97} 161}
98 162
991 1631

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines