Posted to tcl by colin at Thu May 06 04:56:37 GMT 2010view raw
- # hello-direct - a hello world example of a Direct domain
- namespace eval ::Hello {
- proc / {r args} {
- # this is the default
- set content {
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title>Hello World</title>
- </head>
- <body>
- <h1>Hello World</h1>
- <ul>
- <li><a href='text'>Plain Text</a></li>
- <li><a href='html'>Html Fragment</a></li>
- <li><a href='error'>Intentional Error</a></li>
- <li><a href='redirect'>Redirection</a></li>
- </body>
- </html>
- }
- return [Http Ok $r $content text/html]
- }
- proc /text {r args} {
- # [Http Ok] can return other mime types:
- # Here, text/plain can be used to return just the literal text
- set content {
- <p>Hello World</p>
- }
- return [Http Ok $r $content text/plain]
- }
- proc /html {r args} {
- # Here, content is returned as an x-text/html-fragment
- # which is wrapped and filled in by the Convert module
- # to present an HTML page to the client
- set content {
- <p>Hello World</p>
- }
- return [Http Ok $r $content x-text/html-fragment]
- }
- proc /args {r args} {
- }
- proc /error {r args} {
- # errors are caught and presented to the client
- error "This is an intentional error."
- }
- proc /redirect {r args} {
- # You can redirect URLs using the facilities of the Http utility
- return [Http Moved $r hello] ;# this redirects you to /hello
- }
- proc new {args} {}
- namespace export -clear *
- namespace ensemble create -subcommands {}
- }
- # this line inserts the Hello namespace into the URL space at /hello/
- Nub domain /hello/ Direct namespace ::Hello