[Prev][Next][Index][Thread]

Re: [OFF] HTML template languages




  I've been thinking over the weekend about the best approach, IMHO,
dylan 
could take to make it a clean language to work with HTML. This is 
actually a pretty daunting task and I have looked at several of the more 
popular langauges that currently are used in this area. All of them have 
their strengths and weaknesses, but the same basic approach is employed
by 
most.
  Most of the current approaches embed code inside web pages in a manner 
like asp or php. Basically you have

<HTML>
<BODY>
<% Response.Write getDate()%>

</BODY>
</HTML>

which is a delimiter for the code sections, namely <% and %>, with the 
code interpreted and specific calls to write out to the html stream. All 
section marked off by <% and %> are considered to be part of the
embedded 
program. While this is the most popular method available now, there
still 
exists some difficulties. The biggest of these is that the code and the
html 
are mixed together, so editing one or the other can be a problem. There
are 
methods of including external files that hold html or code and that
probably 
works best for something like this. But include files break up pages 
unnaturally, as when you use a header or footer include. To edit these,
you 
still need to combine them together and see what they look like in a browser.
  It also has the problem Scott brought up originally of having an
explicit 
write mechanism to a html page. I have used this and didn't think much
of 
it originally, but I agree that it is a strange way to program a page, 
especially if you start the put in 'echo "<H1>".$var_title."</H1><BR>"' 
statements.
  So, what to do? I'd like to propose that with dylan we avoid trying to 
make dylan look like html and just simply treat it as an extension to
html 
by using xml. In other words, remind ourselves that html is describing 
objects and we can embed our own dylan objects to handle any dynamic content.
  For example, what if we had something like this in a page.

<HTML>
<BODY>
The current time is <DYLAN>

get-decoded-time(timezone:600);

</DYLAN>
</BODY>
</HTML>

The result of the get-decoded-time function is a <decoded-time> dylan
object. 
But it fits in well with the other objects declared in this page. By
this, I 
mean that html runs atop of the Document Object Model. This snippet of
html 
is actually creating an HTML object that holds a BODY object, while the
BODY 
object holds the string 'The current time is ' and a dylan object. If we 
could use a parser to create these objects from the html page and
interpret 
the dylan objects it finds, then we could output the proper html by just 
specifying a few write methods inside dylan.
  As another example, take dealing with a collection with html and
dylan. We 
could just have
<TABLE>
	<TR>
	<TH>Population</TH>
	<TH>Zombies</TH>
	<TH>Normal</TH>
	</TR>

<DYLAN>
for (i from 0 below 100,
     zombies from 0 below 100,
     normals from 100 above 0 by -1)
   let population =  zombies + normals;
	<TR>
	<TD>population</TD>
	<TD>zombies</TD>
	<TD>normals</TD>
	</TR>
end;
</DYLAN>
</TABLE>
  The result from the DYLAN object would be a collection of TRs, TDs,
and the 
values which could then be output as html. 
  Also, it would possible to completely remove the code from the html 
document by using an attribute with the DYLAN tag, something like 

<DYLAN HREF="code/date.dylan"></DYLAN>

  I'm just throwing this out as a suggestion and I am sure more thinking 
needs to go into this before anything real can happen. But I think this 
gives us a nice separation between the html and the dylan code while 
still allowing for a lot of flexibility. 

Comments?

James



Follow-Ups: References: