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; };
27 use Carp qw(cluck confess);
31 our @ISA=qw(My::Web Exporter);
36 # Do not: path_abs_disk("/project/SUBDIRS");
37 # as we would need $W->{"r"} for the possibly relative path resolving.
38 return My::Web::dir_top_abs_disk()."/project/SUBDIRS";
44 my($class,$ListItem)=@_;
46 print "<h1>".$class->title($ListItem)."</h1>\n";
47 do { print $_ if $_; } for ($W->{"project_text_after_title"});
48 print $ListItem->{"description"};
50 print($W->{"before_project_data"}||"");
51 return if $W->{"no_project_data"};
53 {"key"=>"summary","text"=>"Summary"},
54 {"key"=>"license","text"=>"License","format"=>sub ($) {
56 "PD"=>"Public Domain",
57 "GPL"=>a_href("http://www.gnu.org/licenses/gpl.html","GNU General Public License"),
58 "LGPL"=>a_href("http://www.gnu.org/licenses/lgpl.html","GNU Lesser General Public License"),
63 {"key"=>"maintenance","text"=>"State","format"=>sub ($) {
65 "active"=>"Ready to use. Project is now actively developed.",
66 "ready"=>"Ready to use. Maintained.",
67 "dead"=>"Dead code, no longer supported.",
68 "merge"=>"Functions belong to existing other project.",
69 "obsolete"=>"Obsoleted.",
70 "update"=>"Package needs updating to recent software.",
71 "accepted"=>"This patch got already integrated by the original package maintainer.",
72 "pending"=>"Patch is ready to be applied to the mainstream.",
73 "ignored"=>"Patch was ignored. It is not applied in the mainstream.",
77 for ($known{($_[0]=~/^([^-]*)-?/)[0] || ""}) {
83 {"key"=>"aminet","text"=>a_href('http://www.aminet.net/','Aminet'),"format"=>sub ($) {
85 a_href('http://www.aminet.net/'.$_[0].".lha",$_[0].".lha"),
86 "(".a_href('http://www.aminet.net/'.$_[0].".readme","readme").")");
88 {"key"=>qr(^download\b),"text"=>sub ($) {
91 return "Download".$_[0];
94 return a_href($_[0],escapeHTML(File::Basename::basename($_[0])),"size"=>2);
96 {"key"=>qr(^link\b),"text"=>sub ($) {
101 return($_[0]=~/^<a\b/ ? $_[0] : a_href($_[0],escapeHTML($_[0])));
103 {"key"=>qr(^cvs\b),"text"=>sub ($) {
113 $branch=$1 if $val=~s/:(.*)//;
114 return join("<br />\n\t\t",
115 escapeHTML("cvs -d ".$W->{"pserver"}.":".$W->{"pserver_path"}." -z3"
116 ." checkout".(!$branch ? "" : " -r $branch -kk")
117 .($val!~m#/# ? "" : " -d ".File::Basename::basename($val))
120 map({ a_href($_->[1],$_->[0]); }
121 ["ViewCVS CVS repository",$W->{"project_viewcvs"}.$val."/".(!$branch ? "" : '?only_with_tag='.$branch)],
122 ["Download CVS snapshot" ,
123 $W->{"project_viewcvs"}.$val."/".File::Basename::basename($val).".tar.gz?tarball=1"
124 .(!$branch ? "" : '&only_with_tag='.$branch)],
125 ["CVS ChangeLog" ,"/project/ChangeLog.pm?cvs=$val"])));
127 {"key"=>"ownership","text"=>"Ownership"},
128 {"key"=>"sponsorship","text"=>"Sponsorship"},
129 {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
130 return a_href("http://java.sun.com/",escapeHTML($_[0]))
132 return a_href("http://www.php.net/",escapeHTML($_[0]))
140 my($tableit,$val,$key,$ListItem)=@_;
144 if ($tableit->{"text"}) {
146 $r.=(!ref $_ ? $_ : &{$_}($key)) for ($tableit->{"text"});
149 if ($tableit->{"format"}) {
150 do { $val=$_ if defined $_; } for (&{$tableit->{"format"}}($val,$key));
152 return join("",map("<tr><td>".$_->[0]."</td><td>".$_->[1]."</td></tr>\n",@$val))
159 print '<table border="0" class="print_project">'."\n";
160 for my $tableit (@table) {
161 if (!ref $tableit->{"key"}) {
162 print tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem)
163 if $ListItem->{$tableit->{"key"}} && !$used_key{$tableit->{"key"}}++;
166 for my $key (@{$ListItem->{"keys_array"}}) {
167 my $keyregex=$tableit->{"key"};
168 next if $key!~/$keyregex/;
169 print tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
177 sub hashlikearray_get_keys(@)
179 my(@hashlikearray)=@_;
182 while (@hashlikearray) {
183 push @r,shift @hashlikearray; # key
184 shift @hashlikearray; # val
189 sub project_arrayref_to_hashref($$)
191 my($self,$arrayref)=@_;
194 return My::Hash->new({
196 "keys_array"=>[ hashlikearray_get_keys(@$arrayref) ],
197 },"My::Hash::Sub","My::Hash::Readonly");
202 my($class,$hashref)=@_;
204 cluck if !$hashref->{"name"} || !$hashref->{"summary"};
205 return $hashref->{"name"}.": ".$hashref->{"summary"},
208 # Returns: hashref if !wantarray(), list if wantarray().
213 # This cache is "headers_in" hits safe - only local files reading.
217 My::Web->make_file(LIST_FILENAME());
219 open F,LIST_FILENAME() or do {
220 cluck "Error opening \"".LIST_FILENAME()."\": $!";
223 my @r=split(" ",do { undef $/; <F>; });
224 close F or cluck "Error closing \"".LIST_FILENAME()."\": $!";
225 cluck "No projects found?" if !@r;
227 %list_cache=map(($_=>1),@list_cache);
229 return \%list_cache if !wantarray();
233 # Returns: hashlist of hashrefs if !$name.
234 sub name_to_hashref($;$)
238 cluck if !wantarray() && !$name;
239 # Do not cache the result to get all the items &Wrequire-mapped.
240 return map(($_=>$class->name_to_hashref($_)),$class->list()) if !$name;
241 cluck join(" ","Project name \"$name\" not listed in 'list_cache':",$class->list())
242 if !$class->list()->{$name};
243 # Never cache anything to be stable for "headers_in" hits.
244 Wrequire "project::${name}::Index";
245 my $arrayref=eval('\@project::'.$name.'::Index::ListItem');
246 do { warn "Broken project/$name/Index.pm"; return undef(); } if !@$arrayref;
247 return $class->project_arrayref_to_hashref($arrayref);
250 # $args{"ListItem"}=\%...;
255 $args{"__PACKAGE__"}||=caller();
256 $args{"project_name"}||=($args{"__PACKAGE__"}=~/^project::(\w+)::Index$/)[0]
257 or cluck "Error finding project name of the package: ".$args{"__PACKAGE__"};
258 my $ListItem=$class->name_to_hashref($args{"project_name"});
259 my $W=$class->SUPER::init(
260 "title"=>My::Web->a_href_inhibit(sub { return $class->title($ListItem); }),
261 map(("rel_$_"=>'/project/Rel.pm?rel='.$_.'&project='.$args{"project_name"}),qw(prev next)),
262 "rel_up"=>'/project/',
263 # "rel_start"=>"/", # TODO:homepage
264 "css_push"=>"/project/Lib.css",
266 "heading_novskip"=>1,
269 print $class->platforms($ListItem->{"platform"});
270 $class->print_project($ListItem,%args);
276 "unixdevel"=>"UNIX-devel",
286 my($class,$view_selected)=@_;
290 my($current,$href,$content)=@_;
292 return a_href($href,$content) if $current ne $view_selected;
293 return "<b>".$content."</b> (current)";
297 <h1>Project List of @{[ a_href 'http://www.jankratochvil.net/','Jan Kratochvil' ]}</h1>
300 <li>@{[ &{$view}('Detailed' ,'/project/','Detailed project listing per platform') ]}</li>
301 <li>@{[ &{$view}('BriefPlatform','/project/List.pm?platform=platform',
302 'Brief project listing per platform') ]}</li>
303 <li>@{[ &{$view}('BriefUnified' ,'/project/List.pm',
304 'Unified brief project listing') ]}</li>
312 my($class,$platform_selected,%args)=@_;
315 $r.='<table border="0" class="margin-center"><tr>'."\n";
317 $r.='<table border="1" style="border-collapse: collapse; border-style: solid; border-width: 1px;">'."\n";
319 $r.='<td style="padding: 5px; font-weight: bold;">'."\n";
326 $r.='<table border="1" style="border-collapse: collapse; border-style: solid;">'."\n";
328 my @platforms=@platforms;
330 my $platform_sym =shift @platforms;
331 my $platform_name=shift @platforms;
332 my $chosen=($platform_selected && $platform_selected eq $platform_sym);
333 $r.='<td style="padding: 5px;">';
334 $r.=a_href((!$platform_selected ? "" : "/project/").'#'.$platform_sym,$platform_name,
336 ? 'style="text-decoration: underline; font-weight: bold;"'
337 : 'style="text-decoration: inherit; /* revoke underline */"'));
343 $r.='</tr></table>'."\n";
344 if (!$args{"novskip"}) {
346 $r.=My::Web::vskip "6ex";
355 my $item=$class->name_to_hashref($name);
356 my $title=$class->title($item);
359 print $class->platforms($item->{"platform"},"novskip"=>1);
361 $r.='<table border="1" style="border-collapse: collapse; border-style: solid;" class="margin-center">'."\n";
362 $r.='<tr><td style="font-size: larger;">'."\n";
363 $r.=a_href "/project/$name/",$title;
364 $r.='</td></tr>'."\n";