App-Dapper
view release on metacpan or search on metacpan
lib/App/Dapper.pm view on Meta::CPAN
use App::Dapper;
my $d = App::Dapper->new();
$d->build();
When the site is built, it is done in three steps:
1. Parse. In this step, the configuration file is read. In addition, all the source files in the source directory as well as the layout files in the layout directory are reach and stored in the site hash.
2. Transform. Combine source and layout files.
3. Render. Save output files to the output directory.
=cut
sub build {
my($self) = @_;
$ID = 0;
$self->parse();
$self->transform();
$self->render();
print "Project built.\n";
}
# sub parse - Parse the source directory, config file, and templates.
sub parse {
my ($self) = @_;
# load program and project configuration
$self->read_project();
# replaces the values of h_template with actual content
$self->read_templates();
}
# sub transform - Walk the source and output directories and transform the text into the output files.
sub transform {
my ($self) = @_;
# recurse through the project tree and generate output (combine src with templates)
$self->walk($self->{source}, $self->{output});
}
# sub render - Render the internal hash of source files, config file, and layouts into the actual output files on disk.
sub render {
my ($self) = @_;
my $tt = Template::Alloy->new({
INCLUDE_PATH => $self->{layout},
ANYCASE => 1,
ENCODING => 'utf8',
#STRICT => 1,
FILTERS => {
'xml_escape' => \&App::Dapper::Filters::xml_escape,
'date_to_xmlschema' => \&App::Dapper::Filters::date_to_xmlschema,
'replace_last' => \&App::Dapper::Filters::replace_last,
'smart' => \&App::Dapper::Filters::smart,
'json' => \&App::Dapper::Filters::json,
},
#ERROR => 'alloy_errors.html',
EVAL_PERL => $ENV{EVAL_PERL} || 0,
#DEBUG => DEBUG_ALL,
}) || die "$Template::ERROR\n";
for my $page (@{$self->{site}->{pages}}) {
#print Dump $page->{content};
if (not $page->{layout}) {
$page->{layout} = "index";
#print "WARNING: $page->{filename} does not have a page layout assigned: $page->{layout}.\n";
}
my $layout = $self->{layout_content}->{$page->{layout}};
my %tags = ();
$tags{site} = $self->{site};
$tags{page} = $page;
#$tags{page}->{content} = $content;
my $destination1;
$tt->process(\$layout, \%tags, \$destination1)
|| die "Error processing $tags{page}->{filename} with $page->{layout}:" . $tt->error() . "\n";
#if ($page->{layout} ne "index" and $layout =~ m/circuits/) {
# print "DANGER WILL ROBINSON ";
# print "PROCESSED: $tags{page}->{filename} with $page->{layout}\n\n$layout\n\n\n";
#}
# Parse and render once more to make sure that any liquid statments
# In the source file also gets rendered
my $destination;
$tt->process(\$destination1, \%tags, \$destination)
|| die "Error processing (2nd pass) $tags{page}->{filename} with $page->{layout}:" . $tt->error() . "\n";
if ($page->{filename}) {
make_path($page->{dirname}, { verbose => 1 });
open(DESTINATION, ">$page->{filename}") or die "error: could not open destination file:$page->{filename}: $!\n";
print(DESTINATION $destination) or die "error: could not print to $page->{filename}: $!\n";
close(DESTINATION) or die "error: could not close $page->{filename}: $!\n";
print "Wrote $page->{filename}\n";
}
else {
print Dumper "No filename specified\n";
}
}
#print Dumper $self->{site};
#print Dumper($self->{site});
# copy additional files and directories
( run in 0.661 second using v1.01-cache-2.11-cpan-2398b32b56e )