forked from rho_n/hpr_generator
Configure database connection in config file
Pass the db configuration info to the page templates via the template constants feature.
This commit is contained in:
parent
b33e812c3d
commit
3d0ddbfe24
@ -54,14 +54,13 @@ sub main {
|
|||||||
# Load config file
|
# Load config file
|
||||||
read_config "site.cfg" => my %config;
|
read_config "site.cfg" => my %config;
|
||||||
|
|
||||||
my $tt = get_template_html();
|
my $tt = get_template_html($config{DBI});
|
||||||
generate_page($tt, $config{correspondents}{navigation}, $config{correspondents}{content});
|
generate_page($tt, $config{correspondents}{navigation}, $config{correspondents}{content});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_template_html {
|
sub get_template_html (\%@) {
|
||||||
|
|
||||||
# For an HTML based Template file, define the
|
# For an HTML based Template file, define the
|
||||||
# template start and end tags to also function as
|
# template start and end tags to also function as
|
||||||
# HTML comments to make the template file valid HTML.
|
# HTML comments to make the template file valid HTML.
|
||||||
@ -71,6 +70,11 @@ sub get_template_html {
|
|||||||
EVAL_PERL => 1,
|
EVAL_PERL => 1,
|
||||||
START_TAG => '<!--%',
|
START_TAG => '<!--%',
|
||||||
END_TAG => '%-->',
|
END_TAG => '%-->',
|
||||||
|
CONSTANTS => {
|
||||||
|
driver => $_[0]{driver},
|
||||||
|
user => $_[0]{user},
|
||||||
|
password => $_[0]{password},
|
||||||
|
}
|
||||||
}) || die $Template::ERROR, "\n";
|
}) || die $Template::ERROR, "\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
8
site.cfg
8
site.cfg
@ -1,3 +1,11 @@
|
|||||||
|
# Configure the Perl DBI driver to allow the templates communicate
|
||||||
|
# with the database.
|
||||||
|
# dbi:<driver name [SQLite, CSV, ADO, mSQL, etc.]>:<database name>
|
||||||
|
[DBI]
|
||||||
|
driver: dbi:SQLite:hpr.db
|
||||||
|
user:
|
||||||
|
password:
|
||||||
|
|
||||||
# Configure the navigation menu and the content templates for each page
|
# Configure the navigation menu and the content templates for each page
|
||||||
# of the site:
|
# of the site:
|
||||||
# [page_name]
|
# [page_name]
|
||||||
|
Loading…
Reference in New Issue
Block a user