tcl-websh-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@dedasys.com (David N. Welton)
Subject putx substition style
Date Thu, 20 Dec 2001 21:28:52 GMT

I have been looking at the putx code, and wondering about the
suggestion to change it to a group of 'put' statements interspersed
with code to eval.

It's a good idea (mod_dtcl is based around it:-)...

My current thinking on the situation is that there are two good ways
to mix up Tcl and HTML.

1) Using <? ?> (as per
   http://www.w3.org/TR/2000/REC-xml-20001006#sec-pi )

   This is the proper way to do 'processing instructions' for XML.  I
   regard this model as the 'full integration' model, because it lets
   you add things quite naturally to an HTML document, and also
   because it's necessary - at least if you want to be able to loop or
   do conditionals on chunks of HTML outside the <? ?> - to add
   everything up as either bits to execute or 'puts' statements.

2) Substitution, using 'subst' on the text directly.

   This is more immediate, and quicker if one just wants to substitute
   some variable values (possibly having taken care of the logic
   elsewhere).

I would encourage future directions to take after both of these, as
they both have their uses, and to discourage other systems (for
instance, ASP style delimiters, {}, <+, or whatever else).

By the way, what is to be gained from using {} instead of just

web::put " [something blah] ...." ?

For instance:

        web::putx {
            <h1>Top secret session information</h1>
            <dl>
            <dt><b>Id</b>
            <dd>{web::put [web::statef::id]}
            <dt><b>Name</b>
            <dd>{web::put [web::statef::get name]}
            <dt><b>Age</b>
            <dd>{web::put [web::statef::get age]}
        }

Could be 

        web::put [subst {
            <h1>Top secret session information</h1>
            <dl>
            <dt><b>Id</b>
            <dd>[web::statef::id]
            <dt><b>Name</b>
            <dd>[web::statef::get name]
            <dt><b>Age</b>
            <dd>[web::statef::get age]
        }]

The [subst uglifies it a bit, but in reality, you don't even need that
if you just use "" instead of "" (knowing you have to escape the
quotes).

Personally, I am happier when I can rely on native Tcl functionality
to do things for me.

-- 
David N. Welton
   Consulting: http://www.dedasys.com/
Free Software: http://people.debian.org/~davidw/
   Apache Tcl: http://tcl.apache.org/
     Personal: http://www.efn.org/~davidw/

Mime
View raw message