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 Re: putx substition style
Date Fri, 21 Dec 2001 14:39:19 GMT
Ronnie Brunner <ronnie@netcetera.ch> writes:

> > 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.

> This makes sense and is kind of what we now have in the form of { }
> or <% %>. I have no problem with declaring this being <? ?>. Right
> now we provide even a configuration option, so in principle we can
> provide almost any combination. One thing that we do not have is
> that you can actually place your code *around* HTML. We only allow
> it *in* HTML:

Yes, you have to divide things up into little chunks of Tcl, and then
eval them, if you want to place code around HTML, which was probably
the motivation for this feature request.

> we do not have:
>    <? set x 0 
>       while { $x < 5 } { 
>         web::put "\$x = $x<br>" ?>

>    LOOP<br>

>    <? incr x } ?>

That's one of the first things I borrowed from PHP when implementing
mod_dtcl.

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

...

> This is a more complicated issue...

> > 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]}
> >         }

> web::putx is what's needed to "eval" some HTML code. In your first
> example, web::putx would be needed to "eval" a template such as

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

> in general, what we run putx on can be a complete file (putxfile) or a
> template sniplet or whatever.

Ok, so putx is what we can associate with the 'full' style (1).  That
makes sense.

> > 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]
> >         }]

> This is uncool for the above eyample, because I don't want to care
> about escaping the use of '[' and '$' in a template. The template must
> be plain HTML (or XML ...) w/o any special escaping

Ok, but you worry about escaping {} as it is now, or <?, or whatever.

Personally, when using 'subst' style things, I think it might be a
good idea to limit yourself to just commands, as [] stick out to a tcl
programmers eye, and let you do most all of what you need without
worrying about \ and $.

> However, using it from whithin code, we would certainly take this
> approach and just implement this as

>         web::put "
>             <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]
>         "

> But this is a different thing: here we just put a string, whereas in
> the first example, we want to process a template.

Ok, but what line are you drawing between the two?  I haven't fully
formed my thoughts on the subject, but find myself using both.

The first style lends itself more towards heavy intermixing of Tcl and
HTML, whereas the second is a bit more immediate if it's just a string
that needs some values inserted.  One of the things I do like about
the second style is that it can, if used properly, encourage you to
keep your logic in one place, and then just 'parse file.ttml' or
something like that.

> In conclusion, I'm not sure whether it makes sense to have three
> different types of output generation as you suggest:
> 	  - process template (web::putx)
> 	  - output a string (web::put)

> 	  - subst and output a string (not implemented)
> imho: forget about the "web::subst_n_put".

We are in agreement, then.  I will try and produce a version of putx
that uses <? ?> and seperate blocks of code, with html code just being
put statements.

-- 
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