Wapp

Artifact [d19198d39f]
Login

Artifact d19198d39f20334f5e8ff65f6c5231df176cafe8eb5279a4a94d56bc60e04837:


#!/usr/bin/w3tclsh
#
# 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 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 w3
proc common-header {} {
  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([w3-param SCRIPT_NAME]/style.css)" rel="stylesheet">
    <title>W3 Self-Display Demo</title>
    </head>
    <body>
  }
}
proc common-footer {} {
  w3-trim {
    </body>
    </html>
  }
}
proc w3-default {} {
  w3-cache-control max-age=3600
  common-header
  w3-trim {
    <h1>W3 Self-Display Demo</h1>
    <ul>
    <li> <a href='%url([w3-param SCRIPT_NAME])/self'>Show the script
    that generates this page</a>
    <li> <a href='%url([w3-param SCRIPT_NAME])/env'>W3 Environment</a>
    </ul>
  }
  common-footer
}
proc w3-page-env {} {
  common-header
  w3-trim {
    <h1>W3 Environment</h1>
    <pre>%html([w3-debug-env])</pre>
  }
  common-footer
}
proc w3-page-self {} {
  w3-cache-control max-age=3600
  common-header
  set fd [open [w3-param SCRIPT_FILENAME] rb]
  set script [read $fd]
  close $fd
  w3-trim {
    <h1>W3 Script That Shows A Copy Of Itself</h1>
    <pre>%html($script)</pre>
  }
  common-footer
}
proc w3-page-style.css {} {
  w3-mimetype text/css
  w3-cache-control max-age=3600
  w3-trim {
    pre {
       border: 1px solid black;
       padding: 1ex;
    }
  }
}
w3-start $argv