[interchange-cvs] interchange - heins modified lib/Vend/Menu.pm

interchange-core@icdevgroup.org interchange-core@icdevgroup.org
Wed Aug 14 11:41:00 2002


User:      heins
Date:      2002-08-14 15:40:22 GMT
Modified:  lib/Vend Menu.pm
Log:
* Certain things need to be done in order. For instance, we need
  to localize first, then do entities, and then and only then substitute
    for spaces. Originally this could happen in a random order,
  so if you had

  	[menu
			localize=3Dname
			entities=3Dname
			nbsp=3Dname
			....]

  the results were unpredictable.

* Add indicator_profile transform, which allows indication if a certain
  profile is run and passed. Allows generation of the wizard-style
  menu with checkboxes for completion.

* Add entities transform which insures description and other things
  against breaking HTML.

Revision  Changes    Path
2.8       +41 -3     interchange/lib/Vend/Menu.pm


rev 2.8, prev_rev 2.7
Index: Menu.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/Menu.pm,v
retrieving revision 2.7
retrieving revision 2.8
diff -u -r2.7 -r2.8
--- Menu.pm	12 Aug 2002 17:10:13 -0000	2.7
+++ Menu.pm	14 Aug 2002 15:40:22 -0000	2.8
@@ -1,6 +1,6 @@
 # Vend::Menu - Interchange payment processing routines
 #
-# $Id: Menu.pm,v 2.7 2002/08/12 17:10:13 mheins Exp $
+# $Id: Menu.pm,v 2.8 2002/08/14 15:40:22 mheins Exp $
 #
 # Copyright (C) 2002 Mike Heins, <mike@perusion.net>
 #
@@ -21,7 +21,7 @@
=20
 package Vend::Menu;
=20
-$VERSION =3D substr(q$Revision: 2.7 $, 10);
+$VERSION =3D substr(q$Revision: 2.8 $, 10);
=20
 use Vend::Util;
 use strict;
@@ -35,6 +35,14 @@
 		}
 		return 1;
 	},
+	entities =3D> sub {
+		my ($row, $fields) =3D @_;
+		return 1 if ref($fields) ne 'ARRAY';
+		for(@$fields) {
+			$row->{$_} =3D HTML::Entities::encode_entities($row->{$_});
+		}
+		return 1;
+	},
 	localize =3D> sub {
 		my ($row, $fields) =3D @_;
 		return 1 if ref($fields) ne 'ARRAY';
@@ -134,6 +142,26 @@
 		}
 		return $status;
 	},
+	indicator_profile =3D> sub {
+		my ($row, $fields) =3D @_;
+		return 1 if ref($fields) ne 'ARRAY';
+		for(@$fields) {
+			my ($indicator,$rev, $last, $status);
+			next unless $indicator =3D $row->{$_};
+			$rev =3D $indicator =3D~ s/^\s*!\s*// ? 1 : 0;
+			$last =3D $indicator =3D~ s/\s*!\s*$// ? 1 : 0;
+			$status =3D Vend::Tags->run_profile($indicator);
+			if($rev xor $status) {
+				$row->{indicated} =3D 1;
+				next unless $last;
+			}
+			last if $last;
+			$status =3D $Global::Variable->{MV_PAGE} eq $indicator;
+			($row->{indicated} =3D 1, next)
+				if $rev xor $status;
+		}
+		return 1;
+	},
 	indicator =3D> sub {
 		my ($row, $fields) =3D @_;
 		return 1 if ref($fields) ne 'ARRAY';
@@ -621,7 +649,6 @@
 		}
 		$row->{page} =3D Vend::Tags->area( { href =3D> $row->{page}, form =3D> $=
form });
 	}
-	$row->{description} =3D HTML::Entities::encode_entities($row->{descriptio=
n});
=20
 	my @values =3D @{$row}{@$fields};
=20
@@ -699,7 +726,18 @@
 	}
=20
 	my @transform;
+	my @ordered_transform =3D qw/localize entities nbsp/;
+	my %ordered;
+	@ordered{@ordered_transform} =3D @ordered_transform;
+
 	for(keys %transform) {
+		next if $ordered{$_};
+		next unless $opt->{$_};
+		my @fields =3D grep /\S/, split /[\s,\0]+/, $opt->{$_};
+		$opt->{$_} =3D \@fields;
+		push @transform, $_;
+	}
+	for(@ordered_transform) {
 		next unless $opt->{$_};
 		my @fields =3D grep /\S/, split /[\s,\0]+/, $opt->{$_};
 		$opt->{$_} =3D \@fields;