--- trunk/lib/Frey/Pod.pm 2008/10/31 19:51:51 213 +++ branches/no-pager/lib/Frey/Pod.pm 2008/12/06 15:29:10 738 @@ -9,30 +9,25 @@ extends 'Frey::ClassLoader'; with 'Frey::Web'; +with 'Frey::File'; has 'class' => ( is => 'rw', isa => 'Str', required => 1, + default => 'Frey::Manual', ); -use File::Slurp; +use Pod::Find qw/pod_where/; use Data::Dump qw/dump/; -sub request { - my ( $self, $req ) = @_; - my $f = { $req->params }; - my $class = delete( $f->{class} ) || $self->class; - $req->print( $self->page( title => $class, body => $self->markup( $class ) ) ); -} - -sub markup { +sub as_markup { my $self = shift; my $class = $self->class; use Pod::Simple::HTML; - my $path = eval { $self->package_path( $class ) }; - return if $@; - my $pod = read_file( $path ); + my $path = pod_where( { -inc => 1 }, $class ); + return $self->error( "Can't find pod for $class\n" ) unless $path; + my $pod = $self->read_file( $path ); my $converter = Pod::Simple::HTML->new(); my $body; my $my_classes = join('|', $self->classes); @@ -41,13 +36,77 @@ $body =~ s{.*?]+>}{}s; $body =~ s{\s*\s*$}{}; $body =~ s!%3A%3A!::!g; - $body =~ s{]*)>}{}g; - $body =~ s{]*)>}{}g; +# $body =~ s{]*)>}{}g; + $body =~ s{]*)>([^<]+)<([^>]+)>}{$4<$5>◊<$5>}g; $body =~ s!\n\t!; $body =~ s!

!!; $body =~ s!__index__!index!g; - return $body; + + our @toc = (); + + sub heading { + my ($level,$html) = @_; + push @toc, { $level => $html }; + warn "# heading $level $html"; + qq|<$level>$html|; + } + $body =~ s{<(h\d+)>(.+?)}{heading($1,$2)}egs; + + $self->title( $class ); + +# $body .= $self->html_dump( $toc ); + warn "# toc ", dump( @toc ); + + my $toc_html = ''; + my $current_level = 0; + foreach my $entry ( @toc ) { + my ( $level, $html ) = %$entry; + + if ( $level =~ m{h(\d+)} ) { + my $num = $1; + if ( $num > $current_level ) { + if ( ! $toc_html ) { # first ul + $toc_html .= qq|