7
from ivle.webapp.base.plugins import ViewPlugin
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)
17
def generate_toc(plugins, req):
19
for plugin in plugins:
20
if hasattr(plugin, 'help'):
21
# Get the dir the plugin resides in
22
plugindir = os.path.dirname(inspect.getmodule(plugin).__file__)
23
add_dict(toc, plugin.help, plugindir)
26
def add_dict(newdict, curdict, plugin):
28
if key not in newdict:
30
if isinstance(curdict[key], dict):
31
add_dict(newdict[key], curdict[key], plugin)
33
newdict[key] = help_url(plugin, curdict[key])
36
class HelpView(XHTMLView):
37
"""Shows the help file for the specified path."""
39
template = 'helpview.html'
41
def __init__(self, req, path):
42
self.paths = path.split('/')
44
def populate(self, req, ctx):
45
helpfile = generate_toc(req.plugin_index[ViewPlugin], req)
47
for path in self.paths:
48
helpfile = helpfile[path]
49
ctx['helpfile'] = helpfile
54
class HelpToc(XHTMLView):
55
"""Displays the help Table of Contents."""
59
def populate(self, req, ctx):
60
ctx['toc'] = generate_toc(req.plugin_index[ViewPlugin], req)
64
class Plugin(ViewPlugin):
65
"""The plugin for viewing help files."""
69
('+help/*path', HelpView)