style/red: apply slight outline to header text
[sheet.git] / source.plp
1 <(common.inc.plp)><:
2         our $VERSION = 'v1.0';
3
4 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
5  "http://www.w3.org/TR/html4/loose.dtd">
6 <html>
7
8 <head>
9 <meta http-equiv="content-type" content="<:= $header{content_type} :>">
10 <title>sheet page source code</title>
11 <:= stylesheet(qw'light dark mono red') :>
12 </head>
13
14 <body id="source">
15 <:
16
17 my $source = $ENV{PATH_INFO};
18 $source =~ s{^/}{};
19
20 if (not $source) {
21         print "<h1>Source files</h1>";
22
23         print "<p>Project code distributed under the AGPL. Please contribute back.</p>";
24         print '<ul>'."\n";
25         for (glob '*.plp') {
26                 chomp;
27                 printf '<li><a href="/source/%s">%1$s</a></li>'."\n", EscapeHTML($_);
28         }
29         print "</ul>\n\n";
30 }
31 else {
32         print "<h1>Source of $source</h1>\n";
33
34         if ($source =~ m{(?:/|^)\.}) {
35                 die "File request not permitted\n";
36         }
37         elsif ($source =~ s{::}{/}g or !-e $source) {
38                 $source .= '.pm';
39                 for (0 .. $#{@INC}) {
40                         -e ($_ = "$INC[$_]/$source") or next;
41                         $source = $_;
42                         last;
43                 }
44         }
45         -r $source or die "Requested file not found\n";
46
47         if (eval { require Text::VimColor and Text::VimColor->VERSION(0.12) }) {
48                 delete $Text::VimColor::SYNTAX_TYPE{Underlined};
49                 my %TYPETAG = (
50                         Statement => 'strong',
51                         Error     => 'em',
52                         Todo      => 'em',
53                 );
54
55                 my $hl = Text::VimColor->new(
56                         file => $source,
57                         vim_options => [@Text::VimColor::VIM_OPTIONS, '+:set enc=utf-8'],
58                 );
59                 my $parsed = $hl->marked;
60                 print "<pre>\n";
61                 foreach (@$parsed) {
62                         my $tag = $_->[0] && ($TYPETAG{ $_->[0] } || 'span');
63                         my $arg = '';
64                         print "<$tag$arg class=\"sy-\l$_->[0]\">" if $tag;
65                         if (!$_->[0] || $_->[0] eq 'Constant'
66                         and $_->[1] =~ s{^(['"]?)(/?[a-z0-9_.]+\.(?:plp?|css|js))(?=\1$)}{}) {
67                                 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
68                         }
69                         if (!$_->[0] and $_->[1] =~ s/^(\s*)([A-Z]\w+(?:::\w+)+)(?![^;\s])//) {
70                                 printf '%s<a href="%s">%s</a>', $1, "/source/$2", $2;
71                         }
72                         print Text::VimColor::_xml_escape($_->[1]);
73                         print "</$tag>" if $tag;
74                 }
75                 print "</pre>\n";
76         }
77         else {
78                 print "<pre>\n", EscapeHTML(ReadFile($source)), "</pre>\n";
79         }
80 }
81 :>
82 <p class="footer">
83         <a href="/" rel="home">sheet.shiar.nl</a>/source.<a href="/source/source.plp"
84          rel="code" title="Written in Perl">plp</a>
85         <a href="http://git.shiar.nl/sheet.git/history/HEAD:/source.plp"
86          rel="vcs-git" title="Git repository"><:= $VERSION :></a>
87         created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
88         <a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html" rel="copyright"
89          title="Licensed under the GNU Affero General Public License, version 3">AGPLv3</a>
90 </p>
91
92 </html>