Update of /cvsroot/happydoc/HappyDoc3/happydoclib/docset
In directory sc8-pr-cvs1:/tmp/cvs-serv16183/happydoclib/docset
Modified Files:
docset_MultiHTMLFile.py
Log Message:
Switch section headers/footers to use table formatting like HappyDoc
2.0. A new docset will be written to use CSS later, but for now this
makes it easier to see whether the basic work is correct.
Add function information to the module output.
Index: docset_MultiHTMLFile.py
===================================================================
RCS file: /cvsroot/happydoc/HappyDoc3/happydoclib/docset/docset_MultiHTMLFile.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** docset_MultiHTMLFile.py 28 Dec 2002 14:27:32 -0000 1.11
--- docset_MultiHTMLFile.py 28 Dec 2002 15:59:51 -0000 1.12
***************
*** 56,60 ****
--- 56,65 ----
#
import os
+ try:
+ from cStringIO import StringIO
+ except:
+ from StringIO import StringIO
import time
+ import token
#
***************
*** 207,212 ****
output.write('''
<tr>
! <td>%(name)s</td>
! <td>''' % locals())
self.writeText(output, text, text_format)
--- 212,217 ----
output.write('''
<tr>
! <td valign="top"><p>%(name)s</p></td>
! <td valign="top">''' % locals())
self.writeText(output, text, text_format)
***************
*** 219,222 ****
--- 224,234 ----
return
+ def writeList(self, output, listElements):
+ output.write('<p>\n')
+ for list_element in listElements:
+ output.write('%s<br>\n' % list_element)
+ output.write('</p>\n')
+ return
+
def _computeRelativeHREF(self, source, destination):
"""Compute the HREF to point from the output file of source to destination.
***************
*** 259,263 ****
return '<a href="%s">%s</a>' % (href, title)
! def _writeTOCReferencesSection(self, output, packageTreeNode, title, moduleList):
"""Write a list of references in the table of contents.
--- 271,331 ----
return '<a href="%s">%s</a>' % (href, title)
! def writeSectionTitle(self, output, title, subtitle, anchor=None):
! bgcolor = self.levelTwoHeadingBackgroundColor
! fgcolor = self.levelTwoHeadingForegroundColor
! output.write('''
! <tr>
! <th bgcolor="%(bgcolor)s"
! rowspan="2"
! valign="top"
! align="left"
! width="20%%"
! >
! <font color="%(fgcolor)s">
! <a name="%(anchor)s">%(title)s</a>
! </font>
! </th>
! <th bgcolor="%(bgcolor)s"
! valign="top"
! align="left"
! width="80%%"
! >
! <font color="%(fgcolor)s">%(subtitle)s </font>
! </th>
! </tr>
! <tr>
! <td>
! ''' % locals())
! #output.write('<h%s>%s</h%s>\n' % (level, title, level))
! return
!
! def pushSectionLevel(self, output, title, subtitle='', anchor=''):
! """Generate the text and styles to begin a new section one deeper than the previous level.
! """
! output.write(
! '<table border="0" cellpadding="5" cellspacing="0" width="100%">\n'
! )
! self.writeSectionTitle(output,
! title=title,
! subtitle=subtitle,
! anchor=anchor,
! )
! return
!
! def writeSectionFooter(self, output):
! output.write('</td></tr>\n')
! return
!
! def popSectionLevel(self, output):
! self.writeSectionFooter(output)
! output.write('</table>')
! return
!
! def _writeTOCReferencesSection(self,
! output,
! packageTreeNode,
! title,
! moduleList,
! ):
"""Write a list of references in the table of contents.
***************
*** 278,284 ****
for name, node in moduleList ]
if descriptive_list:
! output.write('<h4>%s</h4>\n' % title)
descriptive_list.sort()
self._writeDescriptiveList(output, descriptive_list)
return
--- 346,356 ----
for name, node in moduleList ]
if descriptive_list:
! self.pushSectionLevel(output, title)
!
descriptive_list.sort()
self._writeDescriptiveList(output, descriptive_list)
+
+ if descriptive_list:
+ self.popSectionLevel(output)
return
***************
*** 461,465 ****
import_data = packageTreeNode.module_info.getImportData()
if import_data:
! output.write('<h4>Imported Modules</h4>\n')
output.write('<p>\n')
--- 533,538 ----
import_data = packageTreeNode.module_info.getImportData()
if import_data:
! self.pushSectionLevel(output, 'Imported Modules')
!
output.write('<p>\n')
***************
*** 509,512 ****
--- 582,787 ----
output.write('</p>\n')
+
+ self.popSectionLevel(output)
+
+ return
+
+ def _writePreformatted(self, output, text):
+ """Write text as a preformatted section.
+ """
+ output.write('<pre>\n')
+ output.write(text)
+ if text and text[-1] != '\n':
+ output.write('\n')
+ output.write('</pre>\n')
+ return
+
+ def _writeFunctionParameter(self, output, name, info):
+ '''Write a function parameter to the output.
+
+ No indenting or formatting is performed. The output
+ looks like::
+
+ name
+
+ or
+
+ name=default
+
+ Parameters:
+
+ name -- name of the parameter
+
+ info -- tuple of (default_specified, default_value,
+ default_value_type)
+ concerning the default value of the parameter
+
+ output -- destination for written output
+
+ '''
+ output.write(name)
+ default_specified, default_value, default_value_type = info
+ if default_specified:
+ output.write('=')
+ if default_value_type == token.STRING:
+ output.write(`default_value`)
+ elif default_value_type == token.NUMBER:
+ output.write(str(default_value))
+ else:
+ #print 'FUNCTION DEFAULT VALUE (%s, %s): "%s"' % (
+ # type(default_value),
+ # default_value_type or 'Unknown',
+ # default_value)
+ output.write(str(default_value))
+ return
+
+ def _writeFunctionSignature(self,
+ output,
+ packageTreeNode,
+ function,
+ ):
+ """Write the function signature for 'function' to 'output'.
+
+ Parameters
+
+ output -- Where to write.
+
+ pacakgeTreeNode -- The part of the input we are processing.
+
+ function -- Instance of FunctionInfo from parseinfo module.
+
+ """
+ function_name = function.getName()
+ signature_buffer = StringIO()
+ signature_buffer.write('%s (' % function_name)
+ parameter_names = function.getParameterNames()
+ if parameter_names:
+ if len(parameter_names) <= 2:
+ for param in parameter_names:
+ param_info = function.getParameterInfo(param)
+ signature_buffer.write(' ')
+ self._writeFunctionParameter(signature_buffer,
+ param,
+ param_info,
+ )
+ if param != parameter_names[-1]:
+ signature_buffer.write(',')
+ signature_buffer.write(' ')
+ else:
+ signature_buffer.write('\n')
+ indent = 8 #len(name) + 3
+ for param in parameter_names:
+ signature_buffer.write(' ' * indent)
+ param_info = function.getParameterInfo(param)
+ self._writeFunctionParameter(signature_buffer,
+ param,
+ param_info,
+ )
+ signature_buffer.write(',\n')
+ signature_buffer.write('%s' % (' ' * indent))
+ signature_buffer.write(')\n')
+
+ self._writePreformatted(output, signature_buffer.getvalue())
+ return
+
+ def _writeExceptionListForFunction(self, output, function):
+ """Write the list of exceptions raised by a function.
+
+ Parameters
+
+ output -- Where to write.
+
+ function -- FunctionInfo from parseinfo module.
+
+ listHeader -- Header for list being generated.
+
+ """
+ exception_names = function.getExceptionNames()
+ if not exception_names:
+ return
+
+ if self.sort_names:
+ exception_names.sort()
+
+ exception_list = []
+
+ for name in exception_names:
+ #exception_class = self.getClassInfo(name)
+ exception_class = None
+
+ if exception_class:
+ ref = formatter.getReference( exception_class,
+ #output_reduced_name,
+ output.name,
+ )
+ else:
+ #ref = formatter.getPythonReference( name )
+ ref = name
+
+ exception_list.append(ref)
+
+ self.pushSectionLevel(output, 'Exceptions')
+ self.writeList(output, exception_list)
+ self.popSectionLevel(output)
+
+ return
+
+ def _writeOneFunctionToOutput(self,
+ output,
+ packageTreeNode,
+ functionInfo,
+ ):
+ self.pushSectionLevel(output,
+ title='',
+ subtitle=functionInfo.getName(),
+ anchor=functionInfo.getName(),
+ )
+ #
+ # Signature
+ #
+ self._writeFunctionSignature(output, packageTreeNode, functionInfo)
+
+ #
+ # Description
+ #
+ docstring_text = functionInfo.getDocString()
+ docstring_format = functionInfo.getDocStringFormat()
+ self.writeText(output, docstring_text, docstring_format)
+
+ #
+ # Exceptions
+ #
+ self._writeExceptionListForFunction(output, functionInfo)
+
+ self.popSectionLevel(output)
+ return
+
+ def _writeFunctionsToOutput(self, output, packageTreeNode):
+ """Writes information about functions in this module to the output stream.
+ """
+ function_names = self._filterNames(packageTreeNode.module_info.getFunctionNames())
+ if not function_names:
+ return
+
+ if self.sort_names:
+ function_names.sort()
+
+ #
+ # Section header
+ #
+ self.pushSectionLevel(output, 'Functions')
+
+ #
+ # Functions
+ #
+
+ for function_name in function_names:
+ self._writeOneFunctionToOutput(
+ output,
+ packageTreeNode,
+ packageTreeNode.module_info.getFunctionInfo(function_name),
+ )
+
+ self.popSectionLevel(output)
return
***************
*** 515,519 ****
"""
self._writePythonFileImportsToOutput(output, packageTreeNode)
! # Functions
# Classes
return
--- 790,794 ----
"""
self._writePythonFileImportsToOutput(output, packageTreeNode)
! self._writeFunctionsToOutput(output, packageTreeNode)
# Classes
return
|