Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Disturbing GT::Template feature

Quote Reply
Disturbing GT::Template feature
If a template line has only tags in it, which has no inserted content, like <%if ...%>, <%else%>,
<%endif%>, <%loop%>, <%endloop%>... etc., after the template parsing, there will be a blank line as result, instead of removing the helper line, which was inserted only to hold the template tags.
This makes very messy result html pages with much air (linefeeds) in it ...

Let me show an example template code part:
Code:
---------------<br>
<%if category%>
This is the category: <%category%><br>
<%if category%>
---------------<br>


The parsed html result page will be look like:
Code:
---------------<br>

This is the category: Computers/Accessories<br>

---------------<br>
Note the lines in place of the tags...


The displayed html will appear normally:
Code:
---------------
This is the category: Computers/Accessories
---------------

So while the template code is readable easily, the parsed html pages are very unreadable, which makes debugging more difficult. Moreover, if you want to create crossbrowser html pages using tables, which looks the same in IE & NS, the inserted lines makes difficult the template creating work.

Would be possible to correct the template parser in the following condition?:
- if there is a line with template tags and spaces only, which are not inserting real content, like: if, else, endif, loop, endloop, etc. tags. If this is true, then delete the blank line from the parsed html result.

I mean a regexp something like e.g.:
Code:
$text =~ s/\s*<%(^if|^else|^elsif|^end)+%>\s*\n//mgi;
It may be not correct syntactically, but it shows the basic idea.

This bug disturbs me since Links 2.0, and I think it should be corrected.

Would be possible?
This would help, avoiding such problems I had.


Reference to this post is here:
http://www.gossamer-threads.com/...orum.cgi?post=195579

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
>>
So while the template code is readable easily, the parsed html pages are very unreadable,
<<

If I understand what you are saying then no it isn't a bug its a feature...the html is compressed for faster output.
Quote Reply
Re: [Paul] Disturbing GT::Template feature In reply to
Quote:
If I understand what you are saying then no it isn't a bug its a feature...
You may misunderstood this.
It is definitely a bug, but is not so disturbing. It can cause problems when creating templates.
My opinion is, that it is a bug, but I called it as feature, because I don't know original will of Alex.

Quote:
html is compressed
No, html is only compressed, if you turn on html compression in LSQL setup.
I do not want to turn on html compression, while I developing anything, because I want to be able to debug the html files.
The uncompressed html files have a lot holes (blank lines), which makes reading of html file more difficult. This is caused by a bug (better we would call it as feature) in GT::Template.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
Quote:
My opinion is, that it is a bug, but I called it as feature, because I don't know original will of Alex.

This is caused by a bug (better we would call it as feature) in GT::Template.

I so can't tell if you are patronising me or not....but it seems like you are ;)

Guess Im not enough "in-the-know" to answer you :)
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
Hmm I can't actually reproduce what you are saying anyway.

I went and looked at my page source and there were no blank lines so I edited the template and added:

<%if a%><%a%><%endif%>

Now according to what you said i should now have a blank line in my template as <%a%> doesn't exist so the tags will be removed...however I still have no blank lines.
Quote Reply
Re: [Paul] Disturbing GT::Template feature In reply to
Try this format:
Code:
<%if a%>
<%a%><br>
<%endif%>
In place of <%if a%> and <%endif%> the should be blank lines.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [Paul] Disturbing GT::Template feature In reply to
Patronising? I did not understood that word, but I checked in dictionary Smile
If I understand correctly, then not, I'm not patronising you.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
Ok I see the blank line now....Im experimenting with a fix...its not easy...if you look in GT/Template/Parser.pm you'll see why...I may even be looking in the wrong file Cool
Quote Reply
Re: [Paul] Disturbing GT::Template feature In reply to
Glad you was able to reproduce the bug.
As I remember the GT/Template/Parser.pm should be the file which needs to correct.

But as I mentioned the correction is not so easy, because we must only delete only those lines, where there was only non-content related tags, like: if, else, endif, loop, endloop, etc...
We must make sure, that there was only such non-content text in that line, and the result line is blank (with space & tabs & newline maximum), before deleting.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
In GT/Template/Parser.pm around line 226, try adding (red marks the addition)
Code:
while ($TPL =~ /($begin\s*(--(?:(?:$begin\s*--.*?--\s*$end\n?)|.)*?--|.+?)\s*$end\n?)/gsx) { # This allows 1 level of nested <%-- comments --%>
This might do what you want. Use at your own risk....

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [webmaster33] Disturbing GT::Template feature In reply to
Hi,

I don't see the problem. Try this sample:

use GT::Template;
my $s = '<%if a%>
<%a%><br>
<%endif%>';
my $res = GT::Template->parse("foo", {}, { string => $s });
print "res: $res (", length($res), ")\n";

You get a 0 byte string back, there are no new lines added. Everything from the opening if to the endif is removed.

You do NOT want to remove content before an <%if%>, or after an <%endif%>. Only from the if to the endif should be removed.

Can you provide a small sample that produces the bug you are describing?

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] Disturbing GT::Template feature In reply to
Tomorrow I will do some tests and I will come back with the results. This means about 2:00 AM in the servers time.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...