From adamlounds at gmail.com Fri Mar 3 15:54:11 2006 From: adamlounds at gmail.com (adam) Date: Fri Mar 3 15:54:22 2006 Subject: [Petal] metal:use-macro should be TALES? Message-ID: <6228ceab0603030754k260dfd19l70a91c4292d62934@mail.gmail.com> Howdy. I'm fairly new to petal, and have been battling through the standard problems (overcoming my aversion to &s in hrefs, javascript stuff etc etc), but am stumped on the latest one. Basically I want to choose which metal template to use at run-time, using something along the lines of metal:use-macro="dat/header" or metal:use-macro="foo/${dat/bar}/baz.xml" or metal:use-macro="string: dat/header" Is this supported? Should I be doing something entirely different? Thanks for your help, -- Adam -------------- next part -------------- An HTML attachment was scrubbed... URL: https://lists.webarch.co.uk/pipermail/petal/attachments/20060303/393caa2d/attachment.html From jon at 2xlp.com Fri Mar 3 16:54:07 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Fri Mar 3 16:54:20 2006 Subject: [Petal] metal:use-macro should be TALES? In-Reply-To: <6228ceab0603030754k260dfd19l70a91c4292d62934@mail.gmail.com> References: <6228ceab0603030754k260dfd19l70a91c4292d62934@mail.gmail.com> Message-ID: Usually for things like that, i do: I'm not sure if that will work in your example. btw, you can just $processed =~ s/&/&/g ; i do that for a bunch of petal symbols when doing emails/etc On Mar 3, 2006, at 10:54 AM, adam wrote: > Howdy. > > I'm fairly new to petal, and have been battling through the > standard problems (overcoming my aversion to &s in hrefs, > javascript stuff etc etc), but am stumped on the latest one. > > Basically I want to choose which metal template to use at run-time, > using something along the lines of > > metal:use-macro="dat/header" or > metal:use-macro="foo/${dat/bar}/baz.xml" or > metal:use-macro="string: dat/header" > > Is this supported? Should I be doing something entirely different? > > Thanks for your help, > -- > Adam From adamlounds at gmail.com Mon Mar 6 14:15:25 2006 From: adamlounds at gmail.com (adam) Date: Mon Mar 6 14:15:34 2006 Subject: [Petal] metal:use-macro should be TALES? In-Reply-To: <6228ceab0603060356m7b4b1754nf14dc17d8179d0ce@mail.gmail.com> References: <6228ceab0603030754k260dfd19l70a91c4292d62934@mail.gmail.com> <6228ceab0603060356m7b4b1754nf14dc17d8179d0ce@mail.gmail.com> Message-ID: <6228ceab0603060615p3a46c225l1db37e8e3bf4c3ae@mail.gmail.com> Not quite, I want to choose the file to include, not just have a string " foo/${dat/bar}/ baz.xml" in the output. I'm very wary of replacing all &s with & - I'm expecting something like http://server/cgi?foo=bar&baz=boogie where the visible content has & but the href has &, so replacing all &s would be Bad. Patch: --- lib/Petal/CodeGenerator.pm 2006-01-17 12:27:53.000000000 +0000 +++ libnew/Petal/CodeGenerator.pm 2006-03-06 11:40:46.000000000 +0000 @@ -233,15 +233,23 @@ my $included_from = $petal_object->_file(); $included_from =~ s/\#.*$//; + # allow ${dat/var} expansion in includes + if($path=~ /^\$\{(.*)\}$/ ) { + $path = $class->comp_expr_encoded ($1); + } 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 = \"\" if (defined \$\@ and \$\@);"); $class->add_code ("\$res;"); A bit (OK, a lot) hacky, but it allows me to dynamically choose the file to be included. I think the underlying problem is that nested variables aren't supported, as otherwise would be canonicalized to "?> or whatever and expanded accordingly. I can see how nested expressions would be complicated though :-) On 3/3/06, Jonathan Vanasco wrote: > Usually for things like that, i do: > > > > > I'm not sure if that will work in your example. > > btw, you can just > $processed =~ s/&/&/g ; > > i do that for a bunch of petal symbols when doing emails/etc > > > On Mar 3, 2006, at 10:54 AM, adam wrote: > > > Howdy. > > > > I'm fairly new to petal, and have been battling through the > > standard problems (overcoming my aversion to &s in hrefs, > > javascript stuff etc etc), but am stumped on the latest one. > > > > Basically I want to choose which metal template to use at run-time, > > using something along the lines of > > > > metal:use-macro="dat/header" or > > metal:use-macro="foo/${dat/bar}/baz.xml" or > > metal:use-macro="string: dat/header" > > > > Is this supported? Should I be doing something entirely different? > > > > Thanks for your help, > > -- > > Adam -- Adam -- Adam From rabbit at rabbit.us Sun Mar 19 17:35:38 2006 From: rabbit at rabbit.us (Peter Rabbitson) Date: Sun Mar 19 17:35:56 2006 Subject: [Petal] Accessing coderefs Message-ID: <20060319173538.GB30545@rabbit.us> Greetings, Is it a bug or a feature that if I have: $petal->process ( { coderef => \&useful_sub } ); I can not do ...petal:content="coderef --var1 --var2"... ? Thanks From bruno at mkdoc.com Mon Mar 20 11:21:49 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Mon Mar 20 11:21:53 2006 Subject: [Petal] Accessing coderefs In-Reply-To: <20060319173538.GB30545@rabbit.us> References: <20060319173538.GB30545@rabbit.us> Message-ID: <441E904D.2050702@mkdoc.com> Peter Rabbitson wrote: > > Is it a bug or a feature that if I have: > > $petal->process ( { coderef => \&useful_sub } ); > > I can not do > > ...petal:content="coderef --var1 --var2"... This would be ok as an object, what about it doesn't work? -- Bruno From rabbit at rabbit.us Mon Mar 20 14:09:37 2006 From: rabbit at rabbit.us (Peter Rabbitson) Date: Mon Mar 20 14:09:49 2006 Subject: [Petal] Accessing coderefs In-Reply-To: <441E904D.2050702@mkdoc.com> References: <20060319173538.GB30545@rabbit.us> <441E904D.2050702@mkdoc.com> Message-ID: <20060320140937.GA27377@rabbit.us> On Mon, Mar 20, 2006 at 11:21:49AM +0000, Bruno Postle wrote: > Peter Rabbitson wrote: > > > >Is it a bug or a feature that if I have: > > > >$petal->process ( { coderef => \&useful_sub } ); > > > >I can not do > > > >...petal:content="coderef --var1 --var2"... > > This would be ok as an object, what about it doesn't work? > > -- > Bruno Petal gives me no problems if I am to use object/method and supply parameters. In my case it is very problematic to supply an object to process(), so I was wondering if there is a way to call a coderef. Peter From bruno at mkdoc.com Thu Mar 23 17:25:37 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Thu Mar 23 17:25:41 2006 Subject: [Petal] Accessing coderefs In-Reply-To: <20060320140937.GA27377@rabbit.us> References: <20060319173538.GB30545@rabbit.us> <441E904D.2050702@mkdoc.com> <20060320140937.GA27377@rabbit.us> Message-ID: <20060323172536.GA12450@mkdoc.com> On Mon 20-Mar-2006 at 09:09 -0500, Peter Rabbitson wrote: > > Petal gives me no problems if I am to use object/method and supply > parameters. In my case it is very problematic to supply an object to > process(), so I was wondering if there is a way to call a coderef. No, it seems that Petal explicitly stops you passing parameters to anything that isn't an object. The following patch seems to make this work, though it hasn't had any thorough testing. Can you try it out? Index: lib/Petal/Hash/Var.pm =================================================================== RCS file: /var/spool/cvs/Petal/lib/Petal/Hash/Var.pm,v retrieving revision 1.17 diff -r1.17 Var.pm 98a99,100 > unless (isa $current->{$next}, 'CODE') > { 100a103 > } 130c133 < $current = (isa ($current, 'CODE')) ? $current->() : $current; --- > $current = (isa ($current, 'CODE')) ? $current->(@args) : $current; From jon at 2xlp.com Wed Mar 29 02:35:18 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Wed Mar 29 02:35:40 2006 Subject: [Petal] using $ in petal In-Reply-To: <20060319173538.GB30545@rabbit.us> References: <20060319173538.GB30545@rabbit.us> Message-ID: i can't figure this out if $a is in a document, petal shows me '$a' -- good. if $aa is in a Petal template, its stripped out. any $ followed by 2 or more chars is stripped out. does anyone know why? bug , feature , workaround ? i was trying to use petal to generate some downloadable customized php snippets, and i've tried just about every escape sequence with no luck. From fergal at esatclear.ie Wed Mar 29 09:55:05 2006 From: fergal at esatclear.ie (Fergal Daly) Date: Wed Mar 29 10:02:28 2006 Subject: [Petal] using $ in petal In-Reply-To: References: <20060319173538.GB30545@rabbit.us> Message-ID: <875029960603290055i79f59e0co8fbd7ff9511c9297@mail.gmail.com> Petal is not strict TAL, it also includes some "features" like $variable being the same as . So I guess $aa is being replaced it's value (ie blank), my guess is that something in the parser is wrong so it doesn't correctly recognise single letter variables with $, F On 3/29/06, Jonathan Vanasco wrote: > i can't figure this out > > if $a is in a document, petal shows me '$a' -- good. > > if $aa is in a Petal template, its stripped out. any $ followed by 2 > or more chars is stripped out. > > does anyone know why? bug , feature , workaround ? i was trying to > use petal to generate some downloadable customized php snippets, and > i've tried just about every escape sequence with no luck. > > > From jon at 2xlp.com Wed Mar 29 17:37:47 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Wed Mar 29 17:37:57 2006 Subject: [Petal] using $ in petal In-Reply-To: <875029960603290055i79f59e0co8fbd7ff9511c9297@mail.gmail.com> References: <20060319173538.GB30545@rabbit.us> <875029960603290055i79f59e0co8fbd7ff9511c9297@mail.gmail.com> Message-ID: <00FF9E9B-A51E-4719-BA05-AF16667CF43D@2xlp.com> On Mar 29, 2006, at 3:55 AM, Fergal Daly wrote: > Petal is not strict TAL, it also includes some "features" like > $variable being the same as . So I > guess $aa is being replaced it's value (ie blank), my guess is that > something in the parser is wrong so it doesn't correctly recognise > single letter variables with $, Are there any known workarounds? I can't seem to figure out any way to put the string $abc into a document \$var didn't work $$var didn't work $ isn't a standard html entity - its a 'special character' and not widely supported $ is on some spec sheets, but i haven't found a browser that shows it $ is the equiv, but Petal seems to parse it as a $ for interpolation ( so $a works, but $a[a]* doesn't )