Jonathan Vanasco | 2 Aug 00:49

PATCH: omit omit-tag from templates


This is a trivial patch...

I noticed while checking some petal cache documents that if omit- 
tag="string:1" were set - which is the recommended way of always  
omitting a tag from a document -  it was turned into code that always  
returned true

that seemed a bit wasteful.  this patch just does a secondary check  
on omit-tag items , to see if it is set to string:1

if it is, the start/end tags aren't pushed onto the result stack.  if  
its not , they are.

this seems to work fine, and respect nested items

Attachment (PETAL.diff): application/octet-stream, 1700 bytes

Jonathan Vanasco | 2 Aug 05:04

Re: PATCH: omit omit-tag from templates

please ignore the patch.

it didn't take into account multi-tal tags

i'm going to try and redo it for the case where the only tal  
instruction is an omit tag.

Lenga, Yair [CIB-FI] | 13 Aug 23:00

Using '|' in TALES

Hi,

I'm trying to use Petal for a new project that I'm working on.

I tried to use the '|' (alternative value), based on the TALES documentation. I realized this is not listed
in the Petal doc, but I tought to give it a try.

When I tried:

<html>
<body>
<p petal:content="my/data | string:nothing" > Someting </p>
</body>
</html>

perl -Mpetal -e 'print new Petal(file=>"file.html", error_on_undef_value => 0)->process();"

I was getting an error (undef value). When I allowed the error (error_on_undef_var = 0), I got empty tag - I
was hoping to see "nothing").

I decided to try this without the spaces, same command.

<html>
<body>
<p petal:content="my/data|string:nothing" > Someting </p>
</body>
</html>

What I got was infinite recursion. The program was producing:
Deep recursion on subroutine "Petal::Hash::fetch" at blib/lib/Petal/Hash/Var.pm line 73.
(Continue reading)

Jonathan | 14 Aug 02:16

Re: Using '|' in TALES


On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote:

> Few questions:
> - Is the '|' suppose to work with TAL ? what is the correct syntax.
> - Any chance of fixing the bug ? My pages are designed by a  
> designer - My goal with Petal is to limit his ability to impact  
> server performance.

Sadly, Petal isn't strictly TAL.  It's almost... the guys who make it  
have a good portion of TAL in there, and usually fix stuff they  
overlook when they realize it.  But there There are a few things in  
TAL that aren't in Petal, and vice versa.

If you don't hear anything within the next few days from them  
regarding the bug, there are some options before you give up:

	a- you can try some of the other TAL implementations in Perl.  Last  
I checked there were 2 others on CPAN.  Neither did the code caching  
or anything like you see in Petal (one was admittedly anti-caching).   
But they all were much more compliant with the spec.

	b- alter your code slightly:
		"my/data | string:nothing" => "my/F_data 'nothing'"

		instead of data being a string in the hash you pass to petal, its a  
sub reference, that does the lookup manually, and handles the return  
value

The beauty of TAL is that you can just have your designer handle the  
(Continue reading)

Benjamin Tucker | 14 Aug 03:14

Re: Using '|' in TALES

On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote:
> I tried to use the '|' (alternative value), based on the TALES  
> documentation. I realized this is not listed in the Petal doc, but  
> I tought to give it a try.

You might have a look at Petal::CodePerl.  It adds some functionality  
to Petal, one of which is making '|' work as specified in TAL.

http://search.cpan.org/~fdaly/Petal-CodePerl-0.06/lib/Petal/CodePerl.pm

Fergal Daly | 14 Aug 11:57
Picon

Re: Using '|' in TALES

On 14/08/06, Benjamin Tucker <ben@...> wrote:
> On Aug 13, 2006, at 5:00 PM, Lenga, Yair [CIB-FI] wrote:
> > I tried to use the '|' (alternative value), based on the TALES
> > documentation. I realized this is not listed in the Petal doc, but
> > I tought to give it a try.
>
> You might have a look at Petal::CodePerl.  It adds some functionality
> to Petal, one of which is making '|' work as specified in TAL.
>
> http://search.cpan.org/~fdaly/Petal-CodePerl-0.06/lib/Petal/CodePerl.pm

Does this work with Petal anymore? I haven't touched in for about 2 years now,

F

Jonathan Vanasco | 16 Aug 21:08

Patch Idea

This one line is useful to me... but I don't know if its appropriate  
in Petal.  It would be neat if you thought it was.

sub process {

	if (ref $_[0] eq 'Petal::Hash') { $hash = shift }
	elsif (ref $_[0] eq 'HASH')     { $hash = new Petal::Hash (%{shift 
()}) }
+	elsif (ref $_[0] eq 'ARRAY')     { $hash = new Petal::Hash (@{shift 
()}) }
	else                            { $hash = new Petal::Hash  
(@_)         }

basically,  if you're wrapping Petal as a templating option for a  
framwork, you don't have to deref the input into something that Petal  
expects
its of trivial use.  the difference is in a function below.  just  
wanted to suggest it.

sub process_petal {
	my  $self= shift;
	my 	$template_vars;

	if 		( ref $_[0] eq 'HASH' ) {
		$template_vars= $_[0];
	}
	elsif 	( ref $_[0] eq 'REF' ) {
		$template_vars= $$template_vars;
		while ( ref $template_vars eq 'REF' ) {
			$template_vars= $$template_vars;
(Continue reading)

Corey | 16 Aug 22:06
Favicon

Re: Patch Idea


A while back I asked whether it would be possible to get Petal to
iterate ('petal:repeat') through hashes because I hated having
to convert all my data structures in my classes, which are usually
hashes, into arrays just so I could feed them to petal....  is this
essentially what your provided code does?

If so -- killer!  I think it would be especially useful.

On Wednesday 16 August 2006 12:08, Jonathan Vanasco wrote:
> This one line is useful to me... but I don't know if its appropriate  
> in Petal.  It would be neat if you thought it was.
> 
> sub process {
> 
> 	if (ref $_[0] eq 'Petal::Hash') { $hash = shift }
> 	elsif (ref $_[0] eq 'HASH')     { $hash = new Petal::Hash (%{shift 
> ()}) }
> +	elsif (ref $_[0] eq 'ARRAY')     { $hash = new Petal::Hash (@{shift 
> ()}) }
> 	else                            { $hash = new Petal::Hash  
> (@_)         }
> 
> 
> basically,  if you're wrapping Petal as a templating option for a  
> framwork, you don't have to deref the input into something that Petal  
> expects
> its of trivial use.  the difference is in a function below.  just  
> wanted to suggest it.
> 
(Continue reading)

Jonathan Vanasco | 16 Aug 22:34

Re: Patch Idea


On Aug 16, 2006, at 4:06 PM, Corey wrote:

>
> A while back I asked whether it would be possible to get Petal to
> iterate ('petal:repeat') through hashes because I hated having
> to convert all my data structures in my classes, which are usually
> hashes, into arrays just so I could feed them to petal....  is this
> essentially what your provided code does?
>
> If so -- killer!  I think it would be especially useful.

sorry, but no.  it just has to do with the way perl treats hashes and  
named arguments, and how

a)
	$template->process( a=> 'z' );

my %Personalized= ( 'a' => 'z' );

b)
  	$template->process( %Personalized );

c)
	$template->process( \%Personalized );

d)
	$template->process( {'a' => 'z'}  );

on c, process gets ( $self , $ref__Personalized );
(Continue reading)

Corey | 16 Aug 23:10
Favicon

Re: Patch Idea

On Wednesday 16 August 2006 13:34, Jonathan Vanasco wrote:
> sorry, but no.  it just has to do with the way perl treats hashes and  
> named arguments
<snip>
> but, it means that you save doing
> 	process( @$args ) in your class, instead of just process( $args ),  
> which is kind of confusing
>

Ok - I understand, that's definitely usefull in its own right.

 
> you still don't need to convert hashes into arrays for petal-- just  
> make an iterator class or something.  have petal print out a function  
> to the iterator that loops through an array and pulls out the index  
> you want. 
>   

Thanks, when I get a moment to experiment, I'll try this out.

Beers!

Corey


Gmane