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