[interchange-cvs] interchange - jon modified lib/Vend/Interpolate.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Mon Jul 22 14:19:02 2002


User:      jon
Date:      2002-07-22 18:18:25 GMT
Modified:  lib/Vend Interpolate.pm
Log:
Add 'First' and 'Last' links to more-list, from Mark Johnson.
Can be customized with [first-anchor] and [last-anchor].

Revision  Changes    Path
2.88      +35 -4     interchange/lib/Vend/Interpolate.pm


rev 2.88, prev_rev 2.87
Index: Interpolate.pm
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.87
retrieving revision 2.88
diff -u -u -r2.87 -r2.88
--- Interpolate.pm	22 Jul 2002 17:44:41 -0000	2.87
+++ Interpolate.pm	22 Jul 2002 18:18:24 -0000	2.88
@@ -1,6 +1,6 @@
 # Vend::Interpolate - Interpret Interchange tags
 #=20
-# $Id: Interpolate.pm,v 2.87 2002/07/22 17:44:41 jon Exp $
+# $Id: Interpolate.pm,v 2.88 2002/07/22 18:18:24 jon Exp $
 #
 # Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
 #
@@ -27,7 +27,7 @@
 require Exporter;
 @ISA =3D qw(Exporter);
=20
-$VERSION =3D substr(q$Revision: 2.87 $, 10);
+$VERSION =3D substr(q$Revision: 2.88 $, 10);
=20
 @EXPORT =3D qw (
=20
@@ -3610,6 +3610,7 @@
 		and $q->{mv_matchlimit} > 0;
 	my($arg,$inc,$last,$m);
 	my($adder,$pages);
+	my($first_anchor,$last_anchor);
 	my $next_tag =3D '';
 	my $list =3D '';
 	$session =3D $q->{mv_cache_key};
@@ -3656,6 +3657,22 @@
=20
 	if($first) {
 		$first =3D 0 if $first < 0;
+
+		# First link may appear when prev link is valid
+		if($r =3D~ s:\[first[-_]anchor\]($All)\[/first[-_]anchor\]::i) {
+			$first_anchor =3D $1;
+		}
+		else {
+			$first_anchor =3D ::errmsg('First');
+		}
+		unless ($first_anchor eq 'none') {
+			$arg =3D $session;
+			$arg .=3D ':0:';
+			$arg .=3D $chunk - 1;
+			$arg .=3D ":$chunk";
+			$list .=3D more_link_template($first_anchor, $arg, $form_arg) . ' ';
+		}
+
 		unless ($prev_anchor) {
 			if($r =3D~ s:\[prev[-_]anchor\]($All)\[/prev[-_]anchor\]::i) {
 				$prev_anchor =3D $1;
@@ -3676,12 +3693,14 @@
 			$arg .=3D ":$chunk";
 			$list .=3D more_link_template($prev_anchor, $arg, $form_arg) . ' ';
 		}
+
 	}
 	else {
-		$r =3D~ s:\[prev[-_]anchor\]($All)\[/prev[-_]anchor\]::i;
+		$r =3D~ s:\[(prev|first)[-_]anchor\]$All\[/\1[-_]anchor\]::ig;
 	}
=20=09
 	if($next) {
+
 		unless ($next_anchor) {
 			if($r =3D~ s:\[next[-_]anchor\]($All)\[/next[-_]anchor\]::i) {
 				$next_anchor =3D $1;
@@ -3697,9 +3716,21 @@
 		$last =3D $last > ($total - 1) ? $total - 1 : $last;
 		$arg =3D "$session:$next:$last:$chunk";
 		$next_tag .=3D more_link_template($next_anchor, $arg, $form_arg);
+
+ 		# Last link can appear when next link is valid
+		if($r =3D~ s:\[last[-_]anchor\]($All)\[/last[-_]anchor\]::i) {
+			$last_anchor =3D $1;
+		}
+		else {
+			$last_anchor =3D ::errmsg('Last');
+		}
+ 		$last =3D $total - 1;
+ 		my $last_beg_idx =3D $total - ($total % $chunk || $chunk);
+ 		$arg =3D "$session:$last_beg_idx:$last:$chunk";
+ 		$next_tag .=3D ' ' . more_link_template($last_anchor, $arg, $form_arg);
 	}
 	else {
-		$r =3D~ s:\[next[-_]anchor\]($All)\[/next[-_]anchor\]::i;
+		$r =3D~ s:\[(last|next)[-_]anchor\]$All\[/\1[-_]anchor\]::i;
 	}
=20=09
 	unless ($page_anchor) {