README: Describe forks
[girocco.git] / cgi / html.cgi
bloba2e500f6f9735f888885537ccca0c7d96278c819
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;
13 # Ultra-trivial templating engine;
14 # /^@section=SECTION
15 # /^@heading=HEADING
16 # /^@header produces HTML header based on @section and @heading
17 # /@@gitweburl@@/ substitute for gitweburl configuration variable
20 my $pathinfo = $ENV{PATH_INFO};
21 unless ($pathinfo) {
22 my $gcgi = Girocco::CGI->new('HTML Templater');
23 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
24 exit;
27 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
28 my $gcgi = Girocco::CGI->new('HTML Templater');
29 print "<p>Invalid template name.</p>\n";
30 exit;
33 if ($pathinfo =~ /\.png$/) {
34 print "Content-type: image/png\n\n";
35 print while (<TEMPLATE>);
36 exit;
39 my ($gcgi, $section, $heading);
41 while (<TEMPLATE>) {
42 chomp;
43 if (s/^\@section=//) {
44 $section = $_;
45 next;
46 } elsif (s/^\@heading=//) {
47 $heading = $_;
48 next;
49 } elsif (s/^\@header//) {
50 $gcgi = Girocco::CGI->new($heading, $section);
51 next;
52 } else {
53 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
54 print "$_\n";
58 close TEMPLATE;
60 $gcgi and $gcgi->srcname("html/$pathinfo");