Skip to content

Commit

Permalink
Made Corpus generate index/TOC in output directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
chromatic committed Mar 21, 2012
1 parent 2505499 commit 8df68b9
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions lib/Pod/PseudoPod/DOM/Corpus.pm
Expand Up @@ -5,17 +5,18 @@ use strict;
use warnings;

use Moose;
use Path::Class;

use Pod::PseudoPod::DOM::Index;
use Pod::PseudoPod::DOM::TableOfContents;
use Pod::PseudoPod::DOM::App 'open_fh';


has 'documents', is => 'ro', default => sub { [] };
has 'references', is => 'ro', default => sub { {} };
has 'index', is => 'ro',
default => sub {Pod::PseudoPod::DOM::Index->new};
default => sub { Pod::PseudoPod::DOM::Index->new };
has 'contents', is => 'ro',
default => sub {Pod::PseudoPod::DOM::TableOfContents->new};
default => sub { Pod::PseudoPod::DOM::TableOfContents->new };

sub add_document
{
Expand Down Expand Up @@ -73,15 +74,29 @@ sub write_documents
sub write_index
{
my $self = shift;
my $outfh = open_fh( 'book_index.html', '>' );
my $outfh = $self->get_fh_in_path( 'book_index', '>' );
print {$outfh} $self->get_index;
}

sub write_toc
{
my $self = shift;
my $outfh = open_fh( 'index.html', '>' );
my $outfh = $self->get_fh_in_path( 'index', '>' );
print {$outfh} $self->get_toc;
}

sub get_fh_in_path
{
my ($self, $filename, $mode) = @_;
my $docs = $self->documents;
return unless @$docs;

my $docfile = $docs->[0]->filename;
my ($suffix) = $docfile =~ /\.(.+)$/;
my $dir = file( $docfile )->dir;
my $file = $dir->file( $filename . '.' . $suffix );

return open_fh( $file->stringify, $mode );
}

__PACKAGE__->meta->make_immutable;

0 comments on commit 8df68b9

Please sign in to comment.