--- deliantra/Deliantra-Client/DC/Pod.pm 2006/07/24 08:23:28 1.2
+++ deliantra/Deliantra-Client/DC/Pod.pm 2006/08/18 01:01:01 1.14
@@ -1,243 +1,179 @@
-package CFClient::Pod;
+package CFPlus::Pod;
use strict;
+use utf8;
-use Pod::POM;
+use Storable;
-use CFClient;
-use CFClient::UI;
+our $VERSION = 1;
-our $VERSION = 1.02; # bump if resultant formatting changes
+our $goto_document = sub { };
+our %wiki;
-our @result;
-our $indent;
+my $MA_BEG = "\x{fcd0}";
+my $MA_SEP = "\x{fcd1}";
+my $MA_END = "\x{fcd2}";
-package CFClient::Pod::AsMarkup;
+*wiki = Storable::retrieve CFPlus::find_rcfile "docwiki.pst";
-use strict;
+sub goto_document($) {
+ $goto_document->(split /\//, $_[0]);
+}
-use base "Pod::POM::View::Text";
+sub is_prefix_of($@) {
+ my ($node, @path) = @_;
-*view_seq_file =
-*view_seq_code =
-*view_seq_bold = sub { "$_[1]" };
-*view_seq_italic = sub { "$_[1]" };
-*view_seq_space =
-*view_seq_link = sub { CFClient::asxml $_[1] };
-*view_seq_zero =
-*view_seq_index = sub { };
+ return 1 unless @path;
-sub view_seq_text {
- my $text = $_[1];
- $text =~ s/\s+/ /g;
- CFClient::asxml $text
-}
+ my $kw = lc pop @path;
-sub view_item {
- ("\t" x ($indent / 4))
- . $_[1]->title->present ($_[0])
- . "\n\n"
- . $_[1]->content->present ($_[0])
-}
+ $node = $node->{parent}
+ or return 0;
-sub view_verbatim {
- (join "",
- map +("\t" x ($indent / 2)) . "$_\n",
- split /\n/, CFClient::asxml $_[1])
- . "\n"
+ return ! ! grep $_ eq $kw, @{ $node->{kw} };
}
-sub view_textblock {
- ("\t" x ($indent / 2)) . "$_[1]\n"
-}
+sub find(@) {
+ my (@path) = @_;
-sub view_head1 {
- "\n\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ return unless @path;
-sub view_head2 {
- "\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ my $kw = lc pop @path;
-sub view_head3 {
- "\n" . $_[1]->title->present ($_[0]) . "\n\n"
- . $_[1]->content->present ($_[0])
-};
+ # TODO: make sure results are unique
-sub view_over {
- local $indent = $indent + $_[1]->indent;
- $_[1]->content->present ($_[0])
+ grep { is_prefix_of $_, @path }
+ map @$_,
+ $kw eq "*" ? @wiki{sort keys %wiki}
+ : $wiki{$kw} || ()
}
-package CFClient::Pod::AsParagraphs;
+sub full_path_of($) {
+ my ($node) = @_;
-use strict;
-
-use base "Pod::POM::View";
+ my @path;
-*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 view_seq_text {
- my $text = $_[1];
- $text =~ s/\s+/ /g;
- CFClient::asxml $text
-}
-
-sub view_seq_link {
- my (undef, $link) = @_;
-
- # TODO:
- # http://...
- # ref
- # pod/ref
-
- "" . (CFClient::asxml $_[1]) . "";
-}
-
-sub view_item {
- push @result, {
- indent => $indent * 8,
- markup => $_[1]->title->present ($_[0]) . "\n\n",
- };
- $_[1]->content->present ($_[0]);
- ()
-}
-
-sub view_verbatim {
- push @result, {
- indent => $indent * 16,
- markup => "" . (CFClient::asxml $_[1]) . "\n",
- };
- ()
-}
-
-sub view_textblock {
- push @result, {
- indent => $indent * 16,
- markup => "$_[1]\n",
- };
- ()
-}
-
-sub view_head1 {
- push @result, {
- indent => $indent * 16,
- markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n",
- };
- $_[1]->content->present ($_[0]);
- ()
-};
-
-sub view_head2 {
- push @result, {
- indent => $indent * 16,
- markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n",
- };
- $_[1]->content->present ($_[0]);
- ()
-};
-
-sub view_head3 {
- push @result, {
- indent => $indent * 16,
- markup => "\n\n" . $_[1]->title->present ($_[0]) . "\n",
- };
- $_[1]->content->present ($_[0]);
- ()
-};
-
-sub view_over {
- local $indent = $indent + $_[1]->indent;
- push @result, { indent => $indent };
- $_[1]->content->present ($_[0]);
- ()
-}
-
-sub view_for {
- if ($_[1]->format eq "image") {
- push @result, {
- indent => $indent * 16,
- markup => "\x{fffc}",
- widget => [new CFClient::UI::Image path => "pod/" . $_[1]->text],
- };
+ # skip toplevel hierarchy pod/, because its not a document
+ while ($node->{parent}) {
+ unshift @path, $node;
+ $node = $node->{parent};
}
- ()
-}
-sub view {
- my ($self, $type, $item) = @_;
+ @path
+}
- $item->content->present ($self);
+sub full_path($) {
+ join "/", map $_->{kw}[0], &full_path_of
}
-package CFClient::Pod;
+sub section_of($) {
+ my ($node) = @_;
+
+ my $doc = $node->{doc};
+ my $par = $node->{par};
+ my $lvl = $node->{level};
-my $pod_cache = CFClient::db_table "pod_cache";
+ my @res;
-sub load($$$$) {
- my ($path, $filtertype, $filterversion, $filtercb) = @_;
+ do {
+ my $p = $doc->[$par];
- stat $path
- or die "$path: $!";
+ if (length $p->{markup}) {
+ push @res, {
+ markup => $p->{markup},
+ indent => $p->{indent},
+ };
+ }
+ } while $doc->[++$par]{level} > $lvl;
- my $phash = join ",", $filterversion, $VERSION, (stat _)[7,9];
+ @res
+}
- my ($chash, $pom) = eval {
- local $SIG{__DIE__};
- @{ Storable::thaw $pod_cache->get ("$path/$filtertype") }
- };
+sub section(@) {
+ map section_of $_, &find
+}
- return $pom if $chash eq $phash;
+sub thaw_section(\@\%) {
+ for (@{$_[0]}) {
+ $_->{markup} =~ s{
+ $MA_BEG
+ ([^$MA_END]+)
+ $MA_END
+ }{
+ my ($type, @arg) = split /$MA_SEP/o, $1;
- my $pod = do {
- local $/;
- open my $pod, "<:utf8", $_[0]
- or die "$_[0]: $!";
- <$pod>
- };
+ $_[1]{$type}($_, @arg)
+ }ogex;
+ }
+}
- #utf8::downgrade $pod;
+my %as_label = (
+ image => sub {
+ my ($par, $path) = @_;
- $pom = $filtercb->(Pod::POM->new->parse_text ($pod));
+ "img"
+ },
+ link => sub {
+ my ($par, $text, $link) = @_;
- $pod_cache->put ("$path/$filtertype" => Storable::nfreeze [$phash, $pom]);
+ "↺" . (CFPlus::asxml $text) . ""
+ },
+);
- $pom
-}
+sub as_label(@) {
+ thaw_section @_, %as_label;
-sub section($$) {
- my ($pod, $section) = @_;
+ my $text =
+ join "\n",
+ map +("\xa0" x ($_->{indent} / 4)) . $_->{markup},
+ @_;
+
+ $text =~ s/^\s+//;
+ $text =~ s/\s+$//;
+
+ $text
}
-sub as_markup($) {
- my ($pom) = @_;
+my %as_paragraphs = (
+ image => sub {
+ my ($par, $path, $flags) = @_;
- local $indent = 0;
+ push @{ $par->{widget} }, new CFPlus::UI::Image path => $path,
+ $flags & 1 ? (max_h => $::FONTSIZE) : ();
- $pom->present ("CFClient::Pod::AsMarkup")
-}
+ "\x{fffc}"
+ },
+ link => sub {
+ my ($par, $text, $link) = @_;
-sub as_paragraphs($) {
- my ($pom) = @_;
+ push @{ $par->{widget} }, new CFPlus::UI::Label
+ markup => "↺" . (CFPlus::asxml $text) . "",
+ fontsize => 0.8,
+ can_hover => 1,
+ can_events => 1,
+ padding_x => 0,
+ padding_y => 0,
+ tooltip => "Go to " . (CFPlus::asxml $link) . "",
+ on_button_up => sub {
+ goto_document $link;
+ };
- local @result = ( { } );
- local $indent = 0;
+ "\x{fffc}"
+ },
+);
- $pom->present ("CFClient::Pod::AsParagraphs");
+sub as_paragraphs(@) {
+ thaw_section @_, %as_paragraphs;
+
+ @_
+}
- [grep exists $_->{markup}, @result]
+sub section_paragraphs(@) {
+ as_paragraphs §ion
}
-sub pod_paragraphs($) {
- load CFClient::find_rcfile "pod/$_[0].pod",
- pod_paragraphs => 1, sub { as_paragraphs $_[0] };
+sub section_label(@) {
+ as_label §ion
}
+1