/[Frey]/trunk/lib/Frey/Pod.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk/lib/Frey/Pod.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1034 - (hide annotations)
Tue Feb 3 21:24:02 2009 UTC (15 years, 3 months ago) by dpavlin
File size: 2947 byte(s)
test Frey::Pod generation and enable split into toc and content

after that, use it in Frey::Introspect to move pod TOC into box
on the right.
1 dpavlin 126 package Frey::Pod;
2     use Moose;
3    
4     =head1 NAME
5    
6     Frey::Pod - display documentation
7    
8     =cut
9    
10 dpavlin 797 extends 'Frey::Class::Loader';
11 dpavlin 126 with 'Frey::Web';
12 dpavlin 724 with 'Frey::File';
13 dpavlin 126
14     has 'class' => (
15     is => 'rw',
16     isa => 'Str',
17     required => 1,
18 dpavlin 724 default => 'Frey::Manual',
19 dpavlin 126 );
20    
21 dpavlin 724 use Pod::Find qw/pod_where/;
22 dpavlin 126 use Data::Dump qw/dump/;
23    
24 dpavlin 1034 =head2 as_markup
25    
26     my $html = $o->as_markup;
27    
28     my ( $toc_html, $html ) = $o->as_markup;
29    
30     =cut
31    
32 dpavlin 455 sub as_markup {
33 dpavlin 178 my $self = shift;
34     my $class = $self->class;
35 dpavlin 126 use Pod::Simple::HTML;
36 dpavlin 356 my $path = pod_where( { -inc => 1 }, $class );
37 dpavlin 694 return $self->error( "Can't find pod for $class\n" ) unless $path;
38 dpavlin 724 my $pod = $self->read_file( $path );
39 dpavlin 126 my $converter = Pod::Simple::HTML->new();
40     my $body;
41     my $my_classes = join('|', $self->classes);
42     $converter->output_string( \$body );
43     $converter->parse_string_document($pod);
44     $body =~ s{.*?<body [^>]+>}{}s;
45     $body =~ s{</body>\s*</html>\s*$}{};
46 dpavlin 130 $body =~ s!%3A%3A!::!g;
47 dpavlin 356 # $body =~ s{<a href="http://search\.cpan\.org/perldoc\?($my_classes)"([^>]*)>}{<a href="/$1"$2>}g;
48 dpavlin 376 $body =~ s{<a href="http://(search\.cpan\.org/perldoc\?)([^"]+)"([^>]*)>([^<]+)<([^>]+)>}{<a href="/$2"$3>$4<$5><sup><a target="$1" title="CPAN" style="text-decoration: none" href="http://$1$2"$3>&loz;<$5></sup>}g;
49 dpavlin 126 $body =~ s!</li>\n\t<ul>!<ul>!;
50     $body =~ s!</ul>!</ul></li>!;
51     $body =~ s!<p></p>!!;
52     $body =~ s!__index__!index!g;
53 dpavlin 724
54     our @toc = ();
55    
56     sub heading {
57     my ($level,$html) = @_;
58     push @toc, { $level => $html };
59 dpavlin 800 warn "## heading $level $html" if $self->debug;
60 dpavlin 724 qq|<$level>$html</$level>|;
61     }
62     $body =~ s{<(h\d+)>(.+?)</\1>}{heading($1,$2)}egs;
63    
64 dpavlin 691 $self->title( $class );
65 dpavlin 379
66 dpavlin 724 # $body .= $self->html_dump( $toc );
67     warn "# toc ", dump( @toc );
68    
69     my $toc_html = '';
70     my $current_level = 0;
71     foreach my $entry ( @toc ) {
72     my ( $level, $html ) = %$entry;
73    
74     if ( $level =~ m{h(\d+)} ) {
75     my $num = $1;
76     if ( $num > $current_level ) {
77     if ( ! $toc_html ) { # first ul
78     $toc_html .= qq|<ul class="first">|;
79     } else {
80     $toc_html .= qq|<ul>|;
81     }
82     } elsif ( $num < $current_level ) {
83     $toc_html .= qq|</ul>|;
84     }
85     $current_level = $num;
86     }
87    
88     my $target = $html;
89     $target =~ s{<[^>]+/?>}{}gs; # remove html
90     $target = qq|<a href="#$2">$target</a>| if $html =~ m{<a[^<]+name=(['"]?)([^'"<]+?)\1[^<]+>};
91    
92     $toc_html .= qq|<li title="$level">$target</li>\n|;
93     }
94    
95 dpavlin 1034 $toc_html .= qq|</ul>| while ( $current_level-- );
96    
97     if ( $toc_html && ! wantarray ) {
98 dpavlin 724 $self->add_css(qq|
99     .pod-toc {
100     float: right;
101     background: #eee;
102     font-size: 80%;
103     }
104     .pod-toc .first {
105     padding-left: 1em;
106     padding-right: 1em;
107     }
108     .pod-toc ul > li {
109     list-style: none;
110     }
111     .pod-toc a {
112     text-decoration: none;
113     }
114 dpavlin 800
115 dpavlin 724 |);
116     $toc_html = qq|<div class="pod-toc">$toc_html</div>|;
117     }
118    
119 dpavlin 800 $self->add_css(qq|
120     pre {
121     color: #444;
122     border: 1px solid #eee;
123     padding-top: 0.5em;
124     padding-bottom: 0.5em;
125     }
126     |);
127    
128 dpavlin 1034 return ( $toc_html , $body ) if wantarray;
129     return $toc_html . $body;
130 dpavlin 724
131 dpavlin 126 }
132    
133     1;
134    

  ViewVC Help
Powered by ViewVC 1.1.26