1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
<%python scope="global">
import sys, string, re
# datastructure that will store the whole contents of the documentation
class TOCElement:
def __init__(self, filename, name, description, parent = None, ext = None, header = None, last_updated = 0):
self.filename = filename
self.name = name
self.parent = parent
self.path = self._create_path()
self.header = header
if self.parent is not None:
self.root = parent.root
self.root.pathlookup[self.path] = self
if self.parent.filename != self.filename:
self.root.filelookup[self.filename] = self
self.isTop = True
else:
self.root = self
self.pathlookup = {}
self.pathlookup[''] = self
self.filelookup = {}
self.filelookup[filename] = self
if ext is not None:
self.ext = ext
else:
self.ext = self.root.ext
self.last_updated = last_updated
self.description = description
self.content = None
self.previous = None
self.next = None
self.children = []
if parent:
if len(parent.children):
self.previous = parent.children[-1]
parent.children[-1].next = self
parent.children.append(self)
if last_updated > parent.last_updated:
parent.last_updated = self.last_updated
def get_file(self, name):
name = re.sub("\.\w+$", "", name)
return self.root.filelookup[name]
def lookup(self, path):
return self.root.pathlookup[path]
def get_link(self, includefile = True, anchor = True):
if includefile:
if anchor:
return "%s%s#%s" % (self.filename, self.ext, self.path)
else:
return "%s%s" % (self.filename, self.ext)
else:
if anchor:
return "#" + self.path
else:
return ""
def _create_path(self):
elem = self
tokens = []
while elem.parent is not None:
tokens.insert(0, elem.name)
elem = elem.parent
path = string.join(tokens, '_')
return path
</%python>
<%python scope="request">
current = Value()
filename = Value()
</%python>
<%args scope="request">
paged = 'yes'
</%args>
<%python scope="init">
try:
a = r
isdynamic = True
ext = ".myt"
except:
isdynamic = False
ext = ".html"
request_comp = m.request_comp()
if isdynamic and not m.interpreter.attributes.get('docs_static_cache', False):
page_cache = True
else:
page_cache = False
# for dynamic page, cache the output of the final page
if page_cache:
if m.cache_self(key="doc_%s" % paged, component = request_comp):
return
list_comp = m.fetch_next()
files = request_comp.attributes['files']
title = request_comp.attributes.setdefault('title', "Documentation")
version = request_comp.attributes['version']
wrapper = request_comp.attributes['wrapper']
index = request_comp.attributes['index']
onepage = request_comp.attributes['onepage']
def buildtoc():
root = TOCElement("", "root", "root element", ext = ext)
current.assign(root)
for file in files:
filename.assign(file)
comp = m.fetch_component(file + ".myt")
main = m.scomp(comp)
return root
if not page_cache:
# non-dynamic (i.e. command-line) page, cache the datastructure so successive
# pages are fast (disables auto-recompiling)
cache = m.get_cache(list_comp)
toc = cache.get_value('toc', createfunc = buildtoc)
else:
toc = buildtoc()
last_updated = toc.last_updated
m.comp(wrapper, isdynamic=isdynamic, ext = ext, toc = toc, comp = request_comp, onepage = onepage, paged = paged, title = title, version = version, index=index, last_updated = last_updated)
</%python>
<%method title>
<% m.request_comp().get_attribute('title', inherit = True) or "Documentation" %>
</%method>
<%method item>
<%doc>stores an item in the table of contents</%doc>
<%args>
# name should be a URL friendly name used for hyperlinking the section
name
# description is the heading for the item
description
escapedesc = False
header = None
</%args>
<%python scope="init">
if escapedesc:
description = m.apply_escapes(description, ['h'])
current(TOCElement(filename(), name, description, current(), header = header, last_updated = m.caller.component_source.last_modified))
current().content = m.content()
current(current().parent)
</%python></%method>
<%method current>
<%init>return current()</%init>
</%method>
|