App-Aphra
view release on metacpan or search on metacpan
=over 4
=item B<source>
The main directory that contains the input files. Any file that is found in
this directory will be processed and an equivalent output file will be
created in the B<target> directory. The default value for this option is "in".
$ aphra --source some/other/directory
=item B<fragments>
A directory that contains other templates which are used in the processing
of the source templates. For example, you might have a template in the source
directory called C<index.html.tt> which includes other templates called
C<menu.html.tt> and C<footer.html.tt>. These templates shouldn't be put in
the source directory (as they would then be processed and written to the
target directory, but if they are put in the fragments directory, they will
be found by the template processor. The default value for this option is
"fragments".
$ aphra --fragments some/directory/of/fragments
=item B<layouts>
A directory that contains templates which are used to control the layout of
the files which are produced. These are typically used with the C<WRAPPER>
directive in the Template Toolkit. There's really no difference in handling
the layouts and fragments directories, but I find it useful to keep the two
types of template separate. The default value for this option is "layouts".
$ aphra --layouts some/directory/of/layouts
=item B<wrapper>
The name of a template that will be used as the main C<WRAPPER> for the rest
of the templates. This template should usually contain a C<[% content %]> tag
and will normally be stored in the layouts directory. See the L<Template
Toolkit> documentation for more details of the C<WRAPPER> directive. The
placed under the output directory in a position that mirrors the position
of the input file under the iput directory. The output file is also renamed
to remove the extension that marked the input file as a template.
An example might make this clearer. Imagine we have all of the default
configuration options and the following directory tree.
src/index.html.tt
src/style.css
src/about/index.html.tt
fragments/index_text.md
fragments/about_text.md
And assume that C<index.html.tt> includes the Template Toolkit directive
C<[% INCLUDE index_text.md %]> and C<about/index.html.tt> contains a similar
directive refering to C<about_text.md>. Here's what will happen.
=over 4
=item *
C<src/index.html.tt> is found. Its extension, C<.tt>, matches one of the
defined extensions, so it is processed by the Template Toolkit.
=item *
As part of this processing, the Template Toolkit needs to process
C<index_text.md>. This template is found in the fragments directory, but
its extension, C<.md>, means that it is pre-processed by C<pandoc> (converting
Markdown to HTML) before it is processed by the Template Toolkit.
=item *
The output from processing C<src/index.html.tt> is written to
C<docs/index.html>. The C<.tt> extension is removed.
=item *
C<src/style.css> is found. As its extension is not one of the defined ones,
it is simply copied to C<docs/style.css>.
=item *
C<src/about/index.html.tt> is found. It is processed in a very similar way
to C<src/index.html> (including the processing of C<fragments/about_text.md>
and the output is written to C<docs/about/index.html>.
=back
After the processing is complete, we have the following in the C<docs>
directory:
docs/index.html
docs/style.css
docs/about/index.html
lib/App/Aphra.pm view on Meta::CPAN
has config_defaults => (
isa => 'HashRef',
is => 'ro',
lazy_build => 1,
);
sub _build_config_defaults {
return {
source => 'in',
fragments => 'fragments',
layouts => 'layouts',
wrapper => 'page',
target => 'docs',
extensions => {
tt => 'template',
md => 'markdown',
},
output => 'html',
};
}
lib/App/Aphra.pm view on Meta::CPAN
isa => 'HashRef',
is => 'ro',
lazy_build => 1,
);
sub _build_config {
my $self = shift;
my %opts;
GetOptions(\%opts,
'source=s', 'fragments=s', 'layouts=s', 'wrapper=s',
'target=s', 'extensions=s%', 'output=s',
'version', 'help');
for (qw[version help]) {
$self->$_ and exit if $opts{$_};
}
my %defaults = %{ $self->config_defaults };
my %config;
lib/App/Aphra.pm view on Meta::CPAN
has include_path => (
isa => 'ArrayRef',
is => 'ro',
lazy_build => 1,
);
sub _build_include_path {
my $self = shift;
my $include_path;
foreach (qw[source fragments layouts]) {
push @$include_path, $self->config->{$_}
if exists $self->config->{$_};
}
return $include_path;
}
has template => (
isa => 'Template',
is => 'ro',
t/01-basic.t view on Meta::CPAN
use Test::More;
use App::Aphra;
ok(my $app = App::Aphra->new, 'Got an object');
isa_ok($app, 'App::Aphra');
my %config = (
source => 'in',
fragments => 'fragments',
layouts => 'layouts',
wrapper => 'page',
target => 'docs',
output => 'html',
);
for (keys %config) {
is($app->config->{$_}, $config{$_}, "Config value $_ is correct");
}
( run in 1.917 second using v1.01-cache-2.11-cpan-b16cb0d3907 )