Click here to get back home

I don't want to write an HTML templating module

 HomeNewsGroups | Search | About
 comp.lang.perl.modules    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
I don't want to write an HTML templating module Hayden Stainsby 08-30-2007
Get Chitika Premium
Posted by Eric Berg on August 30, 2007, 8:56 pm
Please log in for more thread options


Hayden,

It sound like you may want to check out XSLT. I can imagine just
transforming the HTML that you're describing, though I haven't given
much thought to the effort involved in addressing your larger issue of
implementing your stuff in something that's supportable, etc.

If you just need to strip out certain attributes, that'd be really
simple. (Famous last words...)

Alternatively, you could mix XPATH and Perl. XPATH is the spec for
addressing XML documents cannonically. You could, for example, refer to
all UL lists and retrieve them to an array, and then process each of those.

Are you just trying to include instructions for humans in your HTML, or
are these processing instructions?

If you just want to be able to view raw templates in a browser, setting
your tag boundries to something innocuous, like comments could be an
approach for you.

-Eric.

Hayden Stainsby wrote:
> merlyn@stonehenge.com(Randal L. Schwartz) wrote:
>> And that makes it not HTML. If you're already crossing the line,
>> crossit completely. Don't pretend you're not crossing it. :)
>
> There's still a big difference between what I have below, which will
> display correctly most browsers and can be passed around as an example
> of what a page will look like, and what's required when you have code
> (even if it isn't perl code) inside the HTML.
>
> I can give the former to anyone who knows HTML - or anyone who can
> operate Dreamweaver - and they can edit it happily without knowing
> what these extra attributes mean. The second however can only be
> editted by someone who knows the syntax for HTML::Template - or
> another templating module which works in a similar fashion.
>> Hayden> So an HTML template snippet like this:
>
>> Hayden> <ul>
>> Hayden> <li jwcid="list_item">Jackets</li>
>> Hayden> <li jwcid="list_item">Shirts</li>
>> Hayden> <li jwcid="list_item">Ties</li>
>> Hayden> </ul>
>
>> And that's not HTML. You might as well write:
>
>> [% list = ['Jackets' 'Shirts' 'Ties'] %]
>> [% FOR item IN list %]
>> [% "<ul>" IF loop.first %]
>> <li> [% item %] </li>
>> [% "</ul>" IF loop.last %]
>> [% END # foreach %]
>
> But thanks for pointing out my stepping over lines and such. (-:
>
>

Posted by Hayden Stainsby on August 31, 2007, 5:19 am
Please log in for more thread options


> Hayden,

> It sound like you may want to check out XSLT. I can imagine just
> transforming the HTML that you're describing, though I haven't given
> much thought to the effort involved in addressing your larger issue
> of implementing your stuff in something that's supportable, etc.

> If you just need to strip out certain attributes, that'd be really
> simple. (Famous last words...)

I've used XSLT previously - although only for creating XSL-FO, I'll
have look into it and see how well I can make it mash the data that I
want together.
> Alternatively, you could mix XPATH and Perl. XPATH is the spec for
> addressing XML documents cannonically. You could, for example, refer
> to all UL lists and retrieve them to an array, and then process each
> of those.

> Are you just trying to include instructions for humans in your HTML,
> or are these processing instructions?

> If you just want to be able to view raw templates in a browser,
> setting your tag boundries to something innocuous, like comments
> could be an approach for you.

I'm just after instructions for machine processing, but the catch is
the template should look exactly the same as a page would in a browser
- providing you fill it in with appropriate sample data. Elsewhere in
this thread the semantics of what constitutes HTML are being
discussed, however what I'm interested in is what a browser displays -
and we all know that most browsers are far more leniant than the HTML
spec.

So, in an ideal world a web developer makes me a template. It consists
of a page heading, a list and a table with three columns and some
number of rows more than 1. Attributes are added (in this case 'myid')
to the important tags to let the processor know that they're the same
- but they won't effect the way a page is displayed in most web
browsers:


<h2 myid="heading1">Sample heading</h2>

<ul>
<li myid="list1">Item 1</li>
<li myid="list1">Item 2</li>
<li myid="list1">Item 3</li>
</ul>

<table>
<tr>
<td myid="tcell1">Item 1</td>
<td myid="tcell1">Item 2</td>
<td myid="tcell1">Item 3</td>
</tr>
<tr>
<td myid="tcell1">Item 4</td>
<td myid="tcell1">Item 5</td>
<td myid="tcell1">Item 6</td>
</tr>
</table>

Now I take my data. I have a page title which I link to
myid="heading1" and that gets substituted in there.

I also have a list of 18 (because I only want multiples of 3) names of
items, I link this to both myid="list1" and myid="tcell1" and my
output will go and give me an un-numbered list with my 18 items in it,
and a table with the same 18 items - split into 6 rows each with 3
cells on the row, because that's what my template looked like.

As I said to begin with - I'm just looking to see if there's a way of
doing this in an existing module, I know it's kind of a big ask.

I'll go look at XSLT/XPATH in more depth now, thanks.

--
Hayden


--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo


Posted by Peter Scott on August 31, 2007, 7:28 am
Please log in for more thread options


On Thu, 30 Aug 2007 16:40:59 +0000, Hayden Stainsby wrote:
> There's still a big difference between what I have below, which will
> display correctly most browsers and can be passed around as an example
> of what a page will look like, and what's required when you have code
> (even if it isn't perl code) inside the HTML.
>
> I can give the former to anyone who knows HTML - or anyone who can
> operate Dreamweaver - and they can edit it happily without knowing
> what these extra attributes mean. The second however can only be
> editted by someone who knows the syntax for HTML::Template - or
> another templating module which works in a similar fashion.

I don't see how that's any different from someone having to learn the
syntax for Tapestry, like the example I found at
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/resources/t5-tutorial.pdf?revision=552890

<body>
<t:if test="message">
<p>
<strong>$</strong>
</p>
</t:if>
<p> Guess a number between one and ten: </p>
<t:loop source="1..10" value="index">
<t:actionlink context="index">$</t:actionlink>
</t:loop>
</body>

They still have to know about all the <t:...> tags.

I have used HTML::Template on a project where the HTML editing person used
Dreamweaver. I just made bare bones pages for them and explained the
function of the <TMPL_VAR>, <TMPL_IF>, and <TMPL_LOOP> tags in about five
minutes so they knew how they could move them around. This was a very
successful arrangement; I never had to look at the HTML layout except
on rare occasions when the behavior changed.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Posted by Hayden Stainsby on August 31, 2007, 7:49 am
Please log in for more thread options


> On Thu, 30 Aug 2007 16:40:59 +0000, Hayden Stainsby wrote:
>> There's still a big difference between what I have below, which
>> will display correctly most browsers and can be passed around as an
>> example of what a page will look like, and what's required when you
>> have code (even if it isn't perl code) inside the HTML.
>>
>> I can give the former to anyone who knows HTML - or anyone who can
>> operate Dreamweaver - and they can edit it happily without knowing
>> what these extra attributes mean. The second however can only be
>> editted by someone who knows the syntax for HTML::Template - or
>> another templating module which works in a similar fashion.

> I don't see how that's any different from someone having to learn
> thesyntax for Tapestry, like the example I found at

> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/resourc
> es/t5-tutorial.pdf?revision=552890

> <body>
> <t:if test="message">
> <p>
> <strong>$</strong>
> </p>
> </t:if>
> <p> Guess a number between one and ten: </p>
> <t:loop source="1..10" value="index">
> <t:actionlink context="index">$</t:actionlink>
> </t:loop>
> </body>

> They still have to know about all the <t:...> tags.

My apologies, looks like tapestry doesn't always behave exactly the
way I thought it did, I've not actually used it myself. Of course now
I look like an idiot, but the way I've seen it working is without any
of the <t:> tags.

You define attributes and then the Java code handles all the control -
so there aren't any control structures in the HTML - just plain HTML
(excluding these attributes, which are ignored my most browsers).

I've posted an example of the functionality I originally looking for
further down in response to Eric Berg's post.

--
Hayden



--
I'm trying a new usenet client for Mac, Nemo OS X.
You can download it at http://www.malcom-mac.com/nemo


Posted by Peter Scott on September 1, 2007, 9:57 am
Please log in for more thread options


On Fri, 31 Aug 2007 11:49:49 +0000, Hayden Stainsby wrote:
>> I don't see how that's any different from someone having to learn
>> thesyntax for Tapestry, like the example I found at
>
>> http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/src/site/resourc
>> es/t5-tutorial.pdf?revision=552890
>
>> <body>
>> <t:if test="message">
>> <p>
>> <strong>$</strong>
>> </p>
>> </t:if>
>> <p> Guess a number between one and ten: </p>
>> <t:loop source="1..10" value="index">
>> <t:actionlink context="index">$</t:actionlink>
>> </t:loop>
>> </body>
>
>> They still have to know about all the <t:...> tags.
>
> My apologies, looks like tapestry doesn't always behave exactly the
> way I thought it did, I've not actually used it myself. Of course now
> I look like an idiot, but the way I've seen it working is without any
> of the <t:> tags.
>
> You define attributes and then the Java code handles all the control -
> so there aren't any control structures in the HTML - just plain HTML
> (excluding these attributes, which are ignored my most browsers).

So your program won't ever want to output a variable number of output
elements, like, say, rows in a table? Sounds pretty elementary. But most
applications do want to do that, and so they need control structures. If
you want to output one table row for each hit on a search, you're going to
have something like

<TABLE><TMPL_LOOP NAME="hits">
<TR><TD><TMPL_VAR NAME="name"></TD><TD><TMPL_VAR NAME="value></TD></TR>
</TMPL_LOOP></TABLE>

If you try and represent that by stuffing it into attributes instead it's
going to look horrible. That's why Tapestry has the <t:...> tags.

Since you *do* have control structures, then it appears equally easy or
difficult to use the <t:...> tags as HTML::Template's <TMPL_LOOP>
and <TMPL_IF> tags. Since the latter don't contain punctuation in their
element names, they're likely to be *more* compatible with HTML tools than
Tapestry.

So I don't see any compelling advantage of Tapestry, which is likely why
no one's written a Perl template module for it, because we certainly have
template modules for everything else under the sun. Anyone who edits
Tapestry source has to know the syntax including what jwcid attributes to
use where, and frankly it looks like the whole syntax would take a bit
longer for an HTML author to learn than the five minutes it would for me
to explain HTML::Template's <TMPL_VAR>, <TMPL_LOOP>, and <TMPL_IF> to
someone, which are enough for 99% of applications.

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


Similar ThreadsPosted
Best HTML Templating Module July 17, 2005, 6:04 pm
Request for naming help (templating module) September 8, 2005, 11:34 pm
write a new module for suffix trees? April 3, 2008, 5:12 pm
"reverse templating" or "auto-meta-regex" module for automated screen-scrape learning? September 18, 2007, 10:09 pm
[RFC] Data::Endian (proposal for module to read/write big-endian floats/doubles) July 3, 2007, 5:26 pm
SerialPort write question October 28, 2004, 11:52 am
Tie::YAML doesn't write to tmp file first? December 23, 2007, 9:34 am
How to write into existing Excel Spreadsheets? July 13, 2004, 1:24 pm
Can I write Macros in excel workbook ? October 8, 2004, 7:50 am
Namespace for new module: HTML::Template::HTX? May 13, 2005, 7:17 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap