--- deliantra/Deliantra-Client/DC/Pod.pm 2006/07/30 13:16:44 1.3 +++ deliantra/Deliantra-Client/DC/Pod.pm 2006/08/13 02:43:22 1.4 @@ -2,242 +2,88 @@ use strict; -use Pod::POM; +use Storable; -use CFPlus; use CFPlus::UI; -our $VERSION = 1.02; # bump if resultant formatting changes +our $VERSION = 1; -our @result; -our $indent; +our %wiki; -package CFPlus::Pod::AsMarkup; +*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst"; -use strict; - -use base "Pod::POM::View::Text"; - -*view_seq_file = -*view_seq_code = -*view_seq_bold = sub { "$_[1]" }; -*view_seq_italic = sub { "$_[1]" }; -*view_seq_space = -*view_seq_link = sub { CFPlus::asxml $_[1] }; -*view_seq_zero = -*view_seq_index = sub { }; - -sub view_seq_text { - my $text = $_[1]; - $text =~ s/\s+/ /g; - CFPlus::asxml $text -} - -sub view_item { - ("\t" x ($indent / 4)) - . $_[1]->title->present ($_[0]) - . "\n\n" - . $_[1]->content->present ($_[0]) -} - -sub view_verbatim { - (join "", - map +("\t" x ($indent / 2)) . "$_\n", - split /\n/, CFPlus::asxml $_[1]) - . "\n" -} - -sub view_textblock { - ("\t" x ($indent / 2)) . "$_[1]\n" -} - -sub view_head1 { - "\n\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; - -sub view_head2 { - "\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; - -sub view_head3 { - "\n" . $_[1]->title->present ($_[0]) . "\n\n" - . $_[1]->content->present ($_[0]) -}; - -sub view_over { - local $indent = $indent + $_[1]->indent; - $_[1]->content->present ($_[0]) -} - -package CFPlus::Pod::AsParagraphs; - -use strict; - -use base "Pod::POM::View"; - -*view_seq_file = -*view_seq_code = -*view_seq_bold = sub { "$_[1]" }; -*view_seq_italic = sub { "$_[1]" }; -*view_seq_zero = sub { }; -*view_seq_space = sub { my $text = $_[1]; $text =~ s/ / /g; $text }; -*view_seq_index = sub { warn "index<@_>\n"; $result[-1]{index}{$_[1]} = undef }; +sub is_prefix_of($@) { + my ($node, @path) = @_; -sub view_seq_text { - my $text = $_[1]; - $text =~ s/\s+/ /g; - CFPlus::asxml $text -} - -sub view_seq_link { - my (undef, $link) = @_; - - # TODO: - # http://... - # ref - # pod/ref + return 1 unless @path; - "" . (CFPlus::asxml $_[1]) . ""; -} + my $kw = pop @path; -sub view_item { - push @result, { - indent => $indent * 8, - markup => $_[1]->title->present ($_[0]) . "\n\n", - }; - $_[1]->content->present ($_[0]); - () -} + $node = $node->{parent} + or return 0; -sub view_verbatim { - push @result, { - indent => $indent * 16, - markup => "" . (CFPlus::asxml $_[1]) . "\n", - }; - () + return ! ! grep $_ eq $kw, @{ $node->{kw} }; } -sub view_textblock { - push @result, { - indent => $indent * 16, - markup => "$_[1]\n", - }; - () -} +sub find(@) { + my (@path) = @_; -sub view_head1 { - push @result, { - indent => $indent * 16, - markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n", - }; - $_[1]->content->present ($_[0]); - () -}; + return unless @path; -sub view_head2 { - push @result, { - indent => $indent * 16, - markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n", - }; - $_[1]->content->present ($_[0]); - () -}; + my $kw = pop @path; -sub view_head3 { - push @result, { - indent => $indent * 16, - markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n", - }; - $_[1]->content->present ($_[0]); - () -}; + # TODO: make sure results are unique -sub view_over { - local $indent = $indent + $_[1]->indent; - push @result, { indent => $indent }; - $_[1]->content->present ($_[0]); - () + grep { is_prefix_of $_, @path } + map @$_, + $kw eq "*" ? @wiki{sort keys %wiki} + : grep $_, $wiki{$kw} } -sub view_for { - if ($_[1]->format eq "image") { - push @result, { - indent => $indent * 16, - markup => "\x{fffc}", - widget => [new CFPlus::UI::Image path => "pod/" . $_[1]->text], - }; - } - () -} - -sub view { - my ($self, $type, $item) = @_; +sub full_path_of($) { + my ($node) = @_; - $item->content->present ($self); + my $path = $node->{kw}[0]; + $path = "$node->{kw}[0]/$path" while $node = $node->{parent}; + $path } -package CFPlus::Pod; - -my $pod_cache = CFPlus::db_table "pod_cache"; - -sub load($$$$) { - my ($path, $filtertype, $filterversion, $filtercb) = @_; - - stat $path - or die "$path: $!"; +sub section_of($) { + my ($node) = @_; - my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9]; + my $doc = $node->{doc}; + my $par = $node->{par}; + my $lvl = $node->{level}; - my ($chash, $pom) = eval { - local $SIG{__DIE__}; - @{ Storable::thaw $pod_cache->get ("$path/$filtertype") } - }; + my @res; - return $pom if $chash eq $phash; + do { + my $p = $doc->[$par]; - my $pod = do { - local $/; - open my $pod, "<:utf8", $_[0] - or die "$_[0]: $!"; - <$pod> - }; + my %para = ( + markup => $p->{markup}, + indent => $p->{indent}, + ); - #utf8::downgrade $pod; + for (@{ $p->{widget} || [] }) { + my ($class, @args) = @$_; + push @{ $para{widget} }, $class->new (@args); + } - $pom = $filtercb->(Pod::POM->new->parse_text ($pod)); + push @res, \%para; + } while $doc->[++$par]{level} > $lvl; - $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]); - - $pom -} - -sub section($$) { - my ($pod, $section) = @_; -} - -sub as_markup($) { - my ($pom) = @_; - - local $indent = 0; - - $pom->present ("CFPlus::Pod::AsMarkup") + @res } -sub as_paragraphs($) { - my ($pom) = @_; - - local @result = ( { } ); - local $indent = 0; - - $pom->present ("CFPlus::Pod::AsParagraphs"); - - [grep exists $_->{markup}, @result] +sub section(@) { + map section_of $_, &find } -sub pod_paragraphs($) { - load CFPlus::find_rcfile "pod/$_[0].pod", - pod_paragraphs => 1, sub { as_paragraphs $_[0] }; +sub as_label(@) { + join "\n", + map +("\xa0" x ($_->{indent} / 4)) . $_->{markup}, + @_ } +1