b8e38891ecbf47f2d5d98dee0edae71d32253fd6
[www.jankratochvil.net.git] / project / Index.html.pl
1 #! /usr/bin/perl
2
3 # $Id$
4 # List of projects Perl template.
5 # Copyright (C) 2003 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; exactly version 2 of June 1991 is required
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20
21 package project::Index;
22 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
23 our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
24 our $CVS_ID=q$Id$;
25 use strict;
26 use warnings;
27
28 BEGIN{ open F,"Makefile"; our $top_dir=pop @{[split /\s/,(grep /^top_srcdir/,<F>)[0]]}; eval "use lib '$top_dir'"; close F; }
29 use My::Web;
30 require CGI;
31 Wrequire 'My::Project';
32
33 use constant ENTRIES=>"CVS/Entries";
34 use constant ENTRIES_LOG=>"CVS/Entries.Log";
35
36
37 My::Web->init(
38                 "__PACKAGE__"=>__PACKAGE__,
39                 "title"=>'Project List',
40                 );
41 My::Web->heading();
42
43 my $CGI=CGI->new();
44
45 print <<'HERE';
46 <h1>Project List of <a href="mailto:web-www.jankratochvil.net@jankratochvil.net">Jan Kratochvil</a></h1>
47
48 <form action="Index.html.pl" method="get"><p>
49 <select name="description_opt" onchange="this.form.submit();">
50 HERE
51 print '<option value="0"'.(!$CGI->param("description_opt") ? ' selected="selected"' : '').'>only list</option>'."\n";
52 print '<option value="1"'.( $CGI->param("description_opt") ? ' selected="selected"' : '').'>incl. descriptions</option>'."\n";
53 print <<'HERE';
54 </select>
55 <input type="submit" value="Update" />
56 </p></form>
57 HERE
58
59 my %dirs;
60 for my $ENTRIES (ENTRIES,ENTRIES_LOG) {
61         local *E;
62         next if !open E,$ENTRIES;
63         while (<E>) {
64                 chomp;
65                 do { $dirs{$1}=1; next; } if m#^(?:A )?D/([^/]*)/#;
66                 next if m#^/([^/]*)/# ;
67                 next if /^D$/;
68                 warn "File $ENTRIES contains invalid line \"$_\": $!";
69                 }
70         close E;
71         }
72
73 my %item;
74 for my $dir (keys(%dirs)) {
75         Wrequire "project::${dir}::ListItem";
76         my $item=eval('\@project::'.$dir.'::ListItem::ListItem');
77         do { warn "Broken project/$dir/ListItem.pm"; next; } if !defined $item;
78         $item{$dir}={ My::Project::project_arr_to_hash(@$item) };
79         }
80
81 # $col{"name"}{"show"}=1
82 # $col{"name"}{"format"}=sub { "<".$_[0].">"; }
83 # $col{"name"}{""}="Project name";
84 # @col_order
85
86 my @row_order=qw(-priority);
87 my @col_order=qw(name summary license maintenance language);
88 my %col;
89
90 sub format_url ($) { return (!$_[0] ? "" : '<a href="'.$_[0].'">X</a>'); }
91
92 $col{"name"}{"format"}=sub {
93                 $_[0]=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
94                 return "<a href=\"".$_[1]."/\">".$_[0]."</a>";
95                 };
96
97 $col{"license"}{"format"}=sub {
98                 my %known=(
99                                 "PD"=>"<a href=\"http://www.gnu.org/philosophy/categories.html#PublicDomainSoftware\">PD</a>",
100                                 "GPL"=>"<a href=\"http://www.gnu.org/licenses/gpl.html\">GPL</a>",
101                                 "LGPL"=>"<a href=\"http://www.gnu.org/licenses/lgpl.html\">LGPL</a>",
102                                 );
103                 return $known{$_[0]} if $known{$_[0]};
104                 return $_[0];
105                 };
106
107 $col{"maintenance"}{"format"}=sub {
108                 return ($_[0]=~/^([^-]*)/)[0];
109                 };
110
111 $col{"online-demo"}{"format"}=\&format_url;
112 $col{"download"}{"format"}=\&format_url;
113 $col{"name"}{""}="Project Name";
114 $col{"summary"}{""}="Abstract";
115 $col{"license"}{""}="Copying";
116 $col{"maintenance"}{""}="State";
117 $col{"language"}{""}="Language";
118
119 # Fill in cols not contained in @col_order
120 if (0) {
121         my %col_order=map(($_=>1),@col_order);
122         push @col_order,map({ ($col_order{$_} ? () : $_); } keys(%{{ map(($_=>1),map((keys(%{$item{$_}})),keys(%item)))}}));
123         }
124
125 print '<table border="1">'."\n";
126         print '<tr>';
127                 for my $col (@col_order) {
128                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
129                         print '<th>'.($col{$col}{""} || "[$col]").'</th>';
130                         }
131         print '</tr>'."\n";
132         my @rows_ordered=sort {
133                         for my $order_by (@row_order,"name") {
134                                 my $order_by=$order_by;
135                                 my $minus=($order_by=~s/^(-)//)[0];
136                                 my $r=($item{$a}{$order_by} cmp $item{$b}{$order_by});
137                                 $r=-$r if $minus;
138                                 return $r if $r;
139                                 }
140                         return 0;
141                         } keys(%item);
142         for my $row (@rows_ordered) {
143                 print '<tr>';
144                 for my $col (@col_order) {
145                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
146                         print '<td>';
147                         if (!$col{$col}{"format"}) {
148                                 print(($item{$row}{$col} || ""));
149                                 }
150                         else {
151                                 print(&{$col{$col}{"format"}}($item{$row}{$col},$row));
152                                 }
153                         print '</td>';
154                         }
155                 print '</tr>'."\n";
156                 if ($CGI->param("description_opt")) {
157                         print '<tr><td style="border: none;"></td>';
158                         print '<td colspan="'.(scalar(@col_order)-1).'"><blockquote>'.$item{$row}{"description"}.'</blockquote></td>';
159                         print '</tr>'."\n";
160                         print '<tr><td style="border: none;" colspan="'.scalar(@col_order).'">&nbsp;</td></tr>'."\n";
161                         }
162                 }
163 print '</table>'."\n";
164
165 My::Web->footer();