1 #!/usr/bin/env python 2 3 """ 4 A demonstration of XSLTools. This is a quick and dirty combination of an 5 adapter, employing lots of resources, and the index page resource. 6 """ 7 8 # Import the things which publish parts of the application. 9 10 from WebStack.Resources.ResourceMap import MapResource 11 import os, sys 12 13 # Here are all the example applications. 14 15 import Candidate 16 import Configurator 17 import Dictionary 18 from Dictionary.Dict import Dict 19 import Questionnaire 20 import PEP241 21 import Recursive 22 import VerySimple 23 24 # A very simple index page. 25 26 from WebStack.Generic import ContentType 27 28 class DemoResource: 29 def respond(self, trans): 30 trans.set_content_type(ContentType("text/html")) 31 trans.get_response_stream().write(""" 32 <html> 33 <head> 34 <title>XSLTools Examples</title> 35 </head> 36 <body> 37 <h1>XSLTools Examples</h1> 38 <p>Here are some of the examples supplied with XSLTools:</p> 39 <ul> 40 <li><a href="candidate">A job candidate profile editor</a></li> 41 <li><a href="configurator">A Webshop-style system configurator</a></li> 42 <li><a href="dictionary">A simple word lookup interface</a></li> 43 <li><a href="questionnaire">A questionnaire generator</a></li> 44 <li><a href="pep241">A Python package repository user interface</a></li> 45 <li><a href="recursive">A recursive template example</a></li> 46 <li><a href="verysimple">A very simple example</a></li> 47 </ul> 48 <p>You can run all of the examples independently, too. See the 49 <code>examples</code> directory for the code.</p> 50 </body> 51 </html>""") 52 trans.set_response_code(200) 53 54 # Find out where our example document will be for the dictionary example. 55 56 def get_site(): 57 58 "Define the resource mapping." 59 60 # Find a file for use with the Dictionary example. 61 62 exec_dir = os.path.split(sys.argv[0])[0] 63 parts = os.path.split(exec_dir) 64 if parts[-1] == "tools": 65 parts = parts[:-1] 66 parts += ("docs", "LICENCE.txt") 67 doc = os.path.join(*parts) 68 dict = Dict(doc) 69 70 # Define the site resource itself. 71 72 resource = MapResource({ 73 74 # NOTE: Change the filesystem encoding if appropriate. 75 # Use the current working directory so that the installed package can still run 76 # the demo. 77 78 "candidate" : Candidate.get_site("iso-8859-15", use_cwd=1), 79 "configurator" : Configurator.get_site(), 80 "dictionary" : Dictionary.get_site(dict), 81 "questionnaire" : Questionnaire.get_site(), 82 "pep241" : PEP241.get_site(), 83 "recursive" : Recursive.get_site(), 84 "verysimple" : VerySimple.get_site(), 85 "" : DemoResource(), 86 }) 87 88 return resource 89 90 # Resource preparation ahead of time - useful for making installations. 91 92 def prepare_resources(): 93 for module in [Candidate, Configurator, Dictionary, Questionnaire, PEP241, Recursive, VerySimple]: 94 module.prepare_resources() 95 96 # vim: tabstop=4 expandtab shiftwidth=4