App-Followme
view release on metacpan or search on metacpan
lib/App/Followme/ConvertPage.pm view on Meta::CPAN
$new_filename =~ s/ +$//;
$new_filename =~ s/ +/\-/g;
$new_filename = catfile($dir, join('.', $new_filename, $ext));
return $new_filename;
}
#----------------------------------------------------------------------
# Convert a single file
sub update_file {
my ($self, $folder, $prototype, $file) = @_;
my $new_file = $self->{data}->convert_filename($file);
my $page = $self->render_file($self->{template_file}, $file);
$page = $self->reformat_file($prototype, $new_file, $page);
$self->write_file($new_file, $page);
return;
}
#----------------------------------------------------------------------
# Find files in directory to convert and do that
sub update_folder {
my ($self, $folder) = @_;
my $index_file = $self->to_file($folder);
my $source_folder = $self->{data}->convert_source_directory($folder);
return unless $source_folder;
my $same_directory = fio_same_file($folder, $source_folder,
$self->{case_sensitivity});
$index_file = $self->to_file($source_folder);
my $files = $self->{data}->build('files', $index_file);
my $prototype;
foreach my $file (@$files) {
my $prototype ||= $self->find_prototype($folder, 0);
eval {$self->update_file($folder, $prototype, $file)};
if ($self->check_error($@, $file)) {
unlink($file) if $same_directory;
}
}
my $folders = $self->{data}->build('folders', $index_file);
foreach my $subfolder (@$folders) {
$self->update_folder($subfolder);
}
return;
}
#----------------------------------------------------------------------
# Write a file, setting folder level metadata
sub write_file {
my ($self, $filename, $page, $binmode) = @_;
my $time = ${$self->{data}->build('mdate', $filename)};
my $new_filename = $self->title_to_filename($filename);
fio_write_page($new_filename, $page, $binmode);
unlink($filename) if -e $filename &&
! fio_same_file($filename, $new_filename, $self->{case_sensitivity});
fio_set_date($new_filename, $time);
return;
}
1;
__END__
=encoding utf-8
=head1 NAME
App::Followme::ConvertPage - Convert text files to html
=head1 SYNOPSIS
use App::Followme::ConvertPage;
my $converter = App::Followme::ConvertPage->new($configuration);
$converter->run($folder);
=head1 DESCRIPTION
This module converts text files into web files by substituting the content into
a template. The type of file converted is determined by the value of the
parameter data_pkg. By default, it converts text files using the methods in
App::Followme::TextData. After the conversion the original file is deleted.
Along with the content, other variables are calculated from the file name and
modification date. Variables in the template are preceded by a sigil, most
usually a dollar sign. Thus a link would look like:
<li><a href="$url">$title</a></li>
=head1 CONFIGURATION
The following parameters are used from the configuration:
=over 4
=item template_file
The name of the template file. The template file is either in the current
directory, in the same directory as the configuration file used to invoke this
method, or if not there, in the _templates subdirectory of the top directory.
The default value is 'convert_page.htm'.
=item data_pkg
The name of the module that parses and retrieves data from the text file. The
default value is 'App::Followme::TextData', which by default parses
Markdown files.
=back
=head1 LICENSE
( run in 0.771 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )