From e31c4a22084c5dab844164f2b97fd74b03764c17 Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Tue, 28 Jun 2022 10:46:52 -0400 Subject: [PATCH] Initial ability to generate page from config file Added a function to facilitate looping through a list of pages to be generated. Currently hard coded the generation of the contact page based on the site.cfg file. --- site-generator | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/site-generator b/site-generator index 8793909..612a5f2 100755 --- a/site-generator +++ b/site-generator @@ -37,6 +37,7 @@ use warnings; use Getopt::Long qw(:config auto_help); use Pod::Usage; use Config::Std; +use Template; exit main(); @@ -53,9 +54,36 @@ sub main { # Load config file read_config "site.cfg" => my %config; - use Data::Dumper 'Dumper'; - warn Dumper [ \%config ]; + my $tt = get_template_html(); + generate_page($tt, $config{contact}{navigation}, $config{contact}{content}); return 0; } +sub get_template_html { + + # For an HTML based Template file, define the + # template start and end tags to also function as + # HTML comments to make the template file valid HTML. + # + return Template->new({ + INCLUDE_PATH => './templates', + EVAL_PERL => 1, + START_TAG => '', + }) || die $Template::ERROR, "\n"; + +} + +sub generate_page ($tt, $navigation, $content) { + my ($tt, $navigation, $content) = @_; + my $tt_vars = { + navigation => $navigation, + content => $content + }; + + $tt->process('page.tpl.html', $tt_vars) + || die $tt->error(), "\n"; + +} +