Jonathan Vanasco | 11 Sep 05:13

Invalid TAL statements

I checked the Petal and Zope docs, but couldn't find any  definitive  
answer:

how SHOULD Petal handle invalid TAL statements

by invalid i mean a 'tal:xxxx' where 'xxxx' is not a valid tal  
statement.

example:
	tal:ttributes

note  that is 'attributes' without the leading 'a'

currently Petal silently ignores these -- is this on purpose?  if  
so,  can that be added to the docs as a feature  set?  if not, can  
that forcefully throw an error?

i'm currently exploiting this 'feature' to stash away variations on  
complex string: modifier actions while i test.  its incredibly  
useful, but I'd rather not upgrade Petal one day and find a  bunch of  
test code on my templates showing.

Jonathan Vanasco | 17 Sep 02:22

condition="true:" superfluous ?

The Petal docs /cookbook are split evenly in use between
	tal:condition="x"
	tal:condition="true: x"

Most notably, the 'condition' docs use 'true:' while the repeat docs  
do not.

And the true:EXPRESSION Petal docs say:
	"the true: modifiers should always be used when doing Petal  
conditions."

that looked odd, so I looked onto the ZPT website for futher  
clarification

According to the Tal 1.4 specs, which are pretty sparse,  
tal:condition implies a 'true:' already -- making including it  
superfluous.  true is supported in all of the implementations as a  
base modifier, but using it is not necessary in condition

based on that, i'd like to suggest the following changes to the Petal  
docs:

	TAL Syntax
		condition (ifs )
			[ ] remove 'true:' from the abstract and example
			[ ] Append to this line:
					Conditions can be used to display something if an expression is  
true. They can also be used to check that a list exists before  
attempting to loop through it.
				this text:
(Continue reading)

Jeffrey.Klein | 21 Sep 21:29

Patch: tal:define="local var expr"


Here is a patch that localizes tal:define="local var expr", as in TAL.
It leaves unspecified defines as global.
It adds <?local name="var"?> ... <?end?> to the canonical syntax.
Also, some oddities in repeat loops are cleaned up by localizing, and
some vars are properly quoted in code.

-Jeff

** ** **  PRIVILEGED AND CONFIDENTIAL  ** ** **
This email transmission contains privileged and confidential information intended only for the use of
the individual or entity named above.  Any unauthorized review, use, disclosure or distribution is
prohibited and may be a violation of law.  If you are not the intended recipient or a person responsible for
delivering this message to an intended recipient, please delete the email and immediately notify the
sender via the email return address or
mailto:postmaster@...  Thank you.

- end -

Attachment (petal-local.patch): application/octet-stream, 4255 bytes
Corey | 25 Sep 23:29
Favicon

interpolate variable in metal:use-macro?


Say I've got a variable stuffed into my template:

tmpl/macro

which would store a string, such as: "product1.html#content".

Now, I'd like to use what's in 'tmpl/macro' in order to include a metal macro,
like so:

<span metal:use-macro="tmpl/macro" petal:omit-tag="" />

... unfortunately, it doesn't look like tmpl/page is interpolating within the
'metal:use-macro=' ...

"[PETAL ERROR] Cannot find tmpl/macro in ......"

I'd really prefer to not have to do something like:

<span metal:use-macro="product1.html#content" petal:omit-tag="" />
<span metal:use-macro="product2.html#content" petal:omit-tag="" />
<span metal:use-macro="product3.html#content" petal:omit-tag="" />

etc.,etc.etc for each my, say, 10-30 products...

Am I missing something obvious?

Thanks!

(Continue reading)

Corey | 27 Sep 04:03
Favicon

new() or process() on a string rather than a file?


Subject says it all - what if I have a string that I'd like to process
using Petal? How do I do so?  It appears that Petal only supports
processing external files?

What if my template was stored in a database, then retrieved with
the DBI into a variable?

It seems that it would be extremely useful to be able to do something
along the lines of:

# or assume this came from some other datasource, like a database
$input = '
<html xmlns:tal="http://purl.org/petal/1.0/">
    <body tal:content="bar">Dummy Content</body>
</html>
';

# obviously, this does not work:
$template = Petal->new( $input );

$output = $template->process ( bar => 'BAZ' );

print $output;

Which would print:

<html>
   <body>BAZ</body>
</html>
(Continue reading)

Corey | 27 Sep 05:10
Favicon

Re: new() or process() on a string rather than a file?


Well, I started looking into the Petal code, and it looks like this wouldn't be
too difficult... in fact, I already have it working after making just a few very
quick ( and dirty ) changes:

corey <at> scanner ~ $ cat  test_string.pl
#!/usr/bin/perl
use strict;
use warnings;

use Petal;

my ( $input, $petal, $output );

$input = 'a is: ${my_var}';

$petal = Petal->new(
   'string'       => $input,
   'disk_cache'   => 0,  # necessary to avoid warnings
   'memory_cache' => 0,  # necessary to avoid warnings
);

$output = $petal->process( 'my_var' => 'Woot!' );

print "$output\n";

corey <at> scanner ~ $ ./test_string.pl
a is: Woot!

... anyone interested in seeing this officially go into Petal?
(Continue reading)

Jonathan Vanasco | 27 Sep 05:38

Re: new() or process() on a string rather than a file?

if you're pulling it out of a DBI, chances are that you have a lot of  
templates

the strength of petal is in caching, which a multitude of templates  
would negate

have you looked at template::tal ?
	
	http://search.cpan.org/~tomi/Template-TAL-0.8/lib/Template/TAL.pm

it was built specifically for things like what you're talking about

unless you did something crazy, you can use the same templates for  
Petal And Template::Tal

even better- you can use both systems at once on the same site ( i've  
done it , it works like a charm ).

// Jonathan Vanasco

Corey | 27 Sep 05:50
Favicon

Re: new() or process() on a string rather than a file?

On Tuesday 26 September 2006 20:38, Jonathan Vanasco wrote:
<snip>
> have you looked at template::tal ?
> 	
> 	http://search.cpan.org/~tomi/Template-TAL-0.8/lib/Template/TAL.pm
> 
> it was built specifically for things like what you're talking about
>

Wow, thanks for pointing that out to me... I had thought Petal was the
only usable TAL implemenation for perl; this is good news, appears to
be exactly what I'm looking for!

( Any particular issues with Template::TAL I should be warned of before
I start using it? (aside from the topic of caching ) )

> even better- you can use both systems at once on the same site ( i've  
> done it , it works like a charm ).
> 

Great idea - use whichever is appropriate based on the number of 
templates necessary per task.  Cool.

Beers!

Corey


Gmane