1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
-
+
-
-
+
+
-
+
-
+
-
+
-
-
+
+
-
+
-
-
+
+
-
-
+
+
-
+
-
+
-
+
-
-
-
+
+
+
-
-
+
+
-
+
-
-
+
+
-
-
-
-
+
+
+
+
-
+
|
#!/usr/bin/wapptclsh
#!/usr/bin/w3tclsh
#
# This script demonstrates a Wapp application that can display a copy
# of itself via the /self page. (See the wapp-page-self procedure for
# This script demonstrates a W3 application that can display a copy
# of itself via the /self page. (See the w3-page-self procedure for
# how that one page is generated.)
#
# This script also has a homepage and an /env page that show the wapp
# This script also has a homepage and an /env page that show the w3
# environment. The header and footer for each page are broken out into
# separate subroutines.
#
# Just for grins, there is also a style-sheet and some cache-control
# lines to show how those things work.
#
package require wapp
package require w3
proc common-header {} {
wapp-trim {
w3-trim {
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link href="%url([wapp-param SCRIPT_NAME]/style.css)" rel="stylesheet">
<title>Wapp Self-Display Demo</title>
<link href="%url([w3-param SCRIPT_NAME]/style.css)" rel="stylesheet">
<title>W3 Self-Display Demo</title>
</head>
<body>
}
}
proc common-footer {} {
wapp-trim {
w3-trim {
</body>
</html>
}
}
proc wapp-default {} {
wapp-cache-control max-age=3600
proc w3-default {} {
w3-cache-control max-age=3600
common-header
wapp-trim {
<h1>Wapp Self-Display Demo</h1>
w3-trim {
<h1>W3 Self-Display Demo</h1>
<ul>
<li> <a href='%url([wapp-param SCRIPT_NAME])/self'>Show the script
<li> <a href='%url([w3-param SCRIPT_NAME])/self'>Show the script
that generates this page</a>
<li> <a href='%url([wapp-param SCRIPT_NAME])/env'>Wapp Environment</a>
<li> <a href='%url([w3-param SCRIPT_NAME])/env'>W3 Environment</a>
</ul>
}
common-footer
}
proc wapp-page-env {} {
proc w3-page-env {} {
common-header
wapp-trim {
<h1>Wapp Environment</h1>
<pre>%html([wapp-debug-env])</pre>
w3-trim {
<h1>W3 Environment</h1>
<pre>%html([w3-debug-env])</pre>
}
common-footer
}
proc wapp-page-self {} {
wapp-cache-control max-age=3600
proc w3-page-self {} {
w3-cache-control max-age=3600
common-header
set fd [open [wapp-param SCRIPT_FILENAME] rb]
set fd [open [w3-param SCRIPT_FILENAME] rb]
set script [read $fd]
close $fd
wapp-trim {
<h1>Wapp Script That Shows A Copy Of Itself</h1>
w3-trim {
<h1>W3 Script That Shows A Copy Of Itself</h1>
<pre>%html($script)</pre>
}
common-footer
}
proc wapp-page-style.css {} {
wapp-mimetype text/css
wapp-cache-control max-age=3600
wapp-trim {
proc w3-page-style.css {} {
w3-mimetype text/css
w3-cache-control max-age=3600
w3-trim {
pre {
border: 1px solid black;
padding: 1ex;
}
}
}
wapp-start $argv
w3-start $argv
|