rivet-3.3.1/doc/examples.rvt 000664 001750 001751 00000006762 15245054302 016555 0 ustar 00manghi manghi 000000 000000
| Rivet examples |
These are some examples, rather limited ones, of what can be done with Rivet.
Hello world | |
<? cookie "foo" "bar" # we have to put this before any 'puts' statements puts "Hello world" ?> | |
|
Produces:
headers setcookie "foo" "bar" puts "hello world" ?>
| |
Conditionals: | |
<? if { 1 } { ?>
<h2> True </h2>
<? } ?>
| |
|
Produces:
if { 1 } { ?> True} ?> | |
Loops: | |
<?
set x 0
while { $x < 5 } {
puts "\$x = $x<br>"
incr x
?>
LOOP<br>
<? } ?>
| |
| Produces:
set x 0
while { $x < 5 } {
puts "\$x = $x | |
Variables (environmental as well as those passed to the script)
| |
<?
hgetvars
if { [ array exists VARS ] } {
puts "< ul>"
foreach { vr } [ array names VARS ] {
puts "<li>(VARS) $vr = $VARS($vr)"
}
puts "</ul>"
}
if { [ array exists ENVS ] } {
puts "<ul>"
foreach { vr } [ array names ENVS ] {
puts "<li>(ENVS) $vr = $ENVS($vr)"
}
puts "</ul>"
}
if { [ array exists COOKIES ] } {
puts "<ul>"
foreach { vr } [ array names COOKIES ] {
puts "<li>(COOKIES) $vr = $COOKIES($vr)"
}
puts "</ul>"
}
?>
| |
| Produces: hgetvars if { [ array exists VARS ] } { puts "
| |
Create a table on the fly
| |
<?
set i 1
puts "<table>\n"
while { $i <= 8 } {
puts "<tr>\n"
for {set j 1} {$j <= 8} {incr j} {
set num [ expr $i * $j * 4 - 1]
puts [ format "<td bgcolor=%2x%2x%2x > $num $num $num </td>\n" $num $num $num ]
}
incr i
puts "</tr>\n"
}
puts "</table>\n"
?>
| |
| Produces: set i 1 puts "
| |
In addition There are many, many other things you can do with Rivet. You can, if everything is compiled right, load tcl modules, like libpgtcl.so (the Postgresql interface), so that you can interact with a database!
|
escape_sgml_chars — escape special SGML characters in a string.
The RivetEntities package was kindly provided by Harald Oehlmann and is largely taken from a simple yet clever encoder/decoder of HTML entities starting from a utf-8 character string. The original code writted by Andy Goth is at http://wiki.tcl.tk/26403. Package entities extends the functionality in the original code combining it with Tcl's 'encoding' command to encode/decode from any supported encoding
-(Windows convention) or
:(Unix, Mac convention). The procedure
constrainin the dictionary