COPYING: New file with the GPLv2 licence text to clarify the legal situation
[girocco.git] / cgi / html.cgi
bloba206bda61c404d38579e8d66544724593f731589
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 $pathinfo =~ s,^/,,;
22 unless ($pathinfo) {
23 my $gcgi = Girocco::CGI->new('HTML Templater');
24 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
25 exit;
28 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
29 my $gcgi = Girocco::CGI->new('HTML Templater');
30 print "<p>Invalid template name.</p>\n";
31 exit;
34 if ($pathinfo =~ /\.png$/) {
35 print "Content-type: image/png\n\n";
36 print while (<TEMPLATE>);
37 exit;
40 my ($gcgi, $section, $heading);
42 while (<TEMPLATE>) {
43 chomp;
44 if (s/^\@section=//) {
45 $section = $_;
46 next;
47 } elsif (s/^\@heading=//) {
48 $heading = $_;
49 next;
50 } elsif (s/^\@header//) {
51 $gcgi = Girocco::CGI->new($heading, $section);
52 next;
53 } else {
54 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
55 print "$_\n";
59 close TEMPLATE;
61 $gcgi and $gcgi->srcname("html/$pathinfo");