Difference between revisions of "AOLserver and Tcl Crash Course"

From AOLserver Wiki
Jump to navigation Jump to search
(added the "hello world" ADP example)
m (outdent code examples)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
== Draft Outline ==
+
{{TOCright}}
  
* ADP Pages
+
The following is a working draft in progress for an introductory guide to AOLserver and Tcl.
** Hello <Yourname> - Simple page, user submits form, displays name
 
*** DOSSY: Create this example with very simple Tcl.
 
  
  # hello-world.adp
+
== ADP Pages ==
  <% set name [ns_queryget name "world"] %>
 
  <html>
 
  <head>
 
    <title>Hello <%= [ns_quotehtml $name] %>!</title>
 
  </head>
 
  <body>
 
    <p>Hello <%= [ns_quotehtml $name] %>!</p>
 
    <form>
 
    <p>Name: <input name="name" value="<%= [ns_quotehtml $name] %>"></p>
 
    <p><input type="submit" value="Go"></p>
 
    </form>
 
  </body>
 
  </html>
 
  
  # hello-world.tcl
+
Hello <Yourname> - Simple page, user submits form, displays name
  set form [ns_getform]
+
 
  set name [string trim [ns_set get $form name]]
+
=== ADP example ===
  if {$name eq ""} {
+
 
      set name "world"
+
hello-world.adp:
  }
+
 
  ns_return 200 text/html "<html>
+
<pre>
      <head><title>Hello [ns_quotehtml $name]!</title></head>
+
<% set name [ns_queryget name "world"] %>
      <body>
+
<html>
      Hello [ns_quotehtml $name]!
+
<head>
      <form action='hello-world.tcl' method='post'>
+
  <title>Hello <%= [ns_quotehtml $name] %>!</title>
      Name: <input name='name' value='[ns_quotehtml $name]'>
+
</head>
      <input type='submit'>
+
<body>
      </form>
+
  <p>Hello <%= [ns_quotehtml $name] %>!</p>
      </body>
+
  <form>
      </html>"
+
  <p>Name: <input name="name" value="<%= [ns_quotehtml $name] %>"></p>
 +
  <p><input type="submit" value="Go"></p>
 +
  </form>
 +
</body>
 +
</html>
 +
</pre>
 +
 
 +
=== Tcl example ===
 +
 
 +
hello-world.tcl:
 +
 
 +
<pre>
 +
set name [ns_queryget name "world"]
 +
ns_return 200 text/html "<html>
 +
  <head>
 +
    <title>Hello [ns_quotehtml $name]!</title>
 +
  </head>
 +
  <body>
 +
    <p>Hello [ns_quotehtml $name]!</p>
 +
    <form>
 +
    <p>Name: <input name="name" value="[ns_quotehtml $name]"></p>
 +
    <p><input type="submit" value="Go"></p>
 +
    </form>
 +
  </body>
 +
  </html>"
 +
</pre>
 +
 
 +
== Tcl Basics ==
  
* Tcl Basics
 
 
** Explain Minimalist Syntax
 
** Explain Minimalist Syntax
 
*** Commands, Subcommands (Evaluated and Non-Evaluated)
 
*** Commands, Subcommands (Evaluated and Non-Evaluated)
Line 44: Line 55:
 
*** if, while, etc.
 
*** if, while, etc.
 
*** procedures
 
*** procedures
* Fetching GET and POST
+
 
 +
== Fetching GET and POST ==
 +
 
 
** Including / Referring to other pages
 
** Including / Referring to other pages
 
** Controlling Output
 
** Controlling Output
Line 53: Line 66:
  
 
== Questions ==
 
== Questions ==
 +
 
* Where does ADP excel?
 
* Where does ADP excel?
 
* What practices should PHP, ASP, JSP developers stop doing?
 
* What practices should PHP, ASP, JSP developers stop doing?

Latest revision as of 03:09, 16 June 2007

The following is a working draft in progress for an introductory guide to AOLserver and Tcl.

ADP Pages

Hello <Yourname> - Simple page, user submits form, displays name

ADP example

hello-world.adp:

<% set name [ns_queryget name "world"] %>
<html>
<head>
  <title>Hello <%= [ns_quotehtml $name] %>!</title>
</head>
<body>
  <p>Hello <%= [ns_quotehtml $name] %>!</p>
  <form>
  <p>Name: <input name="name" value="<%= [ns_quotehtml $name] %>"></p>
  <p><input type="submit" value="Go"></p>
  </form>
</body>
</html>

Tcl example

hello-world.tcl:

set name [ns_queryget name "world"]
ns_return 200 text/html "<html>
  <head>
    <title>Hello [ns_quotehtml $name]!</title>
  </head>
  <body>
    <p>Hello [ns_quotehtml $name]!</p>
    <form>
    <p>Name: <input name="name" value="[ns_quotehtml $name]"></p>
    <p><input type="submit" value="Go"></p>
    </form>
  </body>
  </html>"

Tcl Basics

    • Explain Minimalist Syntax
      • Commands, Subcommands (Evaluated and Non-Evaluated)
      • Working with variables set, expr
    • Control Structures
      • if, while, etc.
      • procedures

Fetching GET and POST

    • Including / Referring to other pages
    • Controlling Output
    • Databases
      • Defining the connection from as a pool in the config.tcl
      • Selecting from the pool
      • Executing Queries, Retrieving Values

Questions

  • Where does ADP excel?
  • What practices should PHP, ASP, JSP developers stop doing?
  • How can one use Tcl to write very concise and readable code?
  • How does one efficiently separate pages into MVC components if the wanted?
  • How and why should one write a domain specific sublanguage?