object-verb.extension
For example, the page to erase a user's portrait from the database is /admin/users/portrait-erase.tcl
.
object.extension
For example, the page to view the properties of an ecommerce product is /ecommerce/product.tcl
.
/bookmarks/
directory, it would be redundant to name the page for editing a bookmark bookmark-edit.tcl
(which would result in the URL bookmarks/bookmark-edit.tcl
. Instead, we omit the object type, and use the convention:
verb.extension
Thus, the page to edit a bookmark is /bookmarks/edit.tcl
.
one.extension
For example, the page to view one bookmark is /bookmarks/one.tcl
.
foobar.extension
(Step 1)foobar-2.extension
(Step 2)foobar-N.extension
(Step N)where foobar
is determined by the above rules.
Typically, we build three-step page flows:
/www/doc/sql
, and name them using the convention:
module.sql
module-procs.tcl
ad-description-procs.tcl
user-delete
instead of user-delete.tcl
), because they enhance maintainability.
Similarly, when linking to the index page of a directory, do not explicitly name the index file (index.tcl
, index.adp
, index.html
, etc.). Instead, use just the directory name, for both relative links (subdir/
) and absolute links (/top-level-dir/
). If linking to the directory in which the page is located, use the empty string (""
), which browsers will resolve correctly.
File Headers and Page Input
Include the appropriate standard header in all scripts. The first line should be a comment specifying the file path relative to the ACS root directory. e.g.
# /www/index.tclor
# /tcl/module-defs.tcl
For static content files (html or adp), include a CVS identification tag as a comment at the top of the file, e.g.
ad_page_contract
after the file path comment (this supersedes set_the_usual_form_variables
and ad_return_complaint
). Here is an example of using ad_page_contract, which serves both documentation and page input validation purposes:
# www/register/user-login-2.tcl ad_page_contract { Verify the user's password and issue the cookie. @param user_id The user's id in users table. @param password_from_from The password the user entered. @param return_url What url to return to after successful login. @param persistent_cookie_p Specifies whether a cookie should be set to keep the user logged in forever. @author John Doe () @cvs-id standards.adp,v 3.7.2.6 2000/07/29 20:36:34 ron Exp } { user_id:integer,notnull password_from_form:notnull {return_url {[ad_pvt_home]}} {persistent_cookie_p f} }
Salient features of ad_page_contract
:
foo:integer,multiple,trim
. In particular, multiple
and array
are the flags that correspond to the old ad_page_variables
flags.trim
, notnull
and optional
. They do what you'd expect; values will not be trimmed, unless you mark them for it; empty strings are valid input, unless you specify notnull; and a specified variable will be considered required, unless you declare it as optional.integer
and sql_identifier
will make sure that the values supplied are integers/sql_identifiers. The integer
flag will also trim leading zeros. Note that unless you specify notnull
, both will accept the empty string.ad_page_contract
does not generate QQvariables, which were automatically created by ad_page_variables and set_the_usual_form_variables. The use of bind variables makes such previous variable syntax obsolete.
ad_library
after the file path comment. Its only argument is a doc_string in the standard (javadoc-style) format, like ad_page_contract
. Don't forget to put the @cvs-id in there. Here is an example of using ad_library:
# tcl/wp-defs.tcl ad_library { Provides helper routines for the Wimpy Point module. @author John Doe () @cvs-id standards.adp,v 3.7.2.6 2000/07/29 20:36:34 ron Exp }
Of course, replace "-- path relative to the ACS root directory -- -- brief description of the file's purpose -- -- author -- created -- -- $Id$
--
" with the comment delimiter appropriate for the language in which you are programming.
Page Construction
Construct the page as one Tcl variable (name it page_content
), and then send it back to the browser with one call to doc_return
, which will call db_release_unused_handles prior to executing ns_return, effectively combining the two operations.
For example:
set page_content "[ad_header "Page Title"]Page Title
" db_foreach get_row_info { select row_information from bar } { append page_content "
[ad_footer]" doc_return 200 text/html $page_content- row_information\n" } append page_content "
The old convention was to call ReturnHeaders
and then ns_write
for each distinct chunk of the page. This approach has the disadvantage of tying up a scarce and valuable resource (namely, a database handle) for an unpredictable amount of time while sending packets back to the browser, and so it should be avoided in most cases. (On the other hand, for a page that requires an expensive database query, it's better to call ad_return_top_of_page
first, so that the user is not left to stare at an empty page while the query is running.)
Local procedures (i.e., procedures defined and used only within one page) should be prefixed with "module_
" and should be used rarely, only when they are exceedingly useful.
All files that prepare HTML to display should end with [ad_footer] or [module_footer]. If your module requires its own footer, this footer should call ad_footer within it. Why? Because when we adapt the ACS to a new site, it is often the case that the client will want a much fancier display than the ACS standard. We like to be able to edit ad_header (which quite possibly can start a