06dd0784bb31747bfe632a12447330707c43d189
[www.jankratochvil.net.git] / project / List.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::List;
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
34 My::Web->init(
35                 "__PACKAGE__"=>__PACKAGE__,
36                 "title"=>'Project List',
37                 );
38 My::Web->heading();
39
40 my $CGI=CGI->new();
41
42 print <<"HERE";
43 <h1>@{[ a_href './','Project List' ]} of @{[ a_href 'http://www.jankratochvil.net/','Jan Kratochvil' ]}</h1>
44 HERE
45
46 my %item=( My::Project::item_hash_read() );
47
48 # $col{"name"}{"show"}=1
49 # $col{"name"}{"format"}=sub { "<".$_[0].">"; }
50 # $col{"name"}{""}="Project name";
51 # @col_order
52
53 my @row_order=qw(-priority);
54 my @col_order=qw(name summary license maintenance language);
55 my %col;
56
57 sub format_url ($) { return (!$_[0] ? "" : '<a href="'.$_[0].'">X</a>'); }
58
59 $col{"name"}{"format"}=sub {
60                 $_[0]=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
61                 return "<a href=\"".$_[1]."/\">".$_[0]."</a>";
62                 };
63
64 $col{"license"}{"format"}=sub {
65                 my %known=(
66                                 "PD"=>"<a href=\"http://www.gnu.org/philosophy/categories.html#PublicDomainSoftware\">PD</a>",
67                                 "GPL"=>"<a href=\"http://www.gnu.org/licenses/gpl.html\">GPL</a>",
68                                 "LGPL"=>"<a href=\"http://www.gnu.org/licenses/lgpl.html\">LGPL</a>",
69                                 );
70                 return $known{$_[0]} if $known{$_[0]};
71                 return $_[0];
72                 };
73
74 $col{"maintenance"}{"format"}=sub {
75                 return ($_[0]=~/^([^-]*)/)[0];
76                 };
77
78 $col{"online-demo"}{"format"}=\&format_url;
79 $col{"download"}{"format"}=\&format_url;
80 $col{"name"}{""}="Project Name";
81 $col{"summary"}{""}="Abstract";
82 $col{"license"}{""}="Copying";
83 $col{"maintenance"}{""}="State";
84 $col{"language"}{""}="Language";
85
86 # Fill in cols not contained in @col_order
87 if (0) {
88         my %col_order=map(($_=>1),@col_order);
89         push @col_order,map({ ($col_order{$_} ? () : $_); } keys(%{{ map(($_=>1),map((keys(%{$item{$_}})),keys(%item)))}}));
90         }
91
92 print '<table border="1">'."\n";
93         print '<tr>';
94                 for my $col (@col_order) {
95                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
96                         print '<th>'.($col{$col}{""} || "[$col]").'</th>';
97                         }
98         print '</tr>'."\n";
99         my @rows_ordered=sort {
100                         for my $order_by (@row_order,"name") {
101                                 my $order_by=$order_by;
102                                 my $minus=($order_by=~s/^(-)//)[0];
103                                 my $r=($item{$a}{$order_by} cmp $item{$b}{$order_by});
104                                 $r=-$r if $minus;
105                                 return $r if $r;
106                                 }
107                         return 0;
108                         } keys(%item);
109         for my $row (@rows_ordered) {
110                 print '<tr>';
111                 for my $col (@col_order) {
112                         next if defined $col{$col}{"show"} && !$col{$col}{"show"};
113                         print '<td>';
114                         if (!$col{$col}{"format"}) {
115                                 print(($item{$row}{$col} || ""));
116                                 }
117                         else {
118                                 print(&{$col{$col}{"format"}}($item{$row}{$col},$row));
119                                 }
120                         print '</td>';
121                         }
122                 print '</tr>'."\n";
123                 if ($CGI->param("description_opt")) {
124                         print '<tr><td style="border: none;"></td>';
125                         print '<td colspan="'.(scalar(@col_order)-1).'"><blockquote>'.$item{$row}{"description"}.'</blockquote></td>';
126                         print '</tr>'."\n";
127                         print '<tr><td style="border: none;" colspan="'.scalar(@col_order).'">&nbsp;</td></tr>'."\n";
128                         }
129                 }
130 print '</table>'."\n";
131
132 My::Web->footer();