Fixed Id tracking.
[MyWeb.git] / Project.pm
1 # $Id$
2 # Common functions for HTML/XHTML output generation
3 # Copyright (C) 2003 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; exactly version 2 of June 1991 is required
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19 package My::Project;
20 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
21 our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
22 our $CVS_ID=q$Id$;
23 use strict;
24 use warnings;
25
26 use My::Web;
27
28 use Exporter;
29 our @EXPORT=qw();
30 our @ISA=qw(My::Web Exporter);
31
32
33 sub print_project ($)
34 {
35 my($class,$ListItem)=@_;
36
37         print "<h1>".$ListItem->{"name"}."</h1>\n";
38         print $ListItem->{"description"};
39         print "<hr />\n";
40         my @table=(
41                 {"key"=>"summary","text"=>"Summary"},
42                 {"key"=>"license","text"=>"License","format"=>sub ($) {
43                                 my %known=(
44                                                 "PD"=>"Public Domain",
45                                                 "GPL"=>a_href("http://www.gnu.org/licenses/gpl.html","GNU General Public License"),
46                                                 "LGPL"=>a_href("http://www.gnu.org/licenses/lgpl.html","GNU Lesser General Public License"),
47                                                 "com"=>"Commercial"
48                                                 );
49                                 return $known{$_[0]};
50                                 }},
51                 {"key"=>"maintenance","text"=>"State","format"=>sub ($) {
52                                 my %known=(
53                                                 "active"=>"Ready to use. Project is now actively developed.",
54                                                 "ready"=>"Ready to use. Maintained.",
55                                                 "dead"=>"Dead code, no longer supported.",
56                                                 "merge"=>"Functions belong to existing other project.",
57                                                 "obsolete"=>"Obsoleted.",
58                                                 "update"=>"Package needs updating to recent software.",
59                                                 "accepted"=>"This patch got already integrated by the original package maintainer.",
60                                                 ""=>"",
61                                                 );
62                                 my @r;
63                                 for ($known{($_[0]=~/^([^-]*)-?/)[0] || ""}) {
64                                         push @r,$_ if $_;
65                                         push @r," $'" if $';
66                                         }
67                                 return join(" ",@r);
68                                 }},
69                 {"key"=>"aminet","text"=>a_href('http://www.aminet.net/','Aminet'),"format"=>sub ($) {
70                                 return join(" ",
71                                                 a_href('http://www.aminet.net/'.$_[0].".lha",$_[0].".lha"),
72                                                 "(".a_href('http://www.aminet.net/'.$_[0].".readme","readme").")");
73                                 }},
74                 {"key"=>qr(^download\b),"text"=>sub ($) {
75                                                 $_[0]=~s/^download//;
76                                                 $_[0]=~s/^-/ /;
77                                                 return "Download".$_[0];
78                                                 },
79                                 "format"=>sub ($) {
80                                                 return a_href($_[0],CGI::escapeHTML(File::Basename::basename($_[0])));
81                                                 }},
82                 {"key"=>qr(^link\b),"text"=>sub ($) {
83                                                 $_[0]=~s/^link-//;
84                                                 return $_[0];
85                                                 },
86                                 "format"=>sub ($) {
87                                                 return a_href($_[0],CGI::escapeHTML($_[0]));
88                                                 }},
89                 {"key"=>qr(^cvs\b),"text"=>sub ($) {
90                                                 $_[0]=~s/^cvs//;
91                                                 $_[0]=~s/^-/ /;
92                                                 return "CVS".$_[0];
93                                                 },
94                                 "format"=>sub ($$) {
95                                                 my($val,$key)=@_;
96                                                 $key=~s/^cvs//;
97                                                 $key=~s/^-/ /;
98                                                 my $branch="";
99                                                 $branch=$1 if $val=~s/:(.*)//;
100                                                 return join("<br />\n\t\t",
101                                                                 CGI::escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
102                                                                                 ." checkout".(!$branch ? "" : " -r $branch -kk")
103                                                                                 .($val!~m#/# ? "" : " -d ".File::Basename::basename($val))
104                                                                                 ." $val"),
105                                                                 join(" | \n\t\t",
106                                                                                 map({ a_href($_->[1],$_->[0]); }
107                                                                                                 ["ViewCVS CVS repository",$W->{"project_viewcvs"}.$val."/".(!$branch ? "" : '?only_with_tag='.$branch)],
108                                                                                                 ["Download CVS snapshot" ,
109                                                                                                                 $W->{"project_viewcvs"}.$val."/".File::Basename::basename($val).".tar.gz?tarball=1"
110                                                                                                                                 .(!$branch ? "" : '&only_with_tag='.$branch)],
111                                                                                                 ["CVS ChangeLog"         ,top_dir()."/project/ChangeLog.txt.pl?cvs=$val"])));
112                                                 }},
113                 {"key"=>"ownership","text"=>"Ownership"},
114                 {"key"=>"sponsorship","text"=>"Sponsorship"},
115                 {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
116                                 return a_href("http://java.sun.com/",CGI::escapeHTML($_[0]))
117                                                 if $_[0]=~/^Java\b/;
118                                 return a_href("http://www.php.net/",CGI::escapeHTML($_[0]))
119                                                 if $_[0]=~/^PHP\b/;
120                                 return undef();
121                                 }},
122                 );
123
124 sub tableit_func
125 {
126 my($tableit,$val,$key,$ListItem)=@_;
127
128         delete $ListItem->{$key};
129         my $r="";
130         $r.="<tr>";
131                 if ($tableit->{"text"}) {
132                         $r.="<td>";
133                                 $r.=(!ref $_ ? $_ : &{$_}($key)) for ($tableit->{"text"});
134                         $r.="</td>";
135                         }
136                 if ($tableit->{"format"}) {
137                         do { $val=$_ if defined $_; } for (&{$tableit->{"format"}}($val,$key));
138                         }
139                 return join("",map("<tr><td>".$_->[0]."</td><td>".$_->[1]."</td></tr>\n",@$val))
140                                 if ref $val;
141                 $r.="<td>$val</td>";
142         $r.="</tr>\n";
143 }
144
145         print '<table border="0" class="print_project">'."\n";
146                 for my $tableit (@table) {
147                         if (!ref $tableit->{"key"}) {
148                                 print tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem)
149                                                 if $ListItem->{$tableit->{"key"}};
150                                 }
151                         else {
152                                 for my $key (@{$ListItem->{"keys_array"}}) {
153                                         my $keyregex=$tableit->{"key"};
154                                         next if $key!~/$keyregex/;
155                                         print tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
156                                         }
157                                 }
158                         }
159         print "</table>\n";
160         print vskip;
161 }
162
163 sub project_arr_to_hash (@)
164 {
165 my(@arr)=@_;
166
167         return (
168                         @arr,
169                         "keys_array"=>[ My::Web::arr_keys(@arr) ],
170                         );
171 }
172
173 # $args{"ListItem"}=\%...;
174 sub init_project ($%)
175 {
176 my($class,%args)=@_;
177
178         my $ListItem={ project_arr_to_hash(@{$args{"ListItem"}}) };
179         my $name=$ListItem->{"name"};
180         $name=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
181         my $W=$class->init(
182                         "title"=>$name,
183                         %args,
184                         "head_css"=>($args{"head_css"} || "")."
185 table.print_project td { vertical-align: top; }
186 ",
187                         );
188         $class->heading();
189         $class->print_project({ %$ListItem });
190         return $W;
191 }
192
193 1;