2 # Common functions for HTML/XHTML output generation
3 # Copyright (C) 2003 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
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
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.
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
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; };
30 our @ISA=qw(My::Web Exporter);
35 my($class,$ListItem)=@_;
37 print "<h1>".$ListItem->{"name"}."</h1>\n";
38 print $ListItem->{"description"};
41 {"key"=>qr(^download\b),"text"=>sub ($) {
44 return "Download".$_[0];
48 if ($_[0]=~m#^[a-z]+://#) {
49 $r=a_href($_[0],CGI::escapeHTML($_[0]));
52 $r=a_href($_[0],CGI::escapeHTML(File::Basename::basename($_[0])));
53 my $size=(stat $_[0])[7];
54 die "Cannot stat \"".$_[0]."\": $!" if !defined $size;
55 if ($size>=1024*1024) { $size=int($size/(1024*1024))." MB"; }
56 elsif ($size>=1024 ) { $size=int($size/(1024 ))." KB"; }
57 else { $size=int($size )." B"; }
62 {"key"=>qr(^link\b),"text"=>sub ($) {
67 return a_href($_[0],CGI::escapeHTML($_[0]));
69 {"key"=>qr(^cvs\b),"text"=>sub ($) {
79 $branch=$1 if $val=~s/:(.*)//;
80 return join("<br />\n\t\t",
81 CGI::escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
82 ." checkout".(!$branch ? "" : " -r $branch -kk")
83 .($val!~m#/# ? "" : " -d ".File::Basename::basename($val))
85 map({ a_href($_->[1],$_->[0]); }
86 ["ViewCVS CVS repository",$W->{"project_viewcvs"}.$val."/".(!$branch ? "" : '?only_with_tag='.$branch)],
87 ["Download CVS snapshot" ,
88 $W->{"project_viewcvs"}.$val."/".File::Basename::basename($val).".tar.gz?tarball=1"
89 .(!$branch ? "" : '&only_with_tag='.$branch)],
90 ["CVS ChangeLog" ,$W->{"top_dir"}."/project/ChangeLog.txt.pl?cvs=$val"]));
92 {"key"=>"summary","text"=>"Summary"},
93 {"key"=>"ownership","text"=>"Ownership"},
94 {"key"=>"license","text"=>"License","format"=>sub ($) {
96 "PD"=>"Public Domain",
97 "GPL"=>a_href("http://www.gnu.org/licenses/gpl.html","GNU General Public License"),
98 "LGPL"=>a_href("http://www.gnu.org/licenses/lgpl.html","GNU Lesser General Public License"),
101 return $known{$_[0]};
103 {"key"=>"maintenance","text"=>"State","format"=>sub ($) {
105 "active"=>"Ready to use and the package is being actively developed.",
106 "ready"=>"Ready to use although no longer being actively developed.",
107 "dead"=>"Dead code, no longer supported.",
108 "merge"=>"Functions belong to existing other project.",
109 "obsolete"=>"Obsoleted.",
110 "update"=>"Package needs updating to recent software.",
111 "accepted"=>"This patch got already integrated by the original package maintainer.",
115 for ($known{($_[0]=~/^([^-]*)-?/)[0] || ""}) {
121 {"key"=>"sponsorship","text"=>"Sponsoring Company"},
122 {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
123 return a_href("http://java.sun.com/",CGI::escapeHTML($_[0]))
125 return a_href("http://www.php.net/",CGI::escapeHTML($_[0]))
133 my($tableit,$val,$key,$ListItem)=@_;
135 delete $ListItem->{$key};
138 if ($tableit->{"text"}) {
140 $r.=(!ref $_ ? $_ : &{$_}($key)) for ($tableit->{"text"});
143 if ($tableit->{"format"}) {
144 do { $val=$_ if defined $_; } for (&{$tableit->{"format"}}($val,$key));
146 return join("",map("<tr><td>".$_->[0]."</td><td>".$_->[1]."</td></tr>\n",@$val))
152 print '<table border="0" class="print_project">'."\n";
153 for my $tableit (@table) {
154 if (!ref $tableit->{"key"}) {
155 print tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem)
156 if $ListItem->{$tableit->{"key"}};
159 for my $key (@{$ListItem->{"keys_array"}}) {
160 my $keyregex=$tableit->{"key"};
161 next if $key!~/$keyregex/;
162 print tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
170 sub project_arr_to_hash (@)
176 "keys_array"=>[ My::Web::arr_keys(@arr) ],
180 # $args{"ListItem"}=\%...;
181 sub init_project ($%)
185 my $ListItem={ project_arr_to_hash(@{$args{"ListItem"}}) };
186 my $name=$ListItem->{"name"};
187 $name=~s#<a\s[^>]*>([^<]*)</a>#$1#g;
191 "head_css"=>($args{"head_css"} || "")."
192 table.print_project td { vertical-align: top; }
196 $class->print_project({ %$ListItem });