[svn r38036] Some small code cleanups (moved more HTML generation code to html.py).
--HG-- branch : trunk
This commit is contained in:
parent
563ed75651
commit
12b991723e
|
@ -23,7 +23,25 @@ class H(html):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ClassDef(html.h1):
|
class ClassDef(html.h1):
|
||||||
pass
|
def __init__(self, classname, bases, docstring, sourcelink,
|
||||||
|
properties, methods):
|
||||||
|
super(H.ClassDef, self).__init__('class %s(' % classname,)
|
||||||
|
for name, href in bases:
|
||||||
|
link = name
|
||||||
|
if href is not None:
|
||||||
|
link = H.a(name, href=href)
|
||||||
|
self.append(H.BaseDescription(link))
|
||||||
|
self.append('):')
|
||||||
|
self.append(H.Docstring(docstring or '*no docstring available*'))
|
||||||
|
self.append(sourcelink)
|
||||||
|
if properties:
|
||||||
|
self.append(H.h2('properties:'))
|
||||||
|
for name, val in properties:
|
||||||
|
self.append(H.PropertyDescription(name, val))
|
||||||
|
if methods:
|
||||||
|
self.append(H.h2('methods:'))
|
||||||
|
for methodhtml in methods:
|
||||||
|
self.append(methodhtml)
|
||||||
|
|
||||||
class MethodDescription(Description):
|
class MethodDescription(Description):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -355,15 +355,7 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
try:
|
try:
|
||||||
sourcefile = inspect.getsourcefile(cls)
|
sourcefile = inspect.getsourcefile(cls)
|
||||||
except TypeError:
|
except TypeError:
|
||||||
sourcelink = 'builtin file, no source available'
|
sourcefile = None
|
||||||
else:
|
|
||||||
if sourcefile is None:
|
|
||||||
sourcelink = H.div('no source available')
|
|
||||||
else:
|
|
||||||
if sourcefile[-1] in ['o', 'c']:
|
|
||||||
sourcefile = sourcefile[:-1]
|
|
||||||
sourcelink = H.div(H.a('view source',
|
|
||||||
href=self.linker.get_lazyhref(sourcefile)))
|
|
||||||
|
|
||||||
docstring = cls.__doc__
|
docstring = cls.__doc__
|
||||||
if docstring:
|
if docstring:
|
||||||
|
@ -375,32 +367,35 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
bases = self.build_bases(dotted_name)
|
bases = self.build_bases(dotted_name)
|
||||||
properties = self.build_properties(cls)
|
properties = self.build_properties(cls)
|
||||||
methods = self.build_methods(dotted_name)
|
methods = self.build_methods(dotted_name)
|
||||||
|
|
||||||
|
if sourcefile is None:
|
||||||
|
sourcelink = H.div('no source available')
|
||||||
|
else:
|
||||||
|
if sourcefile[-1] in ['o', 'c']:
|
||||||
|
sourcefile = sourcefile[:-1]
|
||||||
|
sourcelink = H.div(H.a('view source',
|
||||||
|
href=self.linker.get_lazyhref(sourcefile)))
|
||||||
|
|
||||||
snippet = H.ClassDescription(
|
snippet = H.ClassDescription(
|
||||||
# XXX bases HTML
|
# XXX bases HTML
|
||||||
H.ClassDef('%s(' % (clsname,), *bases),
|
H.ClassDef(clsname, bases, docstring, sourcelink,
|
||||||
H.Docstring(docstring or '*no docstring available*'),
|
properties, methods),
|
||||||
sourcelink,
|
|
||||||
*(properties+methods)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return snippet
|
return snippet
|
||||||
|
|
||||||
def build_bases(self, dotted_name):
|
def build_bases(self, dotted_name):
|
||||||
basehtml = []
|
ret = []
|
||||||
bases = self.dsa.get_possible_base_classes(dotted_name)
|
bases = self.dsa.get_possible_base_classes(dotted_name)
|
||||||
for base in bases:
|
for base in bases:
|
||||||
try:
|
try:
|
||||||
obj = self.dsa.get_obj(base.name)
|
obj = self.dsa.get_obj(base.name)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
basehtml.append(base.name)
|
ret.append((base.name, None))
|
||||||
else:
|
else:
|
||||||
href = self.linker.get_lazyhref(base.name)
|
href = self.linker.get_lazyhref(base.name)
|
||||||
basehtml.append(H.BaseDescription(base.name, href=href))
|
ret.append((base.name, href))
|
||||||
basehtml.append(',')
|
return ret
|
||||||
if basehtml:
|
|
||||||
basehtml.pop()
|
|
||||||
basehtml.append('):')
|
|
||||||
return basehtml
|
|
||||||
|
|
||||||
def build_properties(self, cls):
|
def build_properties(self, cls):
|
||||||
properties = []
|
properties = []
|
||||||
|
@ -411,24 +406,17 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
val = '<property object (dynamically calculated value)>'
|
val = '<property object (dynamically calculated value)>'
|
||||||
properties.append((attr, val))
|
properties.append((attr, val))
|
||||||
properties.sort(key=lambda a: a[0]) # sort on name
|
properties.sort(key=lambda a: a[0]) # sort on name
|
||||||
ret = []
|
return properties
|
||||||
if properties:
|
|
||||||
ret.append(H.h2('properties:'))
|
|
||||||
for name, val in properties:
|
|
||||||
ret.append(H.PropertyDescription(name, val))
|
|
||||||
return ret
|
|
||||||
|
|
||||||
def build_methods(self, dotted_name):
|
def build_methods(self, dotted_name):
|
||||||
ret = []
|
ret = []
|
||||||
methods = self.dsa.get_class_methods(dotted_name)
|
methods = self.dsa.get_class_methods(dotted_name)
|
||||||
if methods:
|
if '__init__' in methods:
|
||||||
ret.append(H.h2('methods:'))
|
methods.remove('__init__')
|
||||||
if '__init__' in methods:
|
methods.insert(0, '__init__')
|
||||||
methods.remove('__init__')
|
for method in methods:
|
||||||
methods.insert(0, '__init__')
|
ret += self.build_callable_view('%s.%s' % (dotted_name,
|
||||||
for method in methods:
|
method))
|
||||||
ret += self.build_callable_view('%s.%s' % (dotted_name,
|
|
||||||
method))
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
|
def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
|
||||||
|
@ -455,6 +443,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
def prepare_class_pages(self, classes_dotted_names):
|
def prepare_class_pages(self, classes_dotted_names):
|
||||||
passed = []
|
passed = []
|
||||||
for dotted_name in sorted(classes_dotted_names):
|
for dotted_name in sorted(classes_dotted_names):
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('preparing: %s\n' % (dotted_name,))
|
||||||
parent_dotted_name, _ = split_of_last_part(dotted_name)
|
parent_dotted_name, _ = split_of_last_part(dotted_name)
|
||||||
try:
|
try:
|
||||||
sibling_dotted_names = self.namespace_tree[parent_dotted_name]
|
sibling_dotted_names = self.namespace_tree[parent_dotted_name]
|
||||||
|
@ -471,6 +461,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
def build_class_pages(self, data, project):
|
def build_class_pages(self, data, project):
|
||||||
""" build the full api pages for a set of classes """
|
""" build the full api pages for a set of classes """
|
||||||
for dotted_name, tag, nav, reltargetpath in data:
|
for dotted_name, tag, nav, reltargetpath in data:
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('building: %s\n' % (dotted_name,))
|
||||||
title = 'api documentation for %s' % (dotted_name,)
|
title = 'api documentation for %s' % (dotted_name,)
|
||||||
self.write_page(title, reltargetpath, project, tag, nav)
|
self.write_page(title, reltargetpath, project, tag, nav)
|
||||||
|
|
||||||
|
@ -497,6 +489,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
def prepare_function_pages(self, method_dotted_names):
|
def prepare_function_pages(self, method_dotted_names):
|
||||||
passed = []
|
passed = []
|
||||||
for dotted_name in sorted(method_dotted_names):
|
for dotted_name in sorted(method_dotted_names):
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('preparing: %s\n' % (dotted_name,))
|
||||||
# XXX should we create a build_function_view instead?
|
# XXX should we create a build_function_view instead?
|
||||||
parent_dotted_name, _ = split_of_last_part(dotted_name)
|
parent_dotted_name, _ = split_of_last_part(dotted_name)
|
||||||
sibling_dotted_names = self.namespace_tree[parent_dotted_name]
|
sibling_dotted_names = self.namespace_tree[parent_dotted_name]
|
||||||
|
@ -509,6 +503,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
|
|
||||||
def build_function_pages(self, data, project):
|
def build_function_pages(self, data, project):
|
||||||
for dotted_name, tag, nav, reltargetpath in data:
|
for dotted_name, tag, nav, reltargetpath in data:
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('building: %s\n' % (dotted_name,))
|
||||||
title = 'api documentation for %s' % (dotted_name,)
|
title = 'api documentation for %s' % (dotted_name,)
|
||||||
self.write_page(title, reltargetpath, project, tag, nav)
|
self.write_page(title, reltargetpath, project, tag, nav)
|
||||||
|
|
||||||
|
@ -521,6 +517,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
function_names = self.dsa.get_function_names()
|
function_names = self.dsa.get_function_names()
|
||||||
class_names = self.dsa.get_class_names()
|
class_names = self.dsa.get_class_names()
|
||||||
for dotted_name in sorted(names):
|
for dotted_name in sorted(names):
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('preparing: %s\n' % (dotted_name,))
|
||||||
if dotted_name in function_names or dotted_name in class_names:
|
if dotted_name in function_names or dotted_name in class_names:
|
||||||
continue
|
continue
|
||||||
subitem_dotted_names = self.namespace_tree[dotted_name]
|
subitem_dotted_names = self.namespace_tree[dotted_name]
|
||||||
|
@ -537,6 +535,8 @@ class ApiPageBuilder(AbstractPageBuilder):
|
||||||
|
|
||||||
def build_namespace_pages(self, data, project):
|
def build_namespace_pages(self, data, project):
|
||||||
for dotted_name, tag, nav, reltargetpath in data:
|
for dotted_name, tag, nav, reltargetpath in data:
|
||||||
|
#if self.capture:
|
||||||
|
# self.capture.err.writeorg('building: %s\n' % (dotted_name,))
|
||||||
if dotted_name == '':
|
if dotted_name == '':
|
||||||
dotted_name = self.dsa.get_module_name().split('/')[-1]
|
dotted_name = self.dsa.get_module_name().split('/')[-1]
|
||||||
title = 'index of %s namespace' % (dotted_name,)
|
title = 'index of %s namespace' % (dotted_name,)
|
||||||
|
|
|
@ -116,7 +116,7 @@ class AbstractBuilderTest(object):
|
||||||
self.namespace_tree = namespace_tree
|
self.namespace_tree = namespace_tree
|
||||||
self.apb = ApiPageBuilder(base, linker, self.dsa,
|
self.apb = ApiPageBuilder(base, linker, self.dsa,
|
||||||
self.fs_root.join(self.pkg_name),
|
self.fs_root.join(self.pkg_name),
|
||||||
namespace_tree, 'root docstring')
|
namespace_tree)
|
||||||
self.spb = SourcePageBuilder(base, linker,
|
self.spb = SourcePageBuilder(base, linker,
|
||||||
self.fs_root.join(self.pkg_name))
|
self.fs_root.join(self.pkg_name))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue