2007-02-02 23:49:58 +08:00
|
|
|
|
2007-02-09 21:01:08 +08:00
|
|
|
import py
|
|
|
|
html = py.xml.html
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
# HTML related stuff
|
|
|
|
class H(html):
|
|
|
|
class Content(html.div):
|
2007-02-06 21:19:16 +08:00
|
|
|
def __init__(self, *args):
|
|
|
|
super(H.Content, self).__init__(id='apigen-content', *args)
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class Description(html.div):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class NamespaceDescription(Description):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class NamespaceItem(html.div):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class NamespaceDef(html.h1):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class ClassDescription(Description):
|
|
|
|
pass
|
|
|
|
|
2007-02-08 21:54:38 +08:00
|
|
|
class ClassDef(html.div):
|
2007-02-07 05:18:56 +08:00
|
|
|
def __init__(self, classname, bases, docstring, sourcelink,
|
2007-02-11 10:04:36 +08:00
|
|
|
attrs, methods):
|
2007-02-08 21:54:38 +08:00
|
|
|
header = H.h1('class %s(' % (classname,))
|
2007-02-09 21:01:08 +08:00
|
|
|
for i, (name, href) in py.builtin.enumerate(bases):
|
|
|
|
if i > 0:
|
|
|
|
header.append(', ')
|
2007-02-07 05:18:56 +08:00
|
|
|
link = name
|
|
|
|
if href is not None:
|
|
|
|
link = H.a(name, href=href)
|
2007-02-08 21:54:38 +08:00
|
|
|
header.append(H.BaseDescription(link))
|
|
|
|
header.append('):')
|
|
|
|
super(H.ClassDef, self).__init__(header)
|
2007-02-07 09:01:25 +08:00
|
|
|
self.append(H.div(H.Docstring(docstring or
|
|
|
|
'*no docstring available*'),
|
|
|
|
sourcelink,
|
|
|
|
class_='classdoc'))
|
2007-02-11 10:04:36 +08:00
|
|
|
if attrs:
|
|
|
|
self.append(H.h2('class attributes and properties:'))
|
|
|
|
for name, val in attrs:
|
2007-02-07 05:18:56 +08:00
|
|
|
self.append(H.PropertyDescription(name, val))
|
|
|
|
if methods:
|
|
|
|
self.append(H.h2('methods:'))
|
|
|
|
for methodhtml in methods:
|
|
|
|
self.append(methodhtml)
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class MethodDescription(Description):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class MethodDef(html.h2):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class FunctionDescription(Description):
|
2007-03-30 04:57:16 +08:00
|
|
|
def __init__(self, localname, argdesc, docstring, valuedesc, excdesc,
|
|
|
|
csource, callstack):
|
2007-02-11 10:04:36 +08:00
|
|
|
infoid = 'info_%s' % (localname.replace('.', '_dot_'),)
|
|
|
|
docstringid = 'docstring_%s' % (localname.replace('.', '_dot_'),)
|
|
|
|
fd = H.FunctionDef(localname, argdesc,
|
2007-03-29 19:56:14 +08:00
|
|
|
title='click to view details',
|
2007-02-11 10:04:36 +08:00
|
|
|
onclick=('showhideel('
|
|
|
|
'document.getElementById("%s")); '
|
2007-02-12 23:45:56 +08:00
|
|
|
% (infoid,)))
|
|
|
|
infodiv = H.div(
|
|
|
|
H.Docstring(docstring or '*no docstring available*',
|
|
|
|
id=docstringid),
|
2007-03-30 04:57:16 +08:00
|
|
|
H.FunctionInfo(valuedesc, excdesc, csource, callstack,
|
2007-02-12 23:45:56 +08:00
|
|
|
id=infoid, style="display: none"),
|
|
|
|
class_='funcdocinfo')
|
|
|
|
super(H.FunctionDescription, self).__init__(fd, infodiv)
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class FunctionDef(html.h2):
|
2007-02-11 10:21:45 +08:00
|
|
|
style = html.Style(cursor='pointer')
|
2007-02-11 10:04:36 +08:00
|
|
|
def __init__(self, name, argdesc, **kwargs):
|
2007-02-11 10:21:45 +08:00
|
|
|
class_ = kwargs.pop('class_', 'funcdef')
|
2007-02-11 10:04:36 +08:00
|
|
|
super(H.FunctionDef, self).__init__('def %s%s:' % (name, argdesc),
|
2007-02-11 10:21:45 +08:00
|
|
|
class_=class_, **kwargs)
|
2007-02-03 07:29:01 +08:00
|
|
|
|
|
|
|
class FunctionInfo(html.div):
|
2007-03-30 04:57:16 +08:00
|
|
|
def __init__(self, valuedesc, excdesc, csource, callstack, **kwargs):
|
|
|
|
super(H.FunctionInfo, self).__init__(valuedesc, H.br(), excdesc,
|
|
|
|
H.br(), csource,
|
2007-02-11 10:04:36 +08:00
|
|
|
callstack, class_='funcinfo',
|
|
|
|
**kwargs)
|
2007-02-04 23:47:33 +08:00
|
|
|
|
|
|
|
class PropertyDescription(html.div):
|
|
|
|
def __init__(self, name, value):
|
|
|
|
if type(value) not in [str, unicode]:
|
|
|
|
value = str(value)
|
|
|
|
if len(value) > 100:
|
|
|
|
value = value[:100] + '...'
|
2007-02-05 05:11:43 +08:00
|
|
|
super(H.PropertyDescription, self).__init__(name, ': ',
|
|
|
|
H.em(value),
|
|
|
|
class_='property')
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class ParameterDescription(html.div):
|
|
|
|
pass
|
|
|
|
|
2007-02-11 10:04:36 +08:00
|
|
|
class Docstring(html.div):
|
|
|
|
style = html.Style(white_space='pre', color='#666',
|
|
|
|
margin_left='1em', margin_bottom='1em')
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class Navigation(html.div):
|
|
|
|
#style = html.Style(min_height='99%', float='left', margin_top='1.2em',
|
|
|
|
# overflow='auto', width='15em', white_space='nowrap')
|
|
|
|
pass
|
|
|
|
|
|
|
|
class NavigationItem(html.div):
|
2007-02-03 07:29:01 +08:00
|
|
|
def __init__(self, linker, linkid, name, indent, selected):
|
|
|
|
href = linker.get_lazyhref(linkid)
|
|
|
|
super(H.NavigationItem, self).__init__((indent * 2 * u'\xa0'),
|
|
|
|
H.a(name, href=href))
|
|
|
|
if selected:
|
|
|
|
self.attr.class_ = 'selected'
|
2007-02-02 23:49:58 +08:00
|
|
|
|
2007-02-09 06:47:28 +08:00
|
|
|
class BaseDescription(html.span):
|
2007-02-02 23:49:58 +08:00
|
|
|
pass
|
|
|
|
|
2007-02-03 07:29:01 +08:00
|
|
|
class SourceSnippet(html.div):
|
|
|
|
def __init__(self, text, href, sourceels=None):
|
|
|
|
if sourceels is None:
|
|
|
|
sourceels = []
|
|
|
|
link = text
|
|
|
|
if href:
|
|
|
|
link = H.a(text, href=href)
|
|
|
|
super(H.SourceSnippet, self).__init__(
|
2007-02-06 21:19:16 +08:00
|
|
|
link, H.div(*sourceels))
|
2007-02-03 07:29:01 +08:00
|
|
|
|
2007-02-09 06:19:10 +08:00
|
|
|
class PythonSource(Content):
|
|
|
|
style = html.Style(font_size='0.8em')
|
2007-02-04 22:35:28 +08:00
|
|
|
def __init__(self, *sourceels):
|
2007-02-09 06:19:10 +08:00
|
|
|
super(H.PythonSource, self).__init__(
|
2007-02-06 21:19:16 +08:00
|
|
|
H.div(*sourceels))
|
|
|
|
|
2007-02-13 09:01:23 +08:00
|
|
|
class SourceBlock(html.table):
|
2007-02-06 21:19:16 +08:00
|
|
|
def __init__(self):
|
2007-02-13 09:01:23 +08:00
|
|
|
tbody = H.tbody()
|
|
|
|
row = H.tr()
|
|
|
|
tbody.append(row)
|
|
|
|
linenocell = H.td(style='width: 1%')
|
|
|
|
row.append(linenocell)
|
|
|
|
linecell = H.td()
|
|
|
|
row.append(linecell)
|
|
|
|
|
|
|
|
self.linenotable = lntable = H.table()
|
2007-02-06 21:19:16 +08:00
|
|
|
self.linenotbody = lntbody = H.tbody()
|
|
|
|
lntable.append(lntbody)
|
2007-02-13 09:01:23 +08:00
|
|
|
linenocell.append(lntable)
|
2007-02-06 21:19:16 +08:00
|
|
|
|
|
|
|
self.linetable = ltable = H.table()
|
|
|
|
self.linetbody = ltbody = H.tbody()
|
|
|
|
ltable.append(ltbody)
|
2007-02-13 09:01:23 +08:00
|
|
|
linecell.append(ltable)
|
|
|
|
|
|
|
|
super(H.SourceBlock, self).__init__(tbody, class_='codeblock')
|
2007-02-06 21:19:16 +08:00
|
|
|
|
|
|
|
def add_line(self, lineno, els):
|
|
|
|
self.linenotbody.append(H.tr(H.td(lineno, class_='lineno')))
|
2007-02-13 09:01:23 +08:00
|
|
|
self.linetbody.append(H.tr(H.td(H.pre(class_='code', *els),
|
|
|
|
class_='codecell')))
|
2007-02-02 23:49:58 +08:00
|
|
|
|
2007-02-09 06:19:10 +08:00
|
|
|
class NonPythonSource(Content):
|
|
|
|
def __init__(self, *args):
|
|
|
|
super(H.NonPythonSource, self).__init__(H.pre(*args))
|
2007-02-02 23:49:58 +08:00
|
|
|
|
2007-02-09 06:19:10 +08:00
|
|
|
class DirList(Content):
|
2007-02-04 22:35:28 +08:00
|
|
|
def __init__(self, dirs, files):
|
|
|
|
dirs = [H.DirListItem(text, href) for (text, href) in dirs]
|
|
|
|
files = [H.DirListItem(text, href) for (text, href) in files]
|
|
|
|
super(H.DirList, self).__init__(
|
|
|
|
H.h2('directories'), dirs,
|
|
|
|
H.h2('files'), files,
|
|
|
|
)
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class DirListItem(html.div):
|
2007-02-04 22:35:28 +08:00
|
|
|
def __init__(self, text, href):
|
|
|
|
super(H.DirListItem, self).__init__(H.a(text, href=href))
|
2007-02-02 23:49:58 +08:00
|
|
|
|
|
|
|
class ValueDescList(html.ul):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(H.ValueDescList, self).__init__(*args, **kwargs)
|
|
|
|
|
2007-03-30 04:57:16 +08:00
|
|
|
class ExceptionDescList(html.ul):
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(H.ExceptionDescList, self).__init__(*args, **kwargs)
|
|
|
|
|
|
|
|
def append(self, t):
|
|
|
|
super(H.ExceptionDescList, self).append(html.li(t))
|
|
|
|
|
2007-02-02 23:49:58 +08:00
|
|
|
class ValueDescItem(html.li):
|
|
|
|
pass
|
|
|
|
|
|
|
|
class CallStackDescription(Description):
|
2007-02-08 22:52:49 +08:00
|
|
|
pass
|
|
|
|
|
|
|
|
class CallStackLink(html.div):
|
|
|
|
def __init__(self, filename, lineno, href):
|
|
|
|
super(H.CallStackLink, self).__init__(
|
|
|
|
H.a("stack trace %s - line %s" % (filename, lineno),
|
|
|
|
href=href))
|
2007-02-03 07:29:01 +08:00
|
|
|
|
|
|
|
class Hideable(html.div):
|
|
|
|
def __init__(self, name, class_, *content):
|
|
|
|
super(H.Hideable, self).__init__(
|
|
|
|
H.div(H.a('show/hide %s' % (name,),
|
|
|
|
href='#',
|
|
|
|
onclick=('showhideel(getnextsibling(this));'
|
|
|
|
'return false;')),
|
|
|
|
H.div(style='display: none',
|
|
|
|
class_=class_,
|
|
|
|
*content)))
|
2007-02-02 23:49:58 +08:00
|
|
|
|