Wapp

Check-in [0afcafe89f]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add the self2.tcl example script
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256:0afcafe89fe6f7c0d0cbecaaf8fb9b454df079f5c6cbfa8a3bd73f28e406b6b6
User & Date: drh 2018-02-08 02:07:08
Context
2018-02-08
02:17
Add she-bangs to the self.tcl and self2.tcl examples. check-in: 654ca1127b user: drh tags: trunk
02:07
Add the self2.tcl example script check-in: 0afcafe89f user: drh tags: trunk
01:31
Add cache-control to the self.tcl example script. check-in: b1545db25b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to examples/README.md.

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
database name.

The password for the "shoplist-demo.db" database is "12345".

When the app is running, the /env page shows the CGI environment for
debugging and testing purposes.

5.0 self.tcl
------------

This script gives an example of a Wapp application that can display
a copy of itself.  The self-display in the /self page is actually
a very small part of the total script.  This example also includes
some cache-control and CSS as a demonstration of how that kind of thing
is accomplished.







|
|

|
|
|
|
|
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
database name.

The password for the "shoplist-demo.db" database is "12345".

When the app is running, the /env page shows the CGI environment for
debugging and testing purposes.

5.0 self.tcl and self2.tcl
--------------------------

These script give examples of Wapp applications that can display
a copy of themselves.  The self-display for self.tcl is in the /self
page and is actually a very small part of the total script. For the
self2.tcl example, the color of the text for the self-display is
controlled by a query parameter.

Added examples/self2.tcl.







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# This script demonstrates a Wapp application that can display a copy
# of itself using a font color selected by a query parameter.
#
# The foreground color is whatever value is given by the color= query
# parameter.  The color is inserted into a style= attribute on the
# <pre> element using the %url(...) substitution mechanism of Wapp,
# so it is safe from XSS injections.  Try it!  You won't be able to
# slip in any unwanted HTML, but you can use %23 to get a # for
# an RGB color, like this:
#
#              ?color=%23003f7f
#
package require wapp
proc wapp-default {} {
  wapp-content-security-policy {default_src 'self' 'inline'}
  wapp-allow-xorigin-params
  set fd [open [wapp-param SCRIPT_FILENAME] rb]
  set script [read $fd]
  close $fd
  set self [wapp-param SELF_URL]
  wapp-trim {
    <html>
    <head>
    <link href="%url([wapp-param SCRIPT_NAME]/style.css)" rel="stylesheet">
    <title>Wapp Self-Display Demo</title>
    </head>
    <body>
    <p>In the box below is shown the Wapp script that generated this page.
    Change the foreground color using the color= query parameter.
    Examples:</p>
    <ul>
    <li><a href='%url($self?color=red)'>%html($self?color=red)</a>
    <li><a href='%url($self?color=green)'>%html($self?color=green)</a>
    <li><a href='%url($self?color=blue)'>%html($self?color=blue)</a>
    <li><a href='%url($self)?color=%23003f7f'>%html($self?color=%23003f7f)</a>
    </ul>
    </p>
    <pre style='color: %url([wapp-param color black]);'>%html($script)</pre>
  }
}
proc wapp-page-style.css {} {
  wapp-mimetype text/css
  wapp-cache-control max-age=3600
  wapp-trim {
    pre {
       border: 1px solid black;
       padding: 1ex;
    }
  }
}
wapp-start $argv