[interchange-cvs] interchange - ton modified lib/Vend/Interpolate.pm
interchange-core@icdevgroup.org
interchange-core@icdevgroup.org
Mon May 26 14:51:01 2003
User: ton
Date: 2003-05-26 18:50:08 GMT
Modified: lib/Vend Interpolate.pm
Log:
Added new filter: words
This filter returns the maximum desired number of words.
Usage:
words10 Returns the first 10 words or the
complete string
words15. Returns the first 15 words appended with
three dots if the original string is
longer than the desired number of words.
Revision Changes Path
2.172 +10 -2 interchange/lib/Vend/Interpolate.pm
rev 2.172, prev_rev 2.171
Index: Interpolate.pm
===================================================================
RCS file: /var/cvs/interchange/lib/Vend/Interpolate.pm,v
retrieving revision 2.171
retrieving revision 2.172
diff -u -r2.171 -r2.172
--- Interpolate.pm 22 May 2003 21:17:02 -0000 2.171
+++ Interpolate.pm 26 May 2003 18:50:07 -0000 2.172
@@ -1,6 +1,6 @@
# Vend::Interpolate - Interpret Interchange tags
#
-# $Id: Interpolate.pm,v 2.171 2003/05/22 21:17:02 racke Exp $
+# $Id: Interpolate.pm,v 2.172 2003/05/26 18:50:07 ton 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.171 $, 10);
+$VERSION = substr(q$Revision: 2.172 $, 10);
@EXPORT = qw (
@@ -619,6 +619,14 @@
substr($value , $_) = ''
if length($value) > $_;
next;
+ }
+ if ( /^words(\d+)(\.?)$/ ) {
+ my @str = (split /\s+/, $value);
+ if (scalar @str > $1) {
+ my $num = $1;
+ $value = join(' ', @str[0..--$num]);
+ $value .= $2 ? '...' : '';
+ }
}
unless (defined $Filter{$_}) {
logError ("Unknown filter '%s'", $_);