[interchange-cvs] interchange - heins modified lib/Vend/Interpolate.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Sat Nov 9 01:03:01 2002
User: heins
Date: 2002-11-09 06:02:03 GMT
Modified: lib/Vend Interpolate.pm
Log:
* Fix bugs in option_format filter. It would turn commas into new options;
and alternate delimiters had no hope of working.
* Add options2line and line2options filters, allowing you to specify
options in a textarea without comma separators and instead with one
option per line.
Revision Changes Path
2.128 +34 -5 interchange/lib/Vend/Interpolate.pm
rev 2.128, prev_rev 2.127
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.127
retrieving revision 2.128
diff -u -r2.127 -r2.128
--- Interpolate.pm 8 Nov 2002 21:48:18 -0000 2.127
+++ Interpolate.pm 9 Nov 2002 06:02:03 -0000 2.128
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.127 2002/11/08 21:48:18 kwalsh Exp $
+# $Id: Interpolate.pm,v 2.128 2002/11/09 06:02:03 mheins Exp $
#
# Copyright (C) 1996-2002 Red Hat, Inc. <interchange@redhat.com>
#
@@ -27,7 +27,7 @@
require Exporter;
@ISA = qw(Exporter);
-$VERSION = substr(q$Revision: 2.127 $, 10);
+$VERSION = substr(q$Revision: 2.128 $, 10);
@EXPORT = qw (
@@ -965,22 +965,50 @@
}
return '';
},
+ 'line2options' => sub {
+ my ($value, $tag, $delim) = @_;
+ return $value unless length $value;
+ $value =~ s/\s+$//;
+ $value =~ s/^\s+//;
+ my @opts = split /[\r\n]+/, $value;
+ for(@opts) {
+ s/^\s+//g;
+ s/\s+$//g;
+ s/,/,/g;
+ }
+ return join ",", @opts;
+ },
+ 'options2line' => sub {
+ my ($value, $tag, $delim) = @_;
+ return $value unless length $value;
+ $value =~ s/\s+$//;
+ $value =~ s/^\s+//;
+ my @opts = split /\s*,\s*/, $value;
+ for(@opts) {
+ s/,/,/g;
+ }
+ $value = return join "\n", @opts;
+ return $value;
+ },
'option_format' => sub {
my ($value, $tag, $delim) = @_;
return $value unless $value =~ /\0.*\0/s;
+ my $scrubcommas;
if(! length($delim) ) {
$delim = ',';
+ $scrubcommas = 1;
}
else {
$delim =~ /pipe/i and $delim = '|'
or
- $delim =~ ';' and $delim =~ /semicolon/i
+ $delim =~ /semicolon/i and $delim = ';'
or
- $delim =~ ':' and $delim =~ /colon/i
+ $delim =~ /colon/i and $delim = ':'
or
- $delim =~ ':' and $delim =~ /null/i;
+ $delim =~ /null/i and $delim = "\0"
+ ;
}
my @opts = split /\0/, $value;
@@ -989,6 +1017,7 @@
while(@opts) {
my ($v, $l, $d) = splice @opts, 0, 3;
$l = length($l) ? "=$l" : '';
+ $l =~ s/,/,/g if $scrubcommas;
$d = $d ? '*' : '';
next unless length("$v$l");
push @out, "$v$l$d";