[Petal] Petal and HTML Tidy

William McKee william@knowmad.com
Thu, 8 Aug 2002 12:26:36 -0400


--Message-Boundary-11948
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Mail message body

On 8 Aug 2002 at 12:08, Jean-Michel Hiver wrote:
> You got it the wrong way around haven't you? :-) Effectively it's
> screwed up, but that's the template's fault, not tidy's.

Yes, I do. So, you're saying that embedding xml tags inside of html 
attributes is illegal? I can see where that would be the fault of the 
Petal template. Kinda loses the appeal of using Petal though if we can't 
create valid html with it. If tidy is messing up these tags, wouldn't a 
GUI html editor do the same? I suppose you're going to say to use the $tag 
format <g>.


> Anyway, the new string: modifier should be your friend.

Although I'm against having the simple syntax or variable interpolation 
embedded directly into templates, I can see where having these values 
inside of attribute tags is ok. It's what you are calling the usual 
syntax, which is essentially a valid xml tag I believe, which is causing 
tidy to think this is invalid html and try to clean it up.

> 
> 
> Try:

Ok, so I tried using the variable interpolation inside of these attribute 
properties. Still no joy. Tidy is turning:

<a href="string:$scriptname?rm=edit_coach&coach_id=$coach.coach_id">

into:

<a href="string:$scriptname?rm=edit_coach&amp;coach_id=$coach.coach_id">

Notice the & is replaced by &amp; in the tidied version. I haven't tested 
this with Petal yet so it may not be correct Petal syntax, but I just want 
to clear up issues with tidying these templates first. This seems like a 
problem with tidy. Or is it? Perhaps that's a valid URL. Any HTTP experts 
out there? My tests seem to indicate it is an acceptable format for the 
browsers, but is it a valid URL?

BTW, Tidy does not mess with <?petal:var name="foo"?> tags that are on 
their own. From what I've seen, it just reformats them if they are in an 
attribute property.

> If it does not work, tell me, because I'd see it as a bug.

Ok, I've done some testing in Petal and there's some bugs in the string 
modifier. I've attached a test.cgi and template for you to see for 
yourself.

NB: I had to force Petal to use the HTML parser. I was getting an error if 
I did not set this value in the test.cgi script. Try commenting out that 
line and see if you get an error. It may be due to my messing with adding 
support for instantiation variables. I'm still using a hacked copy of 
Petal.pm. Looking forward to 0.6!

Thanks,
William

-- 
 Lead Developer
 Knowmad Services Inc. || Internet Applications & Database Integration
 http://www.knowmad.com
 



--Message-Boundary-11948
Content-type: text/plain; charset=US-ASCII
Content-transfer-encoding: 7BIT
Content-description: Text from file 'test.cgi'

#!/usr/bin/perl
#
use strict;
use Petal;
use CGI::Carp qw/fatalsToBrowser/;

my $template_file = 'test.tmpl';
$Petal::DISK_CACHE = 0;
$Petal::MEMORY_CACHE = 0;
$Petal::TAINT = 1;
$Petal::BASE_DIR = './';
$Petal::PARSER = "HTML";
my $template = new Petal ($template_file);


my $hash = {
	error_message => "Kilroy was Here",
	first_name => "William",
	last_name => "McKee",
	email => 'william@knowmad.com',
	students => [ { student_id => '1',
					first_name => 'William',
					last_name => 'McKee',
					email => 'william@knowmad.com',
					},
				  { student_id => '2',
					  first_name => 'Elizabeth',
					  last_name => 'McKee',
					  email => 'elizabeth@knowmad.com',
					},
				],
};
my $html = $template->process($hash);
print "Content-type: text/html\n\n";
print $html;

--Message-Boundary-11948
Content-type: text/plain; charset=US-ASCII
Content-disposition: inline
Content-description: Attachment information.

The following section of this message contains a file attachment
prepared for transmission using the Internet MIME message format.
If you are using Pegasus Mail, or any another MIME-compliant system,
you should be able to save it or view it from within your mailer.
If you cannot, please ask your system administrator for assistance.

   ---- File information -----------
     File:  test.tmpl
     Date:  8 Aug 2002, 12:21
     Size:  3983 bytes.
     Type:  Unknown

--Message-Boundary-11948
Content-type: Application/Octet-stream; name="test.tmpl"; type=Unknown
Content-disposition: attachment; filename="test.tmpl"
Content-transfer-encoding: BASE64

PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iaXNvLTg4NTktMSI/Pg0KPCEtLT8NCiMg
ICAgIFRlbXBsYXRlOiB0ZXN0LnRtcGwNCiMgICAgICBDcmVhdGVkOiAwNy0yMy0yMDAyDQoj
ICAgICBNb2RpZmllZDogMDctMjQtMjAwMg0KIyAgICAgICBBdXRob3I6IHdsbQ0KIyAgRGVz
Y3JpcHRpb246IFRlbXBsYXRlIHRvIGRvIHRlcnJpY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