Petal
Petal is the PErl Template Attribute Language that MKDoc uses for it's templating system, Petal is hosted on CPAN. To email the Petal list send a message to petal@lists.webarch.co.uk, you may subscribe to the list using the form below, more options are on the Petal listinfo page.
Archives
Latest posts on the Petal list
- Re: Bug report: Dollar follwed by a name gets lost
- Petal is interpolating $variable with parameters passed through ->process(). If you were to pass through 'variable' as a argument you would see it printed. ($1000 and $n are not regarded as valid variable names). E.g. if you were to change the following in your example: my %content_data = (nn => 'foo'); my $task_result = $task->process( \%content_data ); you will see the output: "but nn dollars disappear <b>foo</b>!" I've forgotten if there's a proper way to escape dollar characters in Petal, but one work around would be to use html entites, e.g.: This costs $45 Cheers ~mark
- Bug report: Dollar follwed by a name gets lost
- We are currently starting a new project and would like to use Petal. While doing some exercises to get to know it, i tried to include a small example perl script in a template. To my surprise, variable names in the perl source were lost. After some more tests, I came to this conclusion: $variable IN THE template magically disappears $1000 is ok $n is ok (single letter following a $) <span tal:content="xx">...</span> replaces the content always ok Here is a small example: ---------------------------------- my template: <html xml:lang="en" lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:tal="http://purl.org/petal/1.0/"> <head> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"/> </head> <body> <p> 10 dollars are <b>$10</b>, n dollars are <b>$n</b>, but nn dollars disapear <b>$nn</b>! </p> </body> </html> ---------------------------------- my perl script #!/usr/bin/perl -w use strict; use utf8; bi
- Petal alters XML as if it is XHTML
- Hi, I might be doing something wrong, but when explicitly feeding XML and outputting XML, the result has all self closing tags (e.g. <br />) split into two tags (e.g. <br></br>). How can I stop this from happening? Here is a simple test script: ============================================================== use warnings; use strict; use File::Spec::Functions qw/splitpath/; use File::Temp (); use Petal; print "====\n$Petal::VERSION\n====\n\n"; my $fh = File::Temp->new or die "$< at >\n"; print $fh <<'EOD' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="vi" /> <title>Test Page</title> </head> <body> <p>Paragraph with a<br />break</p> </body> </html> EOD ; my $petal = Petal->new ( base_dir => (splitpath ($fh->filename))[1], file => (splitpath ($fh->filename))[2], inp
- omit-tag -- Petal DOCUMENTATION inconsistency with TAL spec
- I just learned this on another TAL list... regarding omit-tag, the TAL spec states If the expression evaluates to a true value, *** or there is no expression *** ie: no conditional/statement is interpreted as true whereas the Petal implementation states: If you want to ALWAYS remove a tag, you can use omit-tag="string:1" The petal behavior should be If you want to ALWAYS remove a tag, you should use omit-tag="" It looks as if this was implemented in v1.06 -- but the docs were never updated to reflect the correct behavior.
- Petal namespace
- Hi, friends. Is it posible to make additional parameter for Petal constructor. When Petal used in portlets it's two not useful ways: 1. Specifing namespace in first tag of portlet 2. Usinng "petal:" name space instead of "tal:" Is it posible to specify namespaces in constructor? For sample: my $portlet = new Petal (file=>'portlet.xml', namespace => 'tal'); print $portlet->process ({name => 'Ivan'});
- i18nfool-extract does not decode Entities
- Hi. IMHO it should do that. There is no good reason a translator should need to understand entity encoding. Sincerely, Joachim
- Re: i18n:name - How do I use it
- Am Samstag, den 17.02.2007, 18:27 +0000 schrieb Mark Holland: Ah, thx, seems I misunderstood the tal spec. To summarize: i18n:translate translates, i18n:name only does the $ stuff. http://plone.org/documentation/how-to/i18n-for-developers So <p i18n:translate="">First we want to test <span style="font-style: italic;" i18n:name="names" i18n:translate="names">names</span>.</p> does what I want. Sincerely, Joachim
- Re: i18n:name - How do I use it
- Hi Joachim, You need to to use i18n:name in conjunction with a petal:content statement. This will interpolate the contents of the tag with the string store in your pot file. So in your template you have: <p i18n:translate="">First we want to test <span style="font-style: italic;" i18n:name="username" petal:content="user/name">Name</span>.</p> Petal will first go through the template and evaluate all petal: attributes. The output at this point will look like: <p i18n:translate="">First we want to test <span style="font-style: italic;" i18n:name="username">Joachim</span>.</p> Then Petal::I18N will go and process the i18n: attributes, giving you: <p>First we want to test <span style="font-style:italic;">Joachim</span>.</p> or in german: <p>Zuerst wollen wir <span style="font-style:italic;">Joachim</span> testen.</p> I hope this makes sense. Viel spass, ~mark Joachim Zobel wrote:
- i18n:name - How do I use it
- Hi. I have a template containing <p i18n:translate="">First we want to test <span style="font-style: italic;" i18n:name="names">names</span>.</p> If I apply i18nfool-extract, I get msgid "First we want to test ${names}." msgstr "First we want to test ${names}." and manually add msgid "names" msgstr "names" Then I i18fool-update and edit the pot-File for de_DE to msgid "First we want to test ${names}." msgstr "Zuerst wollen wir ${names} testen." msgid "names" msgstr "Namen" However after processing this with Petal I get <p>Zuerst wollen wir <span style="font-style: italic;">names</span> testen.</p> So names is not translated. How do I handle this, or is this a bug (in 2.18). Sincerely, Joachim
- Re: Pluggable expression language
- I don't know what the code is like these days but I plugged in a new TALES compiler a few years ago. I can't remember if the final patches to allow plugins were accepted but if you search the archives for Code::Perl, Petal::Code::Perl and other posts by me around that time you might find the answer, F On 04/02/07, Joachim Zobel <jzobel-vMKf/3N+8/jDUM38hKU9Ng< at >public.gmane.org> wrote:
- Pluggable expression language
- Hi. I am researching for what I call Apache2::TAL. The idea is to implement an apache output filter, that processes XML, putting it into a TAL template. This would be straight forward using Petal if I could plug in another expression language. The natural language in my case is XPath. can this be done? Any hints appreciated. Joachim
- escaping "." in variable names
- Does anyone know if it is possible to use "." in variable names with petal -- and if so, how? i have a dictionary/hash that has some keys that are named "section.subsection" , and I'm trying to get petal to show them // Jonathan Vanasco | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | FindMeOn.com - The cure for Multiple Web Personality Disorder | Web Identity Management and 3D Social Networking | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | RoadSound.com - Tools For Bands, Stuff For Fans | Collaborative Online Management And Syndication Tools | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- PATCH ( was Re: stripping whitespace in templates? )
- attached is a patch ( + the patched petal, in case others have issues reading it ) it adds a strip_whitespace argument to new + a function + documentation it runs a quick boolean check in the sub '_file_data_ref' , which just wraps HTML::Strip::Whitespace templates are quite smaller... on 1 webapp w/ strip_whitespace: 749,416 wo/strip_whitespace:802, 395 so its about a 6.65 % size reduction in a webapp. its only 50k , but under modperl that can be 1MB easily when you're running multiple servers 102,105d101 < # strip whitespace mode < our $STRIP_WHITESPACE = 0; < < 149d144 < local $Petal::STRIP_WHITESPACE = 0; 165d159 < local $Petal::STRIP_WHITESPACE = 0; 179d172 < local $Petal::STRIP_WHITESPACE = 0; 259d251 < sub strip_whitespace { exists $_[0]->{strip_whitespace} ? $_[0]->{strip_whitespace} : $STRIP_WHITESPACE } 361d352 < local $STRIP_WHITESPACE = defined $self->{strip_whitespace} ? $self->{strip_whitespace} : $STRIP_WHITESPACE; 617,629c608,609
- PATCH ( was Re: stripping whitespace in templates? )
- attached is a patch ( + the patched petal, in case others have issues reading it ) it adds a strip_whitespace argument to new + a function + documentation it runs a quick boolean check in the sub '_file_data_ref' , which just wraps HTML::Strip::Whitespace templates are quite smaller... on 1 webapp w/ strip_whitespace: 749,416 wo/strip_whitespace:802, 395 so its about a 6.65 % size reduction in a webapp. its only 50k , but under modperl that can be 1MB easily when you're running multiple servers 102,105d101 < # strip whitespace mode < our $STRIP_WHITESPACE = 0; < < 149d144 < local $Petal::STRIP_WHITESPACE = 0; 165d159 < local $Petal::STRIP_WHITESPACE = 0; 179d172 < local $Petal::STRIP_WHITESPACE = 0; 259d251 < sub strip_whitespace { exists $_[0]->{strip_whitespace} ? $_[0]->{strip_whitespace} : $STRIP_WHITESPACE } 361d352 < local $STRIP_WHITESPACE = defined $self->{strip_whitespace} ? $self->{strip_whitespace} : $STRIP_WHITESPACE; 617,629c608,609
- stripping whitespace in templates?
- does anyone have a suggestion as to how i could create a plugin/ filter that would strip certain kinds of whitespace during the template generation phase? my templates all have a fair amount of spaces / tabs / carriage returns to make templates human readable it also bulks stuff up about 15% ( i haven't tested the space difference using gzip compression, or any difference in speed gzipping a stripped document vs a nonstripped ) it seems to me though, that i could probably cut bandwidth by 7% or so if i regexed my templates, so i'd like to look into it anyone have a clue where i could insert the function? within petal? within mkdoc ?
- Re: new() or process() on a string rather than a file?
- <snip> 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 ) ) Great idea - use whichever is appropriate based on the number of templates necessary per task. Cool. Beers! Corey
- 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
- 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? On Tuesday 26 September 2006 19:03, Corey wrote:
- 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> Did I miss what I'm looking for in the docs somewhere? Or if not, is there some specific reason why processing a string rather than a file is not made possible via Petal? Many thanks! Corey
- 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!
- 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-Rw1WCSvBAmdOfGLsdRflZejAqQFK86Wj< at >public.gmane.org Thank you. - end -
MKDoc Ltd., 31 Psalter Lane, Sheffield, S11 8YL, UK.
Copyright © 2001-2005 MKDoc Ltd.