diff options
author | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-05-22 15:33:45 +0000 |
---|---|---|
committer | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-05-22 15:33:45 +0000 |
commit | 8b4aa1b6446b6653d7a09586522e15b0037973f8 (patch) | |
tree | 29e67e5a8a5ad8b4781c19c6d45227c997be6ecc /sandbox/py-rest-doc/sphinx/web/application.py | |
parent | 8a707db81d0d99a962ea2b8e1caccb6cf0644747 (diff) | |
download | docutils-8b4aa1b6446b6653d7a09586522e15b0037973f8.tar.gz |
Some adjustments.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5091 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/py-rest-doc/sphinx/web/application.py')
-rw-r--r-- | sandbox/py-rest-doc/sphinx/web/application.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/sandbox/py-rest-doc/sphinx/web/application.py b/sandbox/py-rest-doc/sphinx/web/application.py index 6426817a9..0b053223b 100644 --- a/sandbox/py-rest-doc/sphinx/web/application.py +++ b/sandbox/py-rest-doc/sphinx/web/application.py @@ -97,11 +97,21 @@ class DocumentationApplication(object): self.cache[url] = (filename, path.getmtime(filename), text) return Response(text) - def get_close_matches(self, req, url): + pretty_type = { + 'data': 'module data', + 'cfunction': 'C function', + 'cmember': 'C member', + 'cmacro': 'C macro', + 'ctype': 'C type', + 'cvar': 'C variable', + } + + def get_keyword_matches(self, req, url): """ - Find close matches. If there is an exact match (for example + Find keyword matches. If there is an exact match, just redirect: http://docs.python.org/os.path.exists would automatically redirect to http://docs.python.org/modules/os.path/#os.path.exists. + Else, show a page with close matches. Module references are processed first so that "os.path" is handled as a module and not as member of os. @@ -125,7 +135,7 @@ class DocumentationApplication(object): close_matches.append({ 'href': relative_uri(url + '/', link), 'title': title, - 'type': type, + 'type': self.pretty_type.get(type, type), 'description': desc }) return Response(render_template(req, 'not_found.html', { @@ -147,11 +157,13 @@ class DocumentationApplication(object): url = req.path.strip('/') or 'index' if url == 'search': resp = self.search(req) + elif url == 'index' and req.args.get('q', ''): + resp = self.get_keyword_matches(req, req.args['q']) else: try: resp = self.get_page(req, url) except NotFound: - resp = self.get_close_matches(req, url) + resp = self.get_keyword_matches(req, url) return resp(environ, start_response) |