1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/DemoApp.py Sat Oct 01 16:27:23 2005 +0000
1.3 @@ -0,0 +1,78 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +A demonstration of XSLTools. This is a quick and dirty combination of an
1.8 +adapter, employing lots of resources, and the index page resource.
1.9 +"""
1.10 +
1.11 +# Import the things which publish parts of the application.
1.12 +
1.13 +from WebStack.Resources.ResourceMap import MapResource
1.14 +import os
1.15 +
1.16 +# Here are all the example applications.
1.17 +
1.18 +import Candidate
1.19 +import Configurator
1.20 +import Dictionary
1.21 +from Dictionary.Dict import Dict
1.22 +import Questionnaire
1.23 +import PEP241
1.24 +import VerySimple
1.25 +
1.26 +# A very simple index page.
1.27 +
1.28 +from WebStack.Generic import ContentType
1.29 +
1.30 +class DemoResource:
1.31 + def respond(self, trans):
1.32 + trans.set_content_type(ContentType("text/html"))
1.33 + trans.get_response_stream().write("""
1.34 +<html>
1.35 + <head>
1.36 + <title>XSLTools Examples</title>
1.37 + </head>
1.38 + <body>
1.39 + <h1>XSLTools Examples</h1>
1.40 + <p>Here are some of the examples supplied with XSLTools:</p>
1.41 + <ul>
1.42 + <li><a href="candidate">A job candidate profile editor</a></li>
1.43 + <li><a href="configurator">A Webshop-style system configurator</a></li>
1.44 + <li><a href="dictionary">A simple word lookup interface</a></li>
1.45 + <li><a href="questionnaire">A questionnaire generator</a></li>
1.46 + <li><a href="pep241">A Python package repository user interface</a></li>
1.47 + <li><a href="verysimple">A very simple example</a></li>
1.48 + </ul>
1.49 + <p>You can run all of the examples independently, too. See the
1.50 + <code>examples</code> directory for the code.</p>
1.51 + </body>
1.52 +</html>""")
1.53 + trans.set_response_code(200)
1.54 +
1.55 +# Find out where our example document will be for the dictionary example.
1.56 +
1.57 +def get_site():
1.58 +
1.59 + "Define the resource mapping."
1.60 +
1.61 + cwd = os.getcwd()
1.62 + parts = os.path.split(cwd)
1.63 + if parts[-1] == "tools":
1.64 + parts = parts[:-1]
1.65 + parts += ("docs", "LICENCE.txt")
1.66 + doc = os.path.join(*parts)
1.67 + dict = Dict(doc)
1.68 +
1.69 + resource = MapResource({
1.70 + "candidate" : Candidate.get_site(),
1.71 + "configurator" : Configurator.get_site(),
1.72 + "dictionary" : Dictionary.get_site(dict),
1.73 + "questionnaire" : Questionnaire.get_site(),
1.74 + "pep241" : PEP241.get_site(),
1.75 + "verysimple" : VerySimple.get_site(),
1.76 + "" : DemoResource(),
1.77 + })
1.78 +
1.79 + return resource
1.80 +
1.81 +# vim: tabstop=4 expandtab shiftwidth=4