App-FuguWeb

 view release on metacpan or  search on metacpan

lib/App/FuguWeb/Site.pm  view on Meta::CPAN

#	the key, and never that the release does.
sub _write_keys ($self)
{
	my $config = $self->{config};
	return 1 unless defined $config->keys_dir;

	my $keys = App::FuguWeb::Keys->new( config => $config );

	# The generation comes first, because it runs the guards of
	# Fugu::KeyDir over every armored key. A copy that ran first
	# would leave a private key block in the output of a build
	# that then failed.
	my $generated = $keys->generated;
	unless ($generated) {
		$self->{log}->error( 'The key directory is not usable: %s',
			$keys->error );
		return;
	}

	for my $copy ( $keys->copies ) {
		$self->_write_out(
			$copy->{to},
			sub {
				my $bytes = Fugu::File->read( $copy->{from} );
				$self->{log}
				    ->error( 'Cannot read %s', $copy->{from} )
				    unless defined $bytes;
				return $bytes;
			} ) or return;
	}

	for my $path ( sort keys %$generated ) {
		$self->_write_out( $path, sub { return $generated->{$path} } )
		    or return;
	}

	return 1;
}

# $self->_write_out($path, $bytes):
#	Write one file of the key directory, at a path below the
#	output directory. Fugu::File->write opens the file and creates
#	no parent, and the Web Key Directory sits three directories
#	down, so the parent comes first.
#
#	The bytes arrive through a code reference, so a read that
#	fails reports its own path and this method reports none.
sub _write_out ( $self, $path, $bytes )
{
	my $target = $self->{out} . "/$path";

	my $dir = $target =~ s{/[^/]+\z}{}r;
	Fugu::File->ensure_dir($dir) or return;

	my $data = $bytes->() // return;

	return Fugu::File->write( $target, $data );
}

# $self->_render_pages:
#	Render every page block. A body fragment is already HTML, a
#	Markdown file goes through lowdown, and the index comes from
#	App::FuguWeb::Index.
sub _render_pages ($self)
{
	my $config = $self->{config};
	my $page   = App::FuguWeb::Page->new( config => $config );
	my $index  = App::FuguWeb::Index->new( config => $config );

	for my $entry ( $config->pages ) {
		my $fragment;

		if ( $entry->{source} eq 'body' ) {
			my $path = $config->source_path( $entry->{value} );
			$fragment = Fugu::File->read($path);
			unless ( defined $fragment ) {
				$self->{log}->error( 'Cannot read %s', $path );
				return;
			}
		}
		elsif ( $entry->{source} eq 'markdown' ) {
			$fragment =
			    $self->{render}
			    ->markdown( $config->root . '/' . $entry->{value} );
			return unless defined $fragment;
		}
		else {
			$fragment = $index->body;
		}

		$page->write( $self->{out} . '/' . $entry->{file},
			$entry->{title}, $fragment )
		    or return;
	}

	return 1;
}

# $self->_render_manuals:
#	Render one page for each manual of each group.
sub _render_manuals ($self)
{
	my $config = $self->{config};
	my $page   = App::FuguWeb::Page->new( config => $config );
	my $date   = $self->pod_date;

	for my $group ( $config->groups ) {
		for my $manual ( $group->manuals ) {
			my $fragment =
			      $manual->is_pod
			    ? $self->{render}
			    ->pod( $manual->path, $manual->name, $date )
			    : $self->{render}
			    ->mdoc( $manual->staged_name, $self->staging );
			return unless defined $fragment;

			$page->write(
				$self->{out} . '/' . $manual->page,
				$manual->name . '(' . $manual->section . ')',
				$fragment
			) or return;
		}
	}

	return 1;
}

1;



( run in 1.095 second using v1.01-cache-2.11-cpan-364913b4093 )