def _build_doc(self): """Create the user function class documentation. @return: The user function class documentation to use in the help system. @rtype: str """ # Initialise. doc = "" # The title. doc += build_subtitle("The %s user function class." % self._name, start_nl=False) # The synopsis. doc += build_subtitle("Synopsis") doc += self._desc doc += "\n\n" # Usage help string. doc += build_subtitle("Usage") doc += format_text(relax_class_help) doc += "\n" # Add a description to the help string. if hasattr(self, '__description__'): doc += build_subtitle("Description") doc += "\n\n%s\n" % strip_lead(self.__description__) # The member user functions. doc += build_subtitle("Contents") doc += "This class contains the following user functions:\n\n" for uf_name, uf in uf_info.uf_loop(self._name): # The unformatted text. text = " %s: %s" % (uf_name, uf.title) # Format. text = format_text(text) # Replace the arg text with bold text. length = 7 + len(uf_name) text = " %s: %s" % (bold_text(uf_name), text[length:]) # Add to the docstring. doc += "%s\n" % text # Return the documentation. return doc
def _build_doc(self): """Create the user function documentation. @return: The user function documentation to use in the help system. @rtype: str """ # Checks. if not isinstance(self._desc, list): raise RelaxError( "The user function 'desc' variable must be a list of Desc_container instances." ) for i in range(len(self._desc)): if not isinstance(self._desc[i], Desc_container): raise RelaxError( "The user function 'desc' list element '%s' must be a list of Desc_container instances." % self._desc[i]) # Initialise. doc = "" # The title. doc += build_subtitle("The %s user function." % self._name, start_nl=False) # The synopsis. doc += build_subtitle("Synopsis") doc += "%s" % self._title doc += "\n\n" # The defaults. doc += build_subtitle("Defaults") keys = [] values = [] for i in range(self._karg_num): keys.append(self._kargs[i]['name']) values.append(self._kargs[i]['default']) doc += "%s" % format_text(self._intro_text(keys, values, prompt=False)) doc += "\n\n" # Add the keyword args. if self._kargs != None: doc += build_subtitle("Keyword Arguments") for i in range(len(self._kargs)): # The unformatted text. text = " %s: %s" % (self._kargs[i]['name'], self._kargs[i]['desc']) # Format. text = format_text(text) # Replace the arg text with bold text. length = 7 + len(self._kargs[i]['name']) text = " %s: %s" % (bold_text( self._kargs[i]['name']), text[length:]) # Add to the docstring. doc += "%s\n" % text # Add the description sections. if isinstance(self._desc, list) and len(self._desc): # Loop over the sections. for i in range(len(self._desc)): # The title. doc += build_subtitle(self._desc[i].get_title()) # Loop over the elements. for type, element in self._desc[i].element_loop(): # A paragraph or verbatim text. if type == 'paragraph': doc += format_text(element) + '\n' # Verbatim text. elif type == 'verbatim': doc += element + '\n\n' # A list. elif type == 'list': # Loop over the list elements. for j in range(len(element)): doc += format_text(" - %s" % element[j]) # Final newline. doc += '\n' # An itemised list. elif type == 'item list': # Loop over the list elements. for j in range(len(element)): # No item. if element[j][0] in [None, '']: doc += format_text(" %s" % element[j][1]) else: doc += format_text( " %s: %s" % (element[j][0], element[j][1])) # Final newline. doc += '\n' # A table. elif type == 'table': doc += create_table(element) + '\n' # A prompt example. elif type == 'prompt': # Loop over the prompt examples. for j in range(len(element)): doc += format_text(element[j]) # Final double newline. doc += '\n\n' # Return the documentation. return doc
def _build_doc(self): """Create the user function documentation. @return: The user function documentation to use in the help system. @rtype: str """ # Checks. if not isinstance(self._desc, list): raise RelaxError("The user function 'desc' variable must be a list of Desc_container instances.") for i in range(len(self._desc)): if not isinstance(self._desc[i], Desc_container): raise RelaxError("The user function 'desc' list element '%s' must be a list of Desc_container instances." % self._desc[i]) # Initialise. doc = "" # The title. doc += build_subtitle("The %s user function." % self._name, start_nl=False) # The synopsis. doc += build_subtitle("Synopsis") doc += "%s" % self._title doc += "\n\n" # The defaults. doc += build_subtitle("Defaults") keys = [] values = [] for i in range(self._karg_num): keys.append(self._kargs[i]['name']) values.append(self._kargs[i]['default']) doc += "%s" % format_text(self._intro_text(keys, values, prompt=False)) doc += "\n\n" # Add the keyword args. if self._kargs != None: doc += build_subtitle("Keyword Arguments") for i in range(len(self._kargs)): # The unformatted text. text = " %s: %s" % (self._kargs[i]['name'], self._kargs[i]['desc']) # Format. text = format_text(text) # Replace the arg text with bold text. length = 7 + len(self._kargs[i]['name']) text = " %s: %s" % (bold_text(self._kargs[i]['name']), text[length:]) # Add to the docstring. doc += "%s\n" % text # Add the description sections. if isinstance(self._desc, list) and len(self._desc): # Loop over the sections. for i in range(len(self._desc)): # The title. doc += build_subtitle(self._desc[i].get_title()) # Loop over the elements. for type, element in self._desc[i].element_loop(): # A paragraph or verbatim text. if type == 'paragraph': doc += format_text(element) + '\n' # Verbatim text. elif type == 'verbatim': doc += element + '\n\n' # A list. elif type == 'list': # Loop over the list elements. for j in range(len(element)): doc += format_text(" - %s" % element[j]) # Final newline. doc += '\n' # An itemised list. elif type == 'item list': # Loop over the list elements. for j in range(len(element)): # No item. if element[j][0] in [None, '']: doc += format_text(" %s" % element[j][1]) else: doc += format_text(" %s: %s" % (element[j][0], element[j][1])) # Final newline. doc += '\n' # A table. elif type == 'table': doc += create_table(element) + '\n' # A prompt example. elif type == 'prompt': # Loop over the prompt examples. for j in range(len(element)): doc += format_text(element[j]) # Final double newline. doc += '\n\n' # Return the documentation. return doc