Skip Menu |

This queue is for tickets about the Petal CPAN distribution.

Report information
The Basics
Id: 57812
Status: new
Priority: 0/
Queue: Petal

People
Owner: Nobody in particular
Requestors: adam_lounds [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.19
Fixed in: (no value)



Petal does not allow variable expansion when choosing a metal template. eg: <strong metal:use-macro="${message}">##MESSAGE##</strong> does not work. This is an easy way to insert arbitrary fragments from a metal macro file into a template. Patch attached. usage: <span tal:define="message string:ErrorIncludes/${language}.xhtml#${message}" /> <strong metal:use-macro="${message}">##MESSAGE##</strong>
Subject: Petal-macros.patch
diff -rupN Petal-2.19.orig/lib/Petal/CodeGenerator.pm Petal-2.19/lib/Petal/CodeGenerator.pm --- Petal-2.19.orig/lib/Petal/CodeGenerator.pm 2005-12-05 15:15:57.000000000 +0000 +++ Petal-2.19/lib/Petal/CodeGenerator.pm 2010-05-25 09:26:59.000000000 +0100 @@ -233,15 +233,25 @@ sub _include my $included_from = $petal_object->_file(); $included_from =~ s/\#.*$//; + # allow ${dat/var} expansion in includes + if($path=~ /\$\{(.*)\}/ ) { + my $expanded = $class->comp_expr_encoded ($1); + $path =~ s/\$\{$1\}/' .$expanded . '/; + $path = "'$path'"; + } else { + $path = "'$path'"; + } + $class->add_code ("do {"); $class->indent_increment(); $class->add_code ("my \$new_hash = \$hash->new();"); $class->add_code ("\$new_hash->{__included_from__} = '$included_from';"); + $class->add_code ("my \$path = $path;"); (defined $lang and $lang) ? - $class->add_code ("my \$res = eval { Petal->new (file => '$path', lang => '$lang')->process (\$new_hash) };") : - $class->add_code ("my \$res = eval { Petal->new ('$path')->process (\$new_hash) };"); + $class->add_code ("my \$res = eval { Petal->new (file => \$path, lang => '$lang')->process (\$new_hash) };") : + $class->add_code ("my \$res = eval { Petal->new (\$path)->process (\$new_hash) };"); $class->add_code ("\$res = \"<!--\\n\$\@\\n-->\" if (defined \$\@ and \$\@);"); $class->add_code ("\$res;");
From: adam_lounds [...] hotmail.com
Show quoted text
> usage: > <span tal:define="message > string:ErrorIncludes/${language}.xhtml#${message}" /> > <strong metal:use-macro="${message}">##MESSAGE##</strong>
Sorry, try that example again... <span tal:define="frag" string:ErrorIncludes/${language}.xhtml#${msgcode}" /> <strong metal:use-macro="${frag}">##ERROR_MESSAGE##</strong>