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