On Sun, Oct 26, 2003 at 07:46:23AM -0800, Sagara Wijetunga wrote:
> 3.    Finally, parse the HTML template and replace all
> tags with HTML fragments generated.
> Eg. Replace ${INBOX} with the HTML fragment generated.

What you have basically described is the function do_output_form_loop() in
sqwebmail/sqwebmail.c (you said to assign the HTML fragments to an
associative array and insert them when required; do_output_form_loop
generates them on the fly, but conceptually they are the same approach)

So I don't think what you propose would be any improvement.

I can see the following improvements which could be made:

1. Separate content entirely from layout, using CSS only. See examples at
http://www.csszengarden.com/ - all these styles use *exactly* the same HTML,
and differ only in the stylesheet (and it views great in a text-only browser
too). Visual customisation then could be done simply by creating a
stylesheet, and without meddling with templates.

2. Remove all English language text from the templates, and replace with
pointers into a dictionary file. Translators then don't need to touch the
template HTML/XML, only the dictionary. If a new feature is added to
sqwebmail, and the appropriate term is not available in the chosen language,
then it can default to displaying English; if the templates are changed or
improved, but don't use any new phrases, then the improved templates will
work in *all* languages immediately.

Side benefit: login.html/expired.html/invalid.html can be replaced with a
single page, containing a text field. The main code can choose a message
from the dictionary and insert it into the page, if displaying the page
after a login failure.

The above two improvements would be great and not require much change to
code, just careful restructing of the templates and HTML snippets in the C
source.

Optionally, step 3 would be to remove all embedded HTML from the C code, and
move it into the templates. This would require a templating engine, which I
personally would model on Ruby's Amrita: the templates might look something
like this

    <tr id="indexrow">
      <td><span id="from"></span></td>
      <td><span id="subject"></span></td>
      <td><span id="date"></span></td>
    </tr>

This would be parsed so that the C code could create a an array of
[from,subject,date] tuples and then bind it to the HTML; the HTML would be
inserted as many times as necessary, once for each array element. This gives
HTML with "loops" needed for handling headers, the folder index, and so on.
The 'id' attributes would be stripped out of the final (X)HTML.

For efficiency, the XML could be pre-parsed and compiled into a binary form
which could be read in quickly and the data quickly inserted into the
templates.

Regards,

Brian.

Reply via email to