[Petal] bug: documentation uses unsupported (but TAL spec) modifier
Jonathan
petal-list at 2xlp.com
Fri Jan 20 21:20:04 GMT 2006
I noticed this today in the petal documentation:
=======
omit-tag
Abstract
<tag tal:omit-tag="EXPRESSION">Some contents</tag>
Example
<b tal:omit-tag="not:bold">I may not be bold.</b>
If not:bold is evaluated as TRUE, then the <b> tag will be omited. If
not:bold is evaluated as FALSE, then the <b> tag will stay in place.
Why?
omit-tag statements can be used to leave the contents of a tag in
place while omitting the surrounding start and end tags if the
expression which is evaluated is TRUE.
TIP:
If you want to ALWAYS remove a tag, you can use omit-tag="string:1"
=======
i've discussed this before, but "not:" is a TAL modifier that isn't
in petal
i just wanted to bring this up again, as following the docs in this
case will cause an error
i suggest either:
* patching petal to use not: which is in the TAL spec (patch below)
* including the Petal Modifier on the TAL doc, so that will work and
others in the future will see it
* changing the docs from not to false
in that order of preference
Petal Modifier method:
=====
use Petal ();
$Petal::Hash::MODIFIERS->{'not:'} = sub { return ( $_[0]->fetch($_
[1]) ? 0 : 1 ); };
=====
Patch
=====
diff -Naur Petal-2.18-dist/lib/Petal/Hash.pm Petal-2.18-patched/lib/
Petal/Hash.pm
--- Petal-2.18-dist/lib/Petal/Hash.pm 2005-03-16 10:23:36.000000000
-0500
+++ Petal-2.18-patched/lib/Petal/Hash.pm 2006-01-20
16:08:20.000000000 -0500
@@ -71,6 +71,14 @@
};
+# not modifier
+$MODIFIERS->{'not:'} = sub {
+ my $hash = shift;
+ my $variable = join ' ', @_;
+ return not $hash->fetch ("true:$variable");
+};
+
+
# encode: modifier (deprecated stuff)
$MODIFIERS->{'encode:'} = sub {
warn "Petal modifier encode: is deprecated";
=====
Sorry, but I don't know the correct way to generate a diff for patching.
it's just adding this
====
# not modifier
$MODIFIERS->{'not:'} = sub {
my $hash = shift;
my $variable = join ' ', @_;
return not $hash->fetch ("true:$variable");
};
=====
to lib/Petal/Hash.pm - its an exact copy of the false function, just
s/false/not/g , and right below it. there's probably a better way to
consolidate not: and false: into 1 modifier, but that works.
More information about the Petal
mailing list