7
7
from ivle.webapp.base.plugins import ViewPlugin
8
8
from ivle.webapp.base.xhtml import XHTMLView
10
def help_url(plugin, path):
11
'''Generates a URL to a media file.
13
Plugin must be a string, which is put into the path literally.'''
15
return os.path.join(ivle.conf.root_dir, plugin, path)
9
from ivle.webapp.errors import NotFound, Forbidden
17
11
def generate_toc(plugins, req):
30
24
if isinstance(curdict[key], dict):
31
25
add_dict(newdict[key], curdict[key], plugin)
33
newdict[key] = help_url(plugin, curdict[key])
27
newdict[key] = os.path.join(plugin, curdict[key])
36
30
class HelpView(XHTMLView):
37
31
"""Shows the help file for the specified path."""
39
33
template = 'helpview.html'
41
35
def __init__(self, req, path):
42
36
self.paths = path.split('/')
44
38
def populate(self, req, ctx):
45
39
helpfile = generate_toc(req.plugin_index[ViewPlugin], req)
47
41
for path in self.paths:
48
helpfile = helpfile[path]
49
ctx['helpfile'] = helpfile
54
class HelpToc(XHTMLView):
43
helpfile = helpfile[path]
44
except (KeyError, TypeError):
45
# Traversal failed. We 404.
48
if not isinstance(helpfile, basestring):
49
# It's a virtual directory.
52
ctx['helpfile'] = helpfile
55
class HelpToCView(XHTMLView):
55
56
"""Displays the help Table of Contents."""
57
58
template = 'toc.html'
59
60
def populate(self, req, ctx):
60
61
ctx['toc'] = generate_toc(req.plugin_index[ViewPlugin], req)
64
64
class Plugin(ViewPlugin):
65
65
"""The plugin for viewing help files."""
68
('+help', HelpToCView),
69
69
('+help/*path', HelpView)