[py-svn] r37256 - py/dist/py/apigen

guido at codespeak.net guido at codespeak.net
Wed Jan 24 13:45:14 CET 2007


Author: guido
Date: Wed Jan 24 13:45:13 2007
New Revision: 37256

Modified:
   py/dist/py/apigen/apigen.py
   py/dist/py/apigen/htmlgen.py
Log:
Some style fixes and small HTML tweaks, fixed source links pointing to outside
the package (for methods that are defined on superclasses that live outside the
package).


Modified: py/dist/py/apigen/apigen.py
==============================================================================
--- py/dist/py/apigen/apigen.py	(original)
+++ py/dist/py/apigen/apigen.py	Wed Jan 24 13:45:13 2007
@@ -36,7 +36,7 @@
 
     all_names = dsa._get_names(filter=lambda x, y: True)
     namespace_tree = htmlgen.create_namespace_tree(all_names)
-    apb = htmlgen.ApiPageBuilder(targetdir, l, dsa)
+    apb = htmlgen.ApiPageBuilder(targetdir, l, dsa, pkgdir)
     spb = htmlgen.SourcePageBuilder(targetdir, l, pkgdir)
 
     ns_data = apb.prepare_namespace_pages(namespace_tree)

Modified: py/dist/py/apigen/htmlgen.py
==============================================================================
--- py/dist/py/apigen/htmlgen.py	(original)
+++ py/dist/py/apigen/htmlgen.py	Wed Jan 24 13:45:13 2007
@@ -14,7 +14,7 @@
 # HTML related stuff
 class H(html):
     class Description(html.div):
-        style = html.Style(margin_left='10em')
+        style = html.Style(margin_left='15em')
     
     class NamespaceDescription(Description):
         pass
@@ -47,10 +47,11 @@
         pass
 
     class Docstring(html.div):
-        style = html.Style(white_space='pre')
+        style = html.Style(white_space='pre', min_height='3em')
 
     class Navigation(html.div):
-        style = html.Style(min_height='99%', float='left', margin_top='1.2em')
+        style = html.Style(min_height='99%', float='left', margin_top='1.2em',
+                           overflow='auto', width='15em', white_space='nowrap')
 
     class NavigationItem(html.div):
         pass
@@ -62,10 +63,10 @@
         pass
 
     class NonPythonSource(html.pre):
-        style = html.Style(margin_left='10em')
+        style = html.Style(margin_left='15em')
 
     class DirList(html.div):
-        style = html.Style(margin_left='10em')
+        style = html.Style(margin_left='15em')
 
     class DirListItem(html.div):
         pass
@@ -279,10 +280,12 @@
 
 class ApiPageBuilder(AbstractPageBuilder):
     """ builds the html for an api docs page """
-    def __init__(self, base, linker, dsa):
+    def __init__(self, base, linker, dsa, projroot):
         self.base = base
         self.linker = linker
         self.dsa = dsa
+        self.projroot = projroot
+        self.projpath = py.path.local(projroot)
         
     def build_callable_view(self, dotted_name):
         """ build the html for a class method """
@@ -295,13 +298,19 @@
 
         sourcefile = inspect.getsourcefile(func)
         callable_source = self.dsa.get_function_source(dotted_name)
+        is_in_pkg = py.path.local(sourcefile).relto(self.projpath)
         # i assume they're both either available or unavailable(XXX ?)
-        if sourcefile and callable_source:
+        if is_in_pkg and sourcefile and callable_source:
             csource = H.div(H.br(),
-                            H.a('source:',
+                            H.a('origin: %s' % (sourcefile,),
                                 href=self.linker.get_lazyhref(sourcefile)),
                             H.br(),
                             H.SourceDef(H.pre(callable_source)))
+        elif not is_in_pkg and sourcefile and callable_source:
+            csource = H.div(H.br(),
+                            H.em('origin: %s' % (sourcefile,)),
+                            H.br(),
+                            H.SourceDef(H.pre(callable_source)))
         else:
             csource = H.SourceDef('could not get source file')
 
@@ -328,7 +337,7 @@
             else:
                 if sourcefile[-1] in ['o', 'c']:
                     sourcefile = sourcefile[:-1]
-                sourcelink = H.div(H.a('source',
+                sourcelink = H.div(H.a('view source',
                     href=self.linker.get_lazyhref(sourcefile)))
 
         docstring = cls.__doc__
@@ -354,20 +363,28 @@
         snippet = H.ClassDescription(
             # XXX bases HTML
             H.ClassDef('%s(' % (clsname,), *basehtml),
-            sourcelink,
             H.Docstring(docstring or H.em('no docstring available')),
+            sourcelink,
         )
-        snippet.append(H.h2('Functions:'))
-        for method in methods:
-            snippet += self.build_callable_view('%s.%s' % (dotted_name,
-                                                method))
+        if methods:
+            snippet.append(H.h2('methods:'))
+            for method in methods:
+                snippet += self.build_callable_view('%s.%s' % (dotted_name,
+                                                    method))
+        # XXX properties
         return snippet
 
     def build_namespace_view(self, namespace_dotted_name, item_dotted_names):
         """ build the html for a namespace (module) """
-        print 'building namespace for', namespace_dotted_name
+        try:
+            obj = self.dsa.get_obj(namespace_dotted_name)
+        except KeyError:
+            docstring = None
+        else:
+            docstring = obj.__doc__
         snippet = H.NamespaceDescription(
             H.NamespaceDef(namespace_dotted_name),
+            H.Docstring(docstring or H.em('no docstring available'))
         )
         for dotted_name in item_dotted_names:
             itemname = dotted_name.split('.')[-1]



More information about the pytest-commit mailing list