# $Id$ # Common functions for HTML/XHTML output generation # Copyright (C) 2003 Jan Kratochvil # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; exactly version 2 of June 1991 is required # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA package product::Lib; require 5.6.0; # at least 'use warnings;' but we need some 5.6.0+ modules anyway our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; }; our $CVS_ID=q$Id$; use strict; use warnings; use My::Web; use Carp qw(cluck confess); use Exporter; our @EXPORT=qw(); Wrequire 'Lib'; our @ISA=qw(My::Web Lib Exporter); my $LIST_ABSPATH="/product/SUBDIRS"; # Returns: hashref if !wantarray(), list if wantarray(). sub list($) { my($self)=@_; return $self->list_abspath($LIST_ABSPATH); } sub products_sorted($) { my($self)=@_; my %item=$self->name_to_hashref(); return sort { ($item{$b}{"priority"} <=> $item{$a}{"priority"}) or (lc($item{$a}{"name"}) cmp lc($item{$b}{"name"})); } keys(%item); } # $args{"is_index"}=1; sub products($;$%) { my($class,$product_selected,%args)=@_; my $r=""; $r.=''."\n"; $r.=''; $r.=''."\n"; $r.='
'; $r.=''."\n"; $r.=''."\n"; $r.=''."\n"; $r.=''."\n"; $r.='
'."\n"; $r.='Products'; $r.='
'; $r.='
'; $r.=''."\n"; $r.=''."\n"; my %item=$class->name_to_hashref(); for my $product_found ($class->products_sorted()) { my $chosen=($product_selected && $product_selected eq $product_found); $r.='\n"; } $r.=''."\n"; $r.='
'; $r.=($chosen && $args{"is_index"} ? "".$item{$product_found}{"name"}."" : a_href "/product/$product_found/",$item{$product_found}{"name"}, "attr"=>($chosen ? 'style="text-decoration: underline; font-weight: bold;"' : 'style="text-decoration: inherit; /* revoke underline */"')); $r.="
'."\n"; $r.='
'."\n"; # Products menu DISABLED: $r=""; if (!$args{"novskip"}) { Wrequire 'WebConfig'; $r.=WebConfig->vskip_hr(); } return $r; } sub init($%) { my($class,%args)=@_; $args{"__PACKAGE__"}||=caller(); $args{"product_name"}||=($args{"__PACKAGE__"}=~/^product::(\w+)::/)[0] or cluck "Error finding product name of the package: ".$args{"__PACKAGE__"}; my $ListItem=$class->name_to_hashref($args{"product_name"}); my $W=$class->SUPER::init( "title"=>My::Web->a_href_inhibit(sub { return $class->title($ListItem); }), "footer_ids"=>0, "no_job"=>1, "rel_up"=>'/product/', # "rel_start"=>"/", # TODO:homepage "css_push"=>"/product/Lib.css", %args, "heading_novskip"=>1, ); $class->heading(); my $is_index=($args{"__PACKAGE__"}=~/^product::\w+::Index$/); print $class->products($args{"product_name"}, "is_index"=>$is_index, %args, ); return $W; } 1;