2 # (c) Petr Baudis <pasky@suse.cz>
13 # Ultra-trivial templating engine;
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 # /@@server(gitweburl)@@/ replace scheme://host:port portion of gitweburl variable
21 # /@@ifmob@@...@@end@@/ remove unless mob defined
22 # /@@ifssh@@...@@end@@/ remove unless pushurl defined
23 # /@@ifhttps@@...@@end@@/ remove unless httpspushurl defined
25 my $pathinfo = $ENV{PATH_INFO
} || '';
28 my $gcgi = Girocco
::CGI
->new('HTML Templater');
29 print "<p>Hi, this is your friendly HTML templater speaking. Pass me template name.</p>\n";
33 unless ($pathinfo !~ m
#\./# and open(TEMPLATE, "$Girocco::Config::basedir/html/$pathinfo")) {
34 my $gcgi = Girocco
::CGI
->new('HTML Templater');
35 print "<p>Invalid template name.</p>\n";
39 if ($pathinfo =~ /\.png$/) {
40 print "Content-type: image/png\n\n";
41 print while (<TEMPLATE
>);
45 my ($gcgi, $section, $heading);
47 my $template=join('', <TEMPLATE
>);
49 $template =~ s/@\@ifmob@\@(.*?)@\@end@\@/$Girocco::Config::mob?$1:''/ges;
50 $template =~ s/@\@ifssh@\@(.*?)@\@end@\@/$Girocco::Config::pushurl?$1:''/ges;
51 $template =~ s/@\@ifhttps@\@(.*?)@\@end@\@/$Girocco::Config::httpspushurl?$1:''/ges;
53 foreach (split(/\n/, $template)) {
55 if (s/^\@section=//) {
58 } elsif (s/^\@heading=//) {
61 } elsif (s/^\@header//) {
62 $gcgi = Girocco
::CGI
->new($heading, $section);
63 print "<div class=\"htmlcgi\">";
66 s/@\@base\((\w+?)\)@@/url_base(${$Girocco::Config::{$1}})/ge;
67 s/@\@path\((\w+?)\)@@/url_path(${$Girocco::Config::{$1}})/ge;
68 s/@\@server\((\w+?)\)@@/url_server(${$Girocco::Config::{$1}})/ge;
69 s/@@(\w+?)@@/${$Girocco::Config::{$1}}/ge;
74 $gcgi and $gcgi->srcname("html/$pathinfo");