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@560 | 28 | # Configuration settings. |
paulb@560 | 29 | # NOTE: Change the filesystem encoding if appropriate. |
paulb@560 | 30 | |
paulb@560 | 31 | fsencoding = "iso-8859-15" |
paulb@560 | 32 | |
paulb@560 | 33 | # Resource classes. |
paulb@560 | 34 | |
paulb@240 | 35 | class DemoResource: |
paulb@240 | 36 | def respond(self, trans): |
paulb@240 | 37 | trans.set_content_type(ContentType("text/html")) |
paulb@240 | 38 | trans.get_response_stream().write(""" |
paulb@240 | 39 | <html> |
paulb@240 | 40 | <head> |
paulb@240 | 41 | <title>XSLTools Examples</title> |
paulb@240 | 42 | </head> |
paulb@240 | 43 | <body> |
paulb@240 | 44 | <h1>XSLTools Examples</h1> |
paulb@240 | 45 | <p>Here are some of the examples supplied with XSLTools:</p> |
paulb@240 | 46 | <ul> |
paulb@240 | 47 | <li><a href="candidate">A job candidate profile editor</a></li> |
paulb@240 | 48 | <li><a href="configurator">A Webshop-style system configurator</a></li> |
paulb@240 | 49 | <li><a href="dictionary">A simple word lookup interface</a></li> |
paulb@240 | 50 | <li><a href="questionnaire">A questionnaire generator</a></li> |
paulb@240 | 51 | <li><a href="pep241">A Python package repository user interface</a></li> |
paulb@490 | 52 | <li><a href="recursive">A recursive template example</a></li> |
paulb@240 | 53 | <li><a href="verysimple">A very simple example</a></li> |
paulb@240 | 54 | </ul> |
paulb@240 | 55 | <p>You can run all of the examples independently, too. See the |
paulb@240 | 56 | <code>examples</code> directory for the code.</p> |
paulb@240 | 57 | </body> |
paulb@240 | 58 | </html>""") |
paulb@240 | 59 | trans.set_response_code(200) |
paulb@240 | 60 | |
paulb@240 | 61 | # Find out where our example document will be for the dictionary example. |
paulb@240 | 62 | |
paulb@240 | 63 | def get_site(): |
paulb@240 | 64 | |
paulb@240 | 65 | "Define the resource mapping." |
paulb@240 | 66 | |
paulb@518 | 67 | # Find a file for use with the Dictionary example. |
paulb@518 | 68 | |
paulb@512 | 69 | exec_dir = os.path.split(sys.argv[0])[0] |
paulb@512 | 70 | parts = os.path.split(exec_dir) |
paulb@240 | 71 | if parts[-1] == "tools": |
paulb@240 | 72 | parts = parts[:-1] |
paulb@240 | 73 | parts += ("docs", "LICENCE.txt") |
paulb@240 | 74 | doc = os.path.join(*parts) |
paulb@240 | 75 | dict = Dict(doc) |
paulb@240 | 76 | |
paulb@518 | 77 | # Define the site resource itself. |
paulb@518 | 78 | |
paulb@240 | 79 | resource = MapResource({ |
paulb@518 | 80 | |
paulb@518 | 81 | # Use the current working directory so that the installed package can still run |
paulb@518 | 82 | # the demo. |
paulb@518 | 83 | |
paulb@560 | 84 | "candidate" : Candidate.get_site(fsencoding, use_cwd=1), |
paulb@240 | 85 | "configurator" : Configurator.get_site(), |
paulb@240 | 86 | "dictionary" : Dictionary.get_site(dict), |
paulb@240 | 87 | "questionnaire" : Questionnaire.get_site(), |
paulb@240 | 88 | "pep241" : PEP241.get_site(), |
paulb@490 | 89 | "recursive" : Recursive.get_site(), |
paulb@240 | 90 | "verysimple" : VerySimple.get_site(), |
paulb@240 | 91 | "" : DemoResource(), |
paulb@240 | 92 | }) |
paulb@240 | 93 | |
paulb@240 | 94 | return resource |
paulb@240 | 95 | |
paulb@512 | 96 | # Resource preparation ahead of time - useful for making installations. |
paulb@512 | 97 | |
paulb@512 | 98 | def prepare_resources(): |
paulb@512 | 99 | for module in [Candidate, Configurator, Dictionary, Questionnaire, PEP241, Recursive, VerySimple]: |
paulb@512 | 100 | module.prepare_resources() |
paulb@512 | 101 | |
paulb@240 | 102 | # vim: tabstop=4 expandtab shiftwidth=4 |