-sub read_templates {
- my $name = shift;
-
- my %tmpl = map { m/\.(.+)$/; $1 => scalar read_file $_ } <tmpl/$name.*>;
- my %arti = map { m/\.(.+)$/; $1 => scalar read_file $_ } <a/$name.*>;
- return %tmpl ? %tmpl : %arti
-}
-
-my %header_templates = read_templates 'header';
-my %footer_templates = read_templates 'footer';
-my %templates;
-
-sub render {
- my ($tmpl, $title, %params) = @_;
- unless ($templates{$tmpl}) {
- $templates{$tmpl} = { read_templates $tmpl };
- for my $lang (keys $templates{$tmpl}) {
- my $header = $header_templates{$lang} =~ s/TITLE_GOES_HERE/$title/rg;
- $templates{$tmpl}{$lang} = $header . $templates{$tmpl}{$lang};
- }
- $templates{$tmpl}{$_} .= $footer_templates{$_} for keys $templates{$tmpl};
-
- }
-
- my $htc = HTML::Template::Compiled->new(scalarref => \$templates{$tmpl}{en}, default_escape => 'HTML', use_perl => 1);
- $htc->param(%params);
- [200, ['Content-Type' => 'text/html'], [$htc->output]]
-}
-