--- deliantra/Deliantra-Client/DC/Pod.pm 2006/09/12 20:48:45 1.15 +++ deliantra/Deliantra-Client/DC/Pod.pm 2008/03/30 13:02:26 1.23 @@ -1,4 +1,4 @@ -package CFPlus::Pod; +package DC::Pod; use strict; use utf8; @@ -14,7 +14,24 @@ my $MA_SEP = "\x{fcd1}"; my $MA_END = "\x{fcd2}"; -*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; +# nodes (order must stay as it is) +sub N_PARENT (){ 0 } +sub N_PAR (){ 1 } +sub N_LEVEL (){ 2 } +sub N_KW (){ 3 } +sub N_DOC (){ 4 } + +# paragraphs (order must stay as it is) +sub P_INDENT (){ 0 } +sub P_LEVEL (){ 1 } +sub P_MARKUP (){ 2 } +sub P_INDEX (){ 3 } + +our %wiki; + +sub load_docwiki { + *wiki = Storable::retrieve $_[0]; +} sub goto_document($) { $goto_document->(split /\//, $_[0]); @@ -25,12 +42,12 @@ return 1 unless @path; - my $kw = lc pop @path; + my $kw = pop @path; - $node = $node->{parent} + $node = $node->[N_PARENT] or return 0; - return ! ! grep $_ eq $kw, @{ $node->{kw} }; + return scalar grep $_ eq $kw, @{ $node->[N_KW] }; } sub find(@) { @@ -38,14 +55,15 @@ return unless @path; - my $kw = lc pop @path; + my $kw = pop @path; - # TODO: make sure results are unique + my %res = map +($_, $_), + grep { is_prefix_of $_, @path } + map @$_, + $kw eq "*" ? values %wiki + : $wiki{$kw} || (); - grep { is_prefix_of $_, @path } - map @$_, - $kw eq "*" ? @wiki{sort keys %wiki} - : $wiki{$kw} || () + values %res } sub full_path_of($) { @@ -53,38 +71,37 @@ my @path; - # skip toplevel hierarchy pod/, because its not a document - while ($node->{parent}) { + while ($node) { unshift @path, $node; - $node = $node->{parent}; + $node = $node->[N_PARENT]; } @path } sub full_path($) { - join "/", map $_->{kw}[0], &full_path_of + join "/", map $_->[N_KW][0], &full_path_of } sub section_of($) { my ($node) = @_; - my $doc = $node->{doc}; - my $par = $node->{par}; - my $lvl = $node->{level}; + my $doc = $node->[N_DOC]; + my $par = $node->[N_PAR]; + my $lvl = $node->[N_LEVEL]; my @res; do { my $p = $doc->[$par]; - if (length $p->{markup}) { + if (length $p->[P_MARKUP]) { push @res, { - markup => $p->{markup}, - indent => $p->{indent}, + markup => $p->[P_MARKUP], + indent => $p->[P_INDENT], }; } - } while $doc->[++$par]{level} > $lvl; + } while $doc->[++$par][P_LEVEL] > $lvl; @res } @@ -107,7 +124,20 @@ } } +my %as_common = ( + h1 => sub { + "\n\n$_[1]\n" + }, + h2 => sub { + "\n\n$_[1]\n" + }, + h3 => sub { + "\n\n$_[1]\n" + }, +); + my %as_label = ( + %as_common, image => sub { my ($par, $path) = @_; @@ -116,7 +146,7 @@ link => sub { my ($par, $text, $link) = @_; - "" . (CFPlus::asxml $text) . "" + "" . (DC::asxml $text) . "" }, ); @@ -135,10 +165,11 @@ } my %as_paragraphs = ( + %as_common, image => sub { my ($par, $path, $flags) = @_; - push @{ $par->{widget} }, new CFPlus::UI::Image path => $path, + push @{ $par->{widget} }, new DC::UI::Image path => $path, $flags & 1 ? (max_h => $::FONTSIZE) : (); "\x{fffc}" @@ -146,14 +177,14 @@ link => sub { my ($par, $text, $link) = @_; - push @{ $par->{widget} }, new CFPlus::UI::Label - markup => "" . (CFPlus::asxml $text) . "", + push @{ $par->{widget} }, new DC::UI::Label + markup => "" . (DC::asxml $text) . "", fontsize => 0.8, can_hover => 1, can_events => 1, padding_x => 0, padding_y => 0, - tooltip => "Go to " . (CFPlus::asxml $link) . "", + tooltip => "Go to " . (DC::asxml $link) . "", on_button_up => sub { goto_document $link; };