From fergal at esatclear.ie Sat Apr 1 14:44:22 2006 From: fergal at esatclear.ie (Fergal Daly) Date: Sat Apr 1 14:44:30 2006 Subject: [Petal] using $ in petal In-Reply-To: <00FF9E9B-A51E-4719-BA05-AF16667CF43D@2xlp.com> References: <20060319173538.GB30545@rabbit.us> <875029960603290055i79f59e0co8fbd7ff9511c9297@mail.gmail.com> <00FF9E9B-A51E-4719-BA05-AF16667CF43D@2xlp.com> Message-ID: <875029960604010544m5de01a63g1a4fb86121d7dc5@mail.gmail.com> I thought \$ was the one but if it's not working for you then I don't have a suggestion beyond reading the source or using one of the other perl TAL implementations which don't have $ syntax, F On 3/29/06, Jonathan Vanasco wrote: > > 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 ) > From bruno at mkdoc.com Mon Apr 3 12:49:01 2006 From: bruno at mkdoc.com (Bruno Postle) Date: Mon Apr 3 12:49:08 2006 Subject: [Petal] using $ in petal In-Reply-To: <00FF9E9B-A51E-4719-BA05-AF16667CF43D@2xlp.com> References: <20060319173538.GB30545@rabbit.us> <875029960603290055i79f59e0co8fbd7ff9511c9297@mail.gmail.com> <00FF9E9B-A51E-4719-BA05-AF16667CF43D@2xlp.com> Message-ID: <44310BAD.2040908@mkdoc.com> Jonathan Vanasco wrote: > > Are there any known workarounds? I can't seem to figure out any way to > put the string $abc into a document Not so elegant, but this should work: $abc Escaping as \$ ought to be ok. This would be a good thing to fix. -- Bruno From petal-list at 2xlp.com Tue Apr 4 18:39:07 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Tue Apr 4 18:39:20 2006 Subject: [Petal] nested expression workaround? Message-ID: <64CF68DC-0C51-45E0-AE7D-B9A8353BE547@2xlp.com> Does anyone know of a workaround for nested expressions? I need to do the following (which is not petal-safe) id - name
anyone know if there's a workaroudn for this sort of thing? From corey_s at qwest.net Thu Apr 6 01:03:58 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 6 01:03:52 2006 Subject: [Petal] macro substitution? Message-ID: <200604051703.58398.corey_s@qwest.net> Hello! I'm new to petal - have a question regarding best-practices, specifically regarding metal includes/macros. In summary, I want to be able to dynamically utilize 'metal:use-macro', so that my calling cgi can set a variable, which will be passed to a base/common petal template, which will then use the intended macro, as defined/set in the aformentioned variable. Say I have: .../dir/foo.html Foo

FOO!

and I also have a: .../dir/bar.html Bar

BAR!

finally, I have a: .../index.html Foo or Bar? Here's the question: What's the best/proper way of changing that use-macro include in 'index.html' to dynamically decide on which macro to use - for instance if I have a variable defined, say, $action, which is either 'foo.html' or 'bar.html'? Basically, somthing along the lines of the following ( which doesn't work ): Many thanks! From corey_s at qwest.net Thu Apr 6 02:27:47 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 6 02:27:40 2006 Subject: [Petal] macro substitution? In-Reply-To: <200604051703.58398.corey_s@qwest.net> References: <200604051703.58398.corey_s@qwest.net> Message-ID: <200604051827.47226.corey_s@qwest.net> The following works for me, but seems... not very elegant ... .../index.html Foo or Bar? .../dir/foo.html Foo

FOO!

On Wednesday April 5 2006 5:03 pm, Corey wrote: > > Hello! > > I'm new to petal - have a question regarding best-practices, specifically regarding > metal includes/macros. > > In summary, I want to be able to dynamically utilize 'metal:use-macro', so that my > calling cgi can set a variable, which will be passed to a base/common petal template, > which will then use the intended macro, as defined/set in the aformentioned variable. > > Say I have: > > .../dir/foo.html > > > > Foo > > > >

FOO!

> > > > > > and I also have a: > > .../dir/bar.html > > > > Bar > > > >

BAR!

> > > > > > finally, I have a: > > .../index.html > > > > Foo or Bar? > > > > > > > > > > Here's the question: > > What's the best/proper way of changing that use-macro include in 'index.html' to > dynamically decide on which macro to use - for instance if I have a variable defined, > say, $action, which is either 'foo.html' or 'bar.html'? > > Basically, somthing along the lines of the following ( which doesn't work ): > > > > > > Many thanks! > > > From corey_s at qwest.net Thu Apr 20 01:52:00 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 20 01:51:52 2006 Subject: [Petal] repeat through hash Message-ID: <200604191752.00922.corey_s@qwest.net> Is there any particular technical reason why the 'repeat' syntax can't/won't loop through hashes, as though passed to, say, the perl 'keys' or 'values' function, or something similar to 'for ( %{ $hash } ) { return $_ }'? It seems rather limiting to only be able to iterate/loop through arrays or arrays of hashes - I'm constantly finding that I have to design my libraries' data-structures around Petal; for instance, using arrays of hashes rather than plain hashes which are often more natural and appropriate. Thanks, Corey From rabbit at rabbit.us Thu Apr 20 02:34:04 2006 From: rabbit at rabbit.us (Peter Rabbitson) Date: Thu Apr 20 02:34:27 2006 Subject: [Petal] repeat through hash In-Reply-To: <200604191752.00922.corey_s@qwest.net> References: <200604191752.00922.corey_s@qwest.net> Message-ID: <20060420013404.GA435@rabbit.us> On Wed, Apr 19, 2006 at 05:52:00PM -0700, Corey wrote: > > Is there any particular technical reason why the 'repeat' syntax can't/won't > loop through hashes, as though passed to, say, the perl 'keys' or 'values' > function, or something similar to 'for ( %{ $hash } ) { return $_ }'? > > It seems rather limiting to only be able to iterate/loop through arrays or > arrays of hashes - I'm constantly finding that I have to design my libraries' > data-structures around Petal; for instance, using arrays of hashes > rather than plain hashes which are often more natural and appropriate. > > Thanks, > > Corey > What you probably need is the each: function provided by Petal::Utils. Cheers From corey_s at qwest.net Thu Apr 20 03:31:19 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 20 03:31:13 2006 Subject: [Petal] repeat through hash In-Reply-To: <20060420013404.GA435@rabbit.us> References: <200604191752.00922.corey_s@qwest.net> <20060420013404.GA435@rabbit.us> Message-ID: <200604191931.19635.corey_s@qwest.net> On Wednesday 19 April 2006 18:34, Peter Rabbitson wrote: > On Wed, Apr 19, 2006 at 05:52:00PM -0700, Corey wrote: > > Is there any particular technical reason why the 'repeat' syntax > > can't/won't loop through hashes > What you probably need is the each: function provided by Petal::Utils. > Cool - just what the doctor ordered. Thanks for the heads-up! From corey_s at qwest.net Thu Apr 20 06:28:29 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 20 06:28:21 2006 Subject: [Petal] bug, or misunderstanding? Message-ID: <200604192228.29832.corey_s@qwest.net> 'Nother question! Trying to iterate through one hash, then use its keys to get values from a second hash. $data = { 'foo' => { 'boat' => 'FOO_val_boat', 'car' => 'FOO_val_car', }, 'bar' => { 'boat' => 'BAR_val_boat', 'car' => 'BAR_val_car', }, }; doesn't work:
doesn't work! why not?
works:
$var equals "boat" results in "BAR_val_boat"
I'd prefer the second version to the first, as the first version seems as though it should be unnecessary. What is it about the ${blah} vs. ${data/foo} syntax? Or is it something special that goes on when I create/define the temporary variable, var? Is there a bug in the way replace scans/parses the string, and so gets confused with the '/' that's in the ${} interpolation? Thanks! Corey From corey_s at qwest.net Thu Apr 20 06:35:38 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 20 06:35:26 2006 Subject: [Petal] bug, or misunderstanding? In-Reply-To: <200604192228.29832.corey_s@qwest.net> References: <200604192228.29832.corey_s@qwest.net> Message-ID: <200604192235.38043.corey_s@qwest.net> On Wednesday 19 April 2006 22:28, Corey wrote: > I'd prefer the second version to the first, as the first version seems as though > it should be unnecessary. > Whoops: I'd prefer the _first_ version to the _second_, as the _second_ version seems as though it should be unnecessary. From corey_s at qwest.net Thu Apr 20 06:52:38 2006 From: corey_s at qwest.net (Corey) Date: Thu Apr 20 06:52:29 2006 Subject: [Petal] bug, or misunderstanding? In-Reply-To: <200604192228.29832.corey_s@qwest.net> References: <200604192228.29832.corey_s@qwest.net> Message-ID: <200604192252.38843.corey_s@qwest.net> On Wednesday 19 April 2006 22:28, Corey wrote: >
> doesn't work! why not? >
> > What is it about the ${blah} vs. ${data/foo} syntax? I said "${data/foo}", when I meant "${field/key}" ... shouldn't be posting when I'm so tired... sorry! Here's my post, with no errors this time: Trying to iterate through one hash, then use its keys to get values from a second hash. $data = { 'foo' => { 'boat' => 'FOO_val_boat', 'car' => 'FOO_val_car', }, 'bar' => { 'boat' => 'BAR_val_boat', 'car' => 'BAR_val_car', }, }; doesn't work:
doesn't work! why not?
works:
$var equals "boat" results in "BAR_val_boat"
I'd prefer the first version to the second, as the second version seems as though it should be unnecessary. What is it about the ${blah} vs. ${field/key} syntax? Or is it something special that goes on when I create/define the temporary variable, var? Is there a bug in the way replace scans/parses the string, and so gets confused with the '/' that's in the ${} interpolation? Thanks! From corey at bitworthy.net Wed Apr 19 22:26:34 2006 From: corey at bitworthy.net (Corey) Date: Thu Apr 20 09:09:47 2006 Subject: [Petal] define question Message-ID: <200604191426.34293.corey@bitworthy.net> Scratching my head, wonder why the following doesn't work: In other words, I simply want to set a variable to an arbitrary string - rather to the result of some method/object/data-structure. Am I missing something ridiculously obvious? Thanks, Corey From corey at bitworthy.net Wed Apr 19 22:29:58 2006 From: corey at bitworthy.net (Corey) Date: Thu Apr 20 09:09:48 2006 Subject: [Petal] Re: define question In-Reply-To: <200604191426.34293.corey@bitworthy.net> References: <200604191426.34293.corey@bitworthy.net> Message-ID: <200604191429.58579.corey@bitworthy.net> On Wednesday 19 April 2006 14:26, you wrote: > Scratching my head, wonder why the following doesn't work: > > > > > In other words, I simply want to set a variable to an arbitrary string - > rather to the result of some method/object/data-structure. > > Am I missing something ridiculously obvious? > Yes I was... ... did the trick. Of course I figure that out the very next moment after sending the question out! Cheers, Corey From jon at 2xlp.com Thu Apr 20 22:01:08 2006 From: jon at 2xlp.com (Jonathan Vanasco) Date: Thu Apr 20 22:01:21 2006 Subject: [Petal] bug, or misunderstanding? In-Reply-To: <200604192252.38843.corey_s@qwest.net> References: <200604192228.29832.corey_s@qwest.net> <200604192252.38843.corey_s@qwest.net> Message-ID: On Apr 20, 2006, at 1:52 AM, Corey wrote: > I'd prefer the first version to the second, as the second version > seems as though > it should be unnecessary. You can't From the docs: (search for 'nested') ===== TRAP: You cannot write nested expressions such as: ${my_var/hello_world ${my_var/current_user}} This will NOT work. At least, not yet. ===== From petal-list at 2xlp.com Thu Apr 20 22:05:56 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Thu Apr 20 22:06:02 2006 Subject: [Petal] repeat through hash In-Reply-To: <20060420013404.GA435@rabbit.us> References: <200604191752.00922.corey_s@qwest.net> <20060420013404.GA435@rabbit.us> Message-ID: <772FA561-8140-4876-BB3E-C1B8B96F4178@2xlp.com> On Apr 19, 2006, at 9:34 PM, Peter Rabbitson wrote: > What you probably need is the each: function provided by Petal::Utils. just be wary that its not strict tal - so you won't be able to use your Petal templates with python or php generally, what i do is this: pull everything from the db into a hash using named keys , and a _HASHNAME_order array that has the order of the keys if necessary do what i must with the data for output, just create a new array, and loop through the order of hash keys tossing a ref to the element into the item petal is great in that it'll dereference most refs automagically so there's almost no performance hit in 90% of what you need to do From corey_s at qwest.net Fri Apr 21 00:24:13 2006 From: corey_s at qwest.net (Corey) Date: Fri Apr 21 00:24:06 2006 Subject: [Petal] repeat through hash In-Reply-To: <772FA561-8140-4876-BB3E-C1B8B96F4178@2xlp.com> References: <200604191752.00922.corey_s@qwest.net> <20060420013404.GA435@rabbit.us> <772FA561-8140-4876-BB3E-C1B8B96F4178@2xlp.com> Message-ID: <200604201624.13355.corey_s@qwest.net> On Thursday 20 April 2006 14:05, Jonathan Vanasco wrote: > > just be wary that its not strict tal - so you won't be able to use > your Petal templates with python or php > That is an excellent point; I had taken pause on it as well, except that I really was in a rush to get things working with what I had, so I opted for it anyhow, hopefully as a temporary solution at least -- read on. > generally, what i do is this: > > pull everything from the db into a hash using named keys , and a > _HASHNAME_order array that has the order of the keys if necessary > do what i must with the data for output, just create a new array, > and loop through the order of hash keys tossing a ref to the element > into the item > That's kindof what I was getting at, when I mentioned how I noticed Petal seemed to make me design a bit of my code/libraries/modules api and implementation around Petal, rather than just coding naturaly, then using Petal to get at the data. I think it would be beneficial to not require any consideration of one's templating system whilst programming/designing one's software. i.e., it shouldn't be necessary to have to create special accessors just to allow your presentation/view templates to work in a convenient manner. Take the following contrived example for an instance: # get person by id # innapropriate ( array ref ) $people = [ { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' 'id_num' => '456a7' }, { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' 'id_num' => '765z4' } ]; # but Petal needs to loop through it, so we're resigned to modeling, # or providing access to, our data in that way # however, the following would make more sense.... # correct/natural ( hash ref ) $people = { '456a7' => { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' }, '765z4' => { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' } }; # but Petal can't loop through hashes, so we're stuck jumping # through hoops such as the former array ref, or such as what # Jonathan described With that in mind, I propose the following: Allow 'repeat' to work seamlessly/transparently with hashes - in array context 'repeat/index' carries the subscript, while in hash context it would carry the key. I'm thinking that such a solution would be fully compliant with the TAL spec, while providing an extremely useful feature which would help tremendously towards minimizing the existant code_implementation-to-templating_sytem incongruency presented above. Contrast the two following examples, notice how transparent it can be made to work: # current approach $people = [ { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' 'id_num' => '456a7' }, { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' 'id_num' => '765z4' } ];
person/firstname => 'Benjamin' person/lastname => 'Tucker' person/id_num => '765z4' repeat/index => 0 repeat/number => 1 # if petal's 'repeat' supported hashes $people = { '456a7' => { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' }, '765z4' => { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' } };
person/firstname => 'Benjamin' person/lastname => 'Tucker' repeat/index => '765z4' repeat/number => 1 And for a more flat, simple example: $people = [ 'Benjamin Tucker', 'Pierre-Joseph Proudhon' ]; # versus $people = { '456a7' => 'Benjamin Tucker', '765z4' => 'Pierre-Joseph Proudhon' }; # would result in
person => 'Benjamin Tucker' repeat/index => 0 or '456a7' Anyone in favor? Any pitholes or details I'm missing? Cheers, Corey From petal-list at 2xlp.com Fri Apr 21 01:29:57 2006 From: petal-list at 2xlp.com (Jonathan Vanasco) Date: Fri Apr 21 01:30:26 2006 Subject: [Petal] repeat through hash In-Reply-To: <200604201624.13355.corey_s@qwest.net> References: <200604191752.00922.corey_s@qwest.net> <20060420013404.GA435@rabbit.us> <772FA561-8140-4876-BB3E-C1B8B96F4178@2xlp.com> <200604201624.13355.corey_s@qwest.net> Message-ID: <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> On Apr 20, 2006, at 7:24 PM, Corey wrote: > Anyone in favor? Any pitholes or details I'm missing? Well there's this: in Perl, Python and PHP (the TAL implementations I use ), hashes ( perl hashes, python dicts , php named arrays ) are unordered. randomly showing items from a list, IMHO, is worthless and confusing. to do what you want, it would just be going randomly through the hash - you'd have to map some sort of sorting algorithm onto the function ( sort on the key? a value of hash element? what is the sort mechanism? ) i believe that in python you can map the repeat onto a generator or iterator - i *think* you can figure out a way mimic that it in perl using petal's method support ie, your repeat loop calls a function that returns the next item in whatever sequence, and petal stops doing that at the end its pretty easy to do in python tal, but i'm not sure about the petal version. i tried to stab away at the petal source and try to get nested variable to work. i don't think its quite possible. maybe some college student out there would want to do it through google summer of code? that would be awesome. | - - - - - - - - - - - - - - - - - - - - | RoadSound.com / Indie-Rock.net | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - From corey_s at qwest.net Fri Apr 21 02:52:28 2006 From: corey_s at qwest.net (Corey) Date: Fri Apr 21 02:52:20 2006 Subject: [Petal] repeat through hash In-Reply-To: <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> References: <200604191752.00922.corey_s@qwest.net> <200604201624.13355.corey_s@qwest.net> <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> Message-ID: <200604201852.28461.corey_s@qwest.net> On Thursday 20 April 2006 17:29, Jonathan Vanasco wrote: > On Apr 20, 2006, at 7:24 PM, Corey wrote: > > Anyone in favor? Any pitholes or details I'm missing? > > Well there's this: > in Perl, Python and PHP (the TAL implementations I use ), hashes > ( perl hashes, python dicts , php named arrays ) are unordered. > randomly showing items from a list, IMHO, is worthless and confusing. > True. And I agree that, from a presentation standpoint, randomly displaying items from an unordered list is not always useful or sensical - however there are certainly plenty of instances/use-cases where an ordered presentation is not in fact necessary, or where there truly is no criteria from which to sort by anyways. ( I'm currently writing an app in which this is the case. ) I have to point out though, that hashes/dicts/named-arrays are unordered _internaly_, while arrays are merely ordered internally by subscript ( i.e., 0 - N ) -- point being, for all intents and purposes: $people_array = [ { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' 'id_num' => '456a7' }, { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' 'id_num' => '765z4' } ]; ... and $people_hash = { '456a7' => { 'firstname' => 'Benjamin', 'lastname' => 'Tucker' }, '765z4' => { 'firstname' => 'Pierre-Joseph', 'lastname' => 'Proudhon' } }; ... can both be said to be "unsorted", from a template user perspective. ( assuming that $people_array wasn't _manually_ sorted by the programmer in the order specified (i.e, first comes Tucker, then comes Proudhon) ). So, while looping through $people_array, the template user would always get Tucker first, then Proudhon; and while looping through $people_hash, the user would not know for sure which order the results would be iterated - the difference is more or less the same: both "lists" were not filtered through a purposed sort/order function. So, appologies for the digression - but I'm attempting to illustrate that the issue of sorting is quite separate from the issue of allowing Petal's 'repeat' statement to be implemented in a manner which allows transparent looping over hashes. If the feature in question is: #1 - conformant to TAL spec and #2 - implementable in Petal but #3 - deemed usefull ... then I think it may be worth considering. If either #1 _or_ #2 are definitely false, then there is no reason to continue. If #1 and #2 are true, but #3 is debatable, then I think it would come down simply to whoever got around to actually implementing it - and people could use it or not; but it would at least be available. > to do what you want, it would just be going randomly through the hash > That's ok, as it is not always necessary to loop over sorted lists -- in those cases, I feel that being able to loop/repeat over hashes would be quite helpfull and convienient - and could be implemented without parting from the TAL spec. > i believe that in python you can map the repeat onto a generator or > iterator - i *think* you can figure out a way mimic that it in perl > using petal's method support > > ie, your repeat loop calls a function that returns the next item in > whatever sequence, and petal stops doing that at the end > This is definitely good food for thought - as I start using TAL/Petal more and more. > i tried to stab away at the petal source and try to get nested > variable to work. i don't think its quite possible. > Bummer! ( Cool that you tried though. I was actually going to bring that up in another post - hoping we/someone could fix that. ) > maybe some college student out there would want to do it through > google summer of code? that would be awesome. > Definitely. Could you summarize what makes that feature so difficult? CHeers, Corey From mark at thinkfoo.com Fri Apr 21 10:42:47 2006 From: mark at thinkfoo.com (Mark Holland) Date: Fri Apr 21 10:43:20 2006 Subject: [Petal] repeat through hash In-Reply-To: <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> References: <200604191752.00922.corey_s@qwest.net> <20060420013404.GA435@rabbit.us> <772FA561-8140-4876-BB3E-C1B8B96F4178@2xlp.com> <200604201624.13355.corey_s@qwest.net> <39F2EE86-5D1C-496E-BE43-D8380BA20328@2xlp.com> Message-ID: <4448A917.90300@thinkfoo.com> Jonathan Vanasco wrote: > i believe that in python you can map the repeat onto a generator or > iterator - i *think* you can figure out a way mimic that it in perl > using petal's method support > > ie, your repeat loop calls a function that returns the next item in > whatever sequence, and petal stops doing that at the end > > its pretty easy to do in python tal, but i'm not sure about the petal > version. I asked the list some time ago about going through cursors in petal. Jean-Michel suggested I tie the cursor to an array, which worked well. I'll have a look for my code but I think it's long gone. https://lists.webarch.co.uk/pipermail/petal/2003-February/000301.html