svn clones: fix prefix computation
[girocco.git] / cgi / html.cgi
blob824bae03efac9ea53f0ee2282ddca29e8773b18e
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;
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
18 # /@@base(gitweburl)@@/ substitute for base portion of gitweburl variable
19 # /@@path(gitweburl)@@/ substitute for path portion of gitweburl variable
20 # /@@ifmob@@...@@end@@/ remove unless mob defined
21 # /@@ifssh@@...@@end@@/ remove unless pushurl defined
22 # /@@ifhttps@@...@@end@@/ remove unless httpspushurl defined
24 my $pathinfo = $ENV{PATH_INFO} || '';
25 $pathinfo =~ s,^/,,;
26 unless ($pathinfo) {
27 my $gcgi = Girocco::CGI->new('HTML Templater');
28 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
29 exit;
32 unless ($pathinfo !~ m#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
33 my $gcgi = Girocco::CGI->new('HTML Templater');
34 print "<p>Invalid template name.</p>\n";
35 exit;
38 if ($pathinfo =~ /\.png$/) {
39 print "Content-type: image/png\n\n";
40 print while (<TEMPLATE>);
41 exit;
44 my ($gcgi, $section, $heading);
46 my $template=join('', <TEMPLATE>);
47 close TEMPLATE;
48 $template =~ s/@\@ifmob@\@(.*?)@\@end@\@/$Girocco::Config::mob?$1:''/ges;
49 $template =~ s/@\@ifssh@\@(.*?)@\@end@\@/$Girocco::Config::pushurl?$1:''/ges;
50 $template =~ s/@\@ifhttps@\@(.*?)@\@end@\@/$Girocco::Config::httpspushurl?$1:''/ges;
52 foreach (split(/\n/, $template)) {
53 chomp;
54 if (s/^\@section=//) {
55 $section = $_;
56 next;
57 } elsif (s/^\@heading=//) {
58 $heading = $_;
59 next;
60 } elsif (s/^\@header//) {
61 $gcgi = Girocco::CGI->new($heading, $section);
62 print "<div class=\"htmlcgi\">";
63 next;
64 } else {
65 s/@\@base\((\w+?)\)@@/url_base(${$Girocco::Config::{$1}})/ge;
66 s/@\@path\((\w+?)\)@@/url_path(${$Girocco::Config::{$1}})/ge;
67 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
68 print "$_\n";
71 print "</div>";
72 $gcgi and $gcgi->srcname("html/$pathinfo");