On Sun, Oct 26, 2003 at 11:38:47PM -0600, James A Baker wrote:
> Hmm... I've wondered about this (removing all code from the C files)
> myself previously. But I don't think it's practical at this time.
> That's a *lot* of C code to change. And probably you'd need to rewrite
> code in a fairly significant way in some cases where the logic would
> have to be updated to deal with the change.
I agree; I put it in as a logical conclusion, but the maximum benefit for
minimum work would be realised from the first two steps.
> Furthermore, I personally don't especially like the idea of using HTML
> tags as placeholders for other content. It seems nice at first, in that
> it leaves you with pure HTML for the templates... But then you have to
> worry about making sure ID names aren't replicated in the document
> (i.e. "real" tags sharing a namespace with "replacement" tags),
> recognizing which tags are "replacement" tags and which aren't when you
> come back to change templates later
I don't understand that; the replacement tags *are* the real tags. A
<tr id="foo"> in the template is replaced by <tr> in the output, and so on.
Any HTML tag can be bound to a source data item by adding an 'id' attribute.
There is a small optimisation in that "<span>xxx</span>" can be replaced by
"xxx" if there are no attributes in the <span> tag, but other than that,
what's in the template is what appears in the output.
Here's a small Ruby/Amrita program to demonstrate the idea: in Ruby, [...]
is an array, and {...} is a hash.
------------------------------------------------------------------------
#!/usr/local/bin/ruby -w
require 'amrita/template'
my_data = {
:message => "Login OK",
:folderindex => [
{
:from=>"[EMAIL PROTECTED]",
:subject=>"Your nomination",
:date=>"04 Jul 2003",
},
{
:from=>"[EMAIL PROTECTED]",
:subject=>"Today's Digest",
:date=>"27 Oct 2003",
},
],
}
my_template = Amrita::TemplateText.new(<<EOS)
<html>
<body>
<h1>Folder index</h1>
<h3 id="message"></h3>
<table>
<tr id="folderindex">
<td id="from" class="from"></td>
<td id="subject" class="subject"></td>
<td id="date" class="date"></td>
</tr>
</table>
</body>
</html>
EOS
my_template.expand($stdout, my_data)
------------------------------------------------------------------------
This program produces the following output:
<html>
<body>
<h1>Folder index</h1>
<h3>Login OK</h3>
<table>
<tr>
<td class="from">[EMAIL PROTECTED]</td>
<td class="subject">Your nomination</td>
<td class="date">04 Jul 2003</td>
</tr><tr>
<td class="from">[EMAIL PROTECTED]</td>
<td class="subject">Today's Digest</td>
<td class="date">27 Oct 2003</td>
</tr>
</table>
</body>
</html>
Notice that <tr id="folderindex"> is a compound item in the template - it
contains nested tags also with id attributes - and hence it is bound to a
compound source data structure (a hash of id=>value pairs, or actually an
array of hashes of id=>value pairs)
If the item :message=>"Login OK" had been omitted, or changed to
:message=>nil, then the <h3> tag would have been removed entirely from the
output. This easily allows conditional inclusion of HTML, and things like
different styles for odd/even rows of a folder index.
Regards,
Brian.