cgi/html.cgi: Introduce simple template engine
[girocco.git] / cgi / html.cgi
blobe2291b17ce5bed9edc370ce9695ef25ae6116bd3
1 #!/usr/bin/perl
2 # (c) Petr Baudis <pasky@suse.cz>
3 # GPLv2
5 use strict;
6 use warnings;
8 use lib ".";
9 use Girocco::CGI;
10 use Girocco::Config;
11 use Girocco::Util;
14 # Ultra-trivial templating engine
17 my $pathinfo = $ENV{PATH_INFO};
18 unless ($pathinfo) {
19 my $gcgi = Girocco::CGI->new('HTML Templater');
20 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
21 exit;
24 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$basedir/html/$pathinfo")) {
25 my $gcgi = Girocco::CGI->new('HTML Templater');
26 print "<p>Invalid template name.</p>\n";
27 exit;
30 my ($gcgi, $section, $heading);
32 while (<TEMPLATE>) {
33 chomp;
34 if (s/^\@section=//) {
35 $section = $_;
36 next;
37 } elsif (s/^\@heading=//) {
38 $heading = $_;
39 next;
40 } elsif (s/^\@header//) {
41 $gcgi = Girocco::CGI->new($heading, $section);
42 next;
43 } else {
44 print "$_\n";
48 close TEMPLATE;
50 $gcgi and $gcgi->srcname("html/$pathinfo");