5054d7136a5f5b11aa0c0329b2de6eb2336f2c5c
[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                 "args_check"=>{
38                                 "platform"=>'^(?:platform)?$',
39                                 },
40 #               "rel_up"=>top_dir(),    # TODO:homepage
41 #               "rel_start"=>top_dir(), # TODO:homepage
42                 "footer_ids"=>0,
43                 );
44 My::Web->heading();
45
46 my $CGI=CGI->new();
47
48 print My::Project->views(($W->{"args"}{"platform"} ? "BriefPlatform" : "BriefUnified"));
49 print My::Project->platforms(undef(),"novskip"=>1) if $W->{"args"}{"platform"};
50
51 my %item=( My::Project::item_hash_read() );
52
53 # $col{"name"}{"show"}=1
54 # $col{"name"}{"format"}=sub { "<".$_[0].">"; }
55 # $col{"name"}{""}="Project name";
56 # @col_order
57
58 my @row_order=qw(-priority);
59 my @col_order=qw(name summary license maintenance language);
60 my %col;
61
62 sub format_url ($) { return (!$_[0] ? "" : '<a href="'.$_[0].'">X</a>'); }
63
64 $col{"name"}{"format"}=sub {
65                 $_[0]=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
66                 return "<a href=\"".$_[1]."/\">"
67                                 .(!$My::Web::W->{"args"}{"W"} ? "" : $item{$_[1]}{"priority"}.":")
68                                 .$_[0]."</a>";
69                 };
70
71 $col{"license"}{"format"}=sub {
72                 my %known=(
73                                 "PD"=>"<a href=\"http://www.gnu.org/philosophy/categories.html#PublicDomainSoftware\">PD</a>",
74                                 "GPL"=>"<a href=\"http://www.gnu.org/licenses/gpl.html\">GPL</a>",
75                                 "LGPL"=>"<a href=\"http://www.gnu.org/licenses/lgpl.html\">LGPL</a>",
76                                 );
77                 return $known{$_[0]} if $known{$_[0]};
78                 return $_[0];
79                 };
80
81 $col{"maintenance"}{"format"}=sub {
82                 return ($_[0]=~/^([^-]*)/)[0];
83                 };
84
85 $col{"online-demo"}{"format"}=\&format_url;
86 $col{"download"}{"format"}=\&format_url;
87 $col{"name"}{""}="Project Name";
88 $col{"summary"}{""}="Abstract";
89 $col{"license"}{""}="Copying";
90 $col{"maintenance"}{""}="State";
91 $col{"language"}{""}="Language";
92
93 # Fill in cols not contained in @col_order
94 if (0) {
95         my %col_order=map(($_=>1),@col_order);
96         push @col_order,map({ ($col_order{$_} ? () : $_); } keys(%{{ map(($_=>1),map((keys(%{$item{$_}})),keys(%item)))}}));
97         }
98
99 my $print_one_platform=sub ($)
100 {
101 my($platform)=@_;
102
103         print '<table border="1">'."\n";
104                 print '<tr>';
105                         for my $col (@col_order) {
106                                 next if defined $col{$col}{"show"} && !$col{$col}{"show"};
107                                 print '<th>'.($col{$col}{""} || "[$col]").'</th>';
108                                 }
109                 print '</tr>'."\n";
110                 my @rows_ordered=sort {
111                                 for my $order_by (@row_order,"name") {
112                                         my $order_by=$order_by;
113                                         my $minus=($order_by=~s/^(-)//)[0];
114                                         # FIXME: 'cmp' or '<=>'?
115                                         my $r=($item{$a}{$order_by} <=> $item{$b}{$order_by});
116                                         $r=-$r if $minus;
117                                         return $r if $r;
118                                         }
119                                 return 0;
120                                 } map(($platform && $item{$_}{"platform"} ne $platform ? () : ($_)),keys(%item));
121                 for my $row (@rows_ordered) {
122                         print '<tr>';
123                         for my $col (@col_order) {
124                                 next if defined $col{$col}{"show"} && !$col{$col}{"show"};
125                                 print '<td>';
126                                 if (!$col{$col}{"format"}) {
127                                         print(($item{$row}{$col} || ""));
128                                         }
129                                 else {
130                                         print(&{$col{$col}{"format"}}($item{$row}{$col},$row));
131                                         }
132                                 print '</td>';
133                                 }
134                         print '</tr>'."\n";
135                         if ($CGI->param("description_opt")) {
136                                 print '<tr><td style="border: none;"></td>';
137                                 print '<td colspan="'.(scalar(@col_order)-1).'"><blockquote>'.$item{$row}{"description"}.'</blockquote></td>';
138                                 print '</tr>'."\n";
139                                 print '<tr><td style="border: none;" colspan="'.scalar(@col_order).'">&nbsp;</td></tr>'."\n";
140                                 }
141                         }
142         print '</table>'."\n";
143 };
144
145
146 if (!$W->{"args"}{"platform"}) {
147         &{$print_one_platform}(undef());
148         }
149 else {
150         my @platforms=@My::Project::platforms;
151         while (@platforms) {
152                 my $platform_sym =shift @platforms;
153                 my $platform_name=shift @platforms;
154                 print '<a name="'.$platform_sym.'">';
155                 print "<h2>$platform_name</h2>";
156                 print '</a>'."\n";
157                 &{$print_one_platform}($platform_sym);
158                 }
159         }
160
161
162 My::Web->footer();