On 2004.08.12, IRA <[EMAIL PROTECTED]> wrote:
> Automatic digest processor wrote on 8/11/2004, 11:01 PM:
>
> > Has anyone tried to get the asp style ADP parser originally written in
> > like 1999 or 2000 by some guys at AM Computers working with Aolserver
> > 4? The source file was nsAspStyleAdps.c. It allowed conditional code
> > throughout the file separated by the <% %> sequence, in the manner of
> > ASP.
>
> This has always been one of my biggest complaints with aolserver. When
> you have to output html conditionally in adp pages, you have to
> backslash everything to keep tcl from choking on it.
Or, you can use [subst].
> It's just this sort of problem that makes me wonder if the people
> building aolserver ever actually USE aolserver to build web
> applications. It seems like not that big of a deal . . . until you
> realize that we do this ALL THE TIME.
What, use AOLserver to build web applications? :-)
> Here's an example from our code:
>
> if {$vlCountryCode == "DE"} {
> ns_puts "<td background=\"$imageDir/hdr_bg.gif\" valign=\"top\"
> align=\"right\"><a
> href=\"http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541\"
> target=\"top\"><img src=\"$imageDir/btn_helptop.gif\" width=$img2w
> height=$img2h border=0 alt=\"$str6\"></a></td>"
> } elseif {$vlCountryCode == "FR"} {
> ns_puts "<td background=\"$imageDir/hdr_bg.gif\" valign=\"top\"
> align=\"right\"><a
> href=\"http://aolaide.aol.fr/version4/topic/theme6.htm\"
> target=\"top\"><img src=\"$imageDir/btn_helptop.gif\" width=$img2w
> height=$img2h border=0 alt=\"$str6\"></a></td>"
> } else {
> ns_puts "<td background=\"$imageDir/hdr_bg.gif\" valign=\"top\"
> align=\"right\"><a
> href=\"javascript:pop=prntPack('help/help.adp',530,500);\"><img
> src=\"$imageDir/btn_helptop.gif\" width=$img2w height=$img2h border=0
> alt=\"$str6\"></a></td>"
> }
if {$vlCountryCode == "DE"} {
ns_puts [subst {<td background="$imageDir/hdr_bg.gif" valign="top"
align="right"><a
href="http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541"
target="top"><img src="$imageDir/btn_helptop.gif" width=$img2w
height=$img2h border=0 alt="$str6"></a></td>}]
} elseif {$vlCountryCode == "FR"} {
ns_puts [subst {<td background="$imageDir/hdr_bg.gif" valign="top"
align="right"><a
href="http://aolaide.aol.fr/version4/topic/theme6.htm"
target="top"><img src="$imageDir/btn_helptop.gif" width=$img2w
height=$img2h border=0 alt="$str6"></a></td>}]
} else {
ns_puts [subst {<td background="$imageDir/hdr_bg.gif" valign="top"
align="right"><a
href="javascript:pop=prntPack('help/help.adp',530,500);"><img
src="$imageDir/btn_helptop.gif" width=$img2w height=$img2h border=0
alt="$str6"></a></td>}]
}
That at least eliminates the escaping of double-quotes issue. There's
even more ways of refactoring your example to condense it further:
switch $vlCountryCode {
DE { set tag {<a
href="http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541" target="top">} }
FR { set tag {<a href="http://aolaide.aol.fr/version4/topic/theme6.htm"
target="top">} }
default { set tag {<a
href="javascript:pop=prntPack('help/help.adp',530,500);">} }
}
ns_adp_puts [subst {<td background="$imageDir/hdr_bg.gif" valign="top"
align="right">$tag<img src="$imageDir/btn_helptop.gif" width=$img2w
height=$img2h border=0 alt="$str6"></a></td>}]
> Whereas in darn near any other language/appserver out there
> (php,npe,jsp,asp), it would look something like this (syntax varies a
> bit, of course):
>
> <% if $vlCountryCode == "DE" %>
>
> <td background="<%=$imageDir%>/hdr_bg.gif" valign="top" align="right">
> <a
> href="http://www.aol.de/action_templates/globalhelp_1.jsp?cid=1041541"
> target="top"><img src="$imageDir/btn_helptop.gif" width=<%=$img2w%>
> height=<%=$img2h%> border=0 alt="<%=$str6%>"></a></td>
>
> <% elseif $vlCountryCode == "FR" %>
>
> <td background="<%=$imageDir%>/hdr_bg.gif" valign="top" align="right">
> <a href="http://aolaide.aol.fr/version4/topic/theme6.htm"
> target="top"><img src="<%=$imageDir%>/btn_helptop.gif" width=<%=$img2w%>
> height=<%=$img2h%> border=0 alt="<%=$str6%>"></a></td>
>
>
> <% else %>
> <td background="<%=$imageDir%>/hdr_bg.gif" valign="top"
> align="right"><a
> href="javascript:pop=prntPack('help/help.adp',530,500);"><img
> src="<%=$imageDir%>/btn_helptop.gif" width=<%=$img2w%>
> height=<%=$img2h%> border=0 alt="<%=$str6%>"></a></td>
>
> <% endif %>
Matter of preference. I, personally, prefer the second refactoring I
provided above.
> The readability difference may not be so apparent given the lack of
> formatting in this email, but the difference in my text editor (using
> syntax coloring) is tremendous.
Use a better text editor? :-)
-- Dossy
--
Dossy Shiobara mail: [EMAIL PROTECTED]
Panoptic Computer Network web: http://www.panoptic.com/
"He realized the fastest way to change is to laugh at your own
folly -- then you can let go and quickly move on." (p. 70)
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.