I've been putting some thought into what might be useful for a standard
tag library for everyone to use. I thought I'd send in my current
thoughts (along with a very small bit of implementation that I've written):

# Tag: ns:foreach
# Attributess:
#     varList, list pairs
# Description:
#     Evaluates the html inside the tags once for each
#     value in the list, with the value stored in the
#     variable(s) named
# Examples:
#     <!-- a single var and list -->
#         <ns:foreach varName="i" list="a b c">
#             <li><ns:getvar varName="i"/>
#         <ns:foreach>
#     <!-- multiple vars in one list -->
#         <ns:foreach varName="i j" list="a 1 b 2 c 3">
#             <li><ns:getvar varName="i"/> <ns:getvar varName="j"/>
#         <ns:foreach>
#     <!-- multiple var/list pairs
#         <ns:foreach varName="i" list="a b c" varName="j" list="1 2 3">
#             <li><ns:getvar varName="i"/> <ns:getvar varName="j"/>
#         <ns:foreach>
proc taglib::ns_foreach {string tagset} {
     set varName [ns_set get $tagset "varList"]
     set list [ns_set get $tagset "list"]

     upvar #0 $varName iter

     set retval ""
     foreach iter $list {
         append retval \
             [uplevel #0 [list ns_adp_parse $string]]
     }

     return $retval
}

# Tag: ns:getvar
# Attributes:
#     varName - the name of the variable to get the value of
# Description:
#     Replaces the tag with the value of the variable
# Examples:
#     <ns:getvar varName="i"/>
proc taglib::ns_getVar {tagset} {
     uplevel #0 [list set [ns_set get $tagset "varName"]]
}

# Tag: ns:getvar
# Attributes:
#     test - the expression to evaluate
# Description:
#     Evaluates the html within the tags if and only if
#     the specified expression evaluates to true (per expr)
# Examples:
#     <ns:if test="1 == 1">
#         <h1>Yup, 1 is indeed equal to 1</h1>
#     </ns:if>
proc taglib::ns_if {string tagset} {
     # attribs: test
     ...
}

# Tag: ns:include
# Attributes:
#     file - the name of the file to include
# Description:
#     Inserts the contents of another file into the current one,
#     and evaluate the html. Does not create an additional
#     callstack as the tcl command [ns_adp_include "$file"] would.
# Examples:
#     <ns:include "file.inc"/>
proc taglib::ns_include {tagset} {
     set file [ns_set get $tagset "file"]

     ...
}

# Tag: ns:query
# Attributes:
#     sql
# Description:
#     Executes an sql query (against the default db?), the results
#     of which can be used in a <ns:foreach> construct to access
#     the data row by row
# Examples:
#     <ns:foreach varList="row"
#                 list="<ns:query sql="SELECT index, name
#                                      FROM myTable WHERE index > 5"/>">
#         <ns:foreach varList="index,name" list="<ns:getvar
varName="row"/>">
#             <td><ns:getvar varName="index"/></td>
#             <td><ns:getvar varName="name"/></td>
#         </ns:foreach>
#     </ns:foreach>
proc taglib::ns_query {string tagset} {
     ...
}

Also useful would be <ns:for ?varName="..."? start="#" end="#"
?step="#"?>  construct.

Of less useful functionality would be things like while and setVar.

Any thoughts and/or comments are welcome.

Rob Seeger


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

Reply via email to