diff options
author | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-05-24 19:31:43 +0000 |
---|---|---|
committer | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-05-24 19:31:43 +0000 |
commit | 2e3b812ff5931b954a04eff90ed8fec0bac9563f (patch) | |
tree | 496f26934c8fd272edea7396941f78ee97f7a8e7 /sandbox/py-rest-doc/sphinx/web/application.py | |
parent | d5528ffc3b01ea21ade5d6380a813a83b8666caa (diff) | |
download | docutils-2e3b812ff5931b954a04eff90ed8fec0bac9563f.tar.gz |
Move some code to environment from application.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5132 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 | 59 |
1 files changed, 25 insertions, 34 deletions
diff --git a/sandbox/py-rest-doc/sphinx/web/application.py b/sandbox/py-rest-doc/sphinx/web/application.py index 1ac2576e9..885c387e1 100644 --- a/sandbox/py-rest-doc/sphinx/web/application.py +++ b/sandbox/py-rest-doc/sphinx/web/application.py @@ -213,41 +213,32 @@ class DocumentationApplication(object): """ if term is None: term = req.path.strip('/') - # module references - if term in self.env.modules: - filename, title, system = self.env.modules[term] - url = get_target_uri(filename) - return RedirectResponse(url) - # direct references - if term in self.env.descrefs: - filename, ref_type = self.env.descrefs[term] - url = get_target_uri(filename) + '#' + term - return RedirectResponse(url) - - if avoid_fuzzy: - return - # get some close matches - close_matches = [] - good_matches = 0 - for ratio, type, filename, title, desc in self.env.get_close_matches(term): - link = get_target_uri(filename) - if type != 'module': - link += '#' + title - good_match = ratio > 0.75 - good_matches += good_match - close_matches.append({ - 'href': relative_uri(req.path, link), - 'title': title, - 'good_match': good_match, - 'type': self.pretty_type.get(type, type), - 'description': desc - }) - return Response(render_template(req, 'not_found.html', { - 'close_matches': close_matches, - 'good_matches_count': good_matches, - 'keyword': term - }), status=404) + matches = self.env.find_keyword(term, avoid_fuzzy) + if not matches: + return + if type(matches) is tuple: + return RedirectResponse(get_target_uri(matches[1]) + '#' + matches[2]) + elif type(matches) is list: + # get some close matches + close_matches = [] + good_matches = 0 + for ratio, type, filename, anchorname, desc in matches: + link = get_target_uri(filename) + '#' + anchorname + good_match = ratio > 0.75 + good_matches += good_match + close_matches.append({ + 'href': relative_uri(req.path, link), + 'title': anchorname, + 'good_match': good_match, + 'type': self.pretty_type.get(type, type), + 'description': desc, + }) + return Response(render_template(req, 'not_found.html', { + 'close_matches': close_matches, + 'good_matches_count': good_matches, + 'keyword': term + }), status=404) def __call__(self, environ, start_response): """ |