#!/usr/bin/perl

use Template;
use YAML 'LoadFile';

my $tmpl = Template->new({
                    RELATIVE => 1,
                    INCLUDE_PATH => $ENV{"PWD"} . "/tmpl"
                    });

my ( $conf ) = LoadFile("mysite.yml");

my $pages = $conf->{'pages'};
foreach my $page (@$pages) {
    my $path = "site/$page.html";
    open($file, ">$path");
    my $tt = "main.tt";
    $conf->{"page"} = "$page.tt";
    $tmpl->process($tt, $conf, \*$file);
    close($file);
}

mkdir "site/css" unless -d "site/css";
my $stylesheets = $conf->{'stylesheets'};
foreach my $stylesheet (@$stylesheets) {
    my $path = "site/css/$stylesheet.css";
    open($file, ">$path");
    my $tt = "css/$stylesheet.tt";
    $tmpl->process($tt, $conf, \*$file);
    close($file);
}

mkdir "site/js" unless -d "site/js";
my $scripts = $conf->{'scripts'};
foreach my $script (@$scripts) {
    my $path = "site/js/$script.js";
    open($file, ">$path");
    my $tt = "js/$script.tt";
    $tmpl->process($tt, $conf, \*$file);
    close($file);
}



syntax highlighted by Code2HTML, v. 0.9.1