Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/ModuleListing.py
    1| # $Id: ModuleListing.py,v 1.11 2002/11/02 06:37:37 chalky Exp $
    2| #
    3| # This file is a part of Synopsis.
    4| # Copyright (C) 2000, 2001 Stephen Davies
    5| # Copyright (C) 2000, 2001 Stefan Seefeld
    6| #
    7| # Synopsis is free software; you can redistribute it and/or modify it
    8| # under the terms of the GNU General Public License as published by
    9| # the Free Software Foundation; either version 2 of the License, or
   10| # (at your option) any later version.
   11| #
   12| # This program is distributed in the hope that it will be useful,
   13| # but WITHOUT ANY WARRANTY; without even the implied warranty of
   14| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15| # General Public License for more details.
   16| #
   17| # You should have received a copy of the GNU General Public License
   18| # along with this program; if not, write to the Free Software
   19| # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   20| # 02111-1307, USA.
   21| #
   22| # $Log: ModuleListing.py,v $
   23| # Revision 1.11  2002/11/02 06:37:37  chalky
   24| # Allow non-frames output, some refactoring of page layout, new modules.
   25| #
   26| # Revision 1.10  2002/11/01 07:21:15  chalky
   27| # More HTML formatting fixes eg: ampersands and stuff
   28| #
   29| # Revision 1.9  2002/07/04 06:43:18  chalky
   30| # Improved support for absolute references - pages known their full path.
   31| #
   32| # Revision 1.8  2001/07/05 05:39:58  stefan
   33| # advanced a lot in the refactoring of the HTML module.
   34| # Page now is a truely polymorphic (abstract) class. Some derived classes
   35| # implement the 'filename()' method as a constant, some return a variable
   36| # dependent on what the current scope is...
   37| #
   38| # Revision 1.7  2001/07/05 02:08:35  uid20151
   39| # Changed the registration of pages to be part of a two-phase construction
   40| #
   41| # Revision 1.6  2001/06/28 07:22:18  stefan
   42| # more refactoring/cleanup in the HTML formatter
   43| #
   44| # Revision 1.5  2001/06/26 04:32:16  stefan
   45| # A whole slew of changes mostly to fix the HTML formatter's output generation,
   46| # i.e. to make the output more robust towards changes in the layout of files.
   47| #
   48| # the rpm script now works, i.e. it generates source and binary packages.
   49| #
   50| # Revision 1.4  2001/06/05 10:04:36  chalky
   51| # Can filter modules based on type, eg: 'Package'
   52| #
   53| # Revision 1.3  2001/06/05 05:28:34  chalky
   54| # Some old tree abstraction
   55| #
   56| # Revision 1.6  2001/04/18 04:08:03  chalky
   57| # Sort modules so that packages come first
   58| #
   59| # Revision 1.5  2001/04/17 13:36:10  chalky
   60| # Slight enhancement to JSTree and derivatives, to use a dot graphic for leaves
   61| #
   62| # Revision 1.4  2001/03/29 14:11:33  chalky
   63| # Refactoring for use by RefManual's own derived module
   64| #
   65| # Revision 1.3  2001/02/06 05:12:46  chalky
   66| # Added JSTree class and FileTreeJS and modified ModuleListingJS to use JSTree
   67| #
   68| # Revision 1.2  2001/02/05 07:58:39  chalky
   69| # Cleaned up image copying for *JS. Added synopsis logo to ScopePages.
   70| #
   71| # Revision 1.1  2001/02/05 05:31:52  chalky
   72| # Initial commit. Image finding is a hack
   73| #
   74| # Revision 1.2  2001/02/01 15:23:24  chalky
   75| # Copywritten brown paper bag edition.
   76| #
   77| #
   78| 
   79| # System modules
   80| import os
   81| 
   82| # Synopsis modules
   83| from Synopsis.Core import AST, Util
   84| 
   85| # HTML modules
   86| import core
   87| import Page
   88| from core import config
   89| from Tags import *
   90| 
   91| 
   92| class ModuleListing(Page.Page): 
   93|     """Create an index of all modules with JS. The JS allows the user to
   94|     expand/collapse sections of the tree!"""
   95|     def __init__(self, manager):
   96|         Page.Page.__init__(self, manager)
   97|         self.child_types = None
   98|         self._children_cache = {}
   99|         self.__short_title = 'Modules'
  100|         if hasattr(config.obj, 'ModuleListing'):
  101|             myconfig = config.obj.ModuleListing
  102|             if hasattr(myconfig, 'short_title'):
  103|                 self.__short_title = myconfig.short_title
  104| 
  105|     def filename(self): return config.files.nameOfSpecial('ModuleListing')
  106|     def title(self): return self.__short_title + ' Listing'
  107| 
  108|     def register(self):
  109|         "registers the page with the manager for the 'contents' (top left) frame"
  110|         filename = self.filename()
  111|         config.set_contents_page(filename)
  112|         self.manager.addRootPage(filename, self.__short_title, 'contents', 2)
  113|         self._link_target = 'index'
  114| 
  115|     def process(self, start):
  116|         """Create a page with an index of all modules"""
  117|         # Init tree
  118|         self.tree = config.treeFormatterClass(self)
  119|         # Init list of module types to display
  120|         try: self.child_types = config.obj.ModuleListing.child_types
  121|         except AttributeError: pass
  122|         # Create the file
  123|         self.start_file()
  124|         self.write(self.manager.formatHeader(self.filename(), 2))
  125|         self.tree.startTree()
  126|         self.indexModule(start, start.name())
  127|         self.tree.endTree()
  128|         self.end_file()
  129| 
  130|     def _child_filter(self, child):
  131|         """Returns true if the given child declaration is to be included"""
  132|         if not isinstance(child, AST.Module): return 0
  133|         if self.child_types and child.type() not in self.child_types:
  134|             return 0
  135|         return 1
  136|     def _link_href(self, ns):
  137|         """Returns the link to the given declaration"""
  138|         return rel(self.filename(), config.files.nameOfModuleIndex(ns.name()))
  139|     def _get_children(self, decl):
  140|         """Returns the children of the given declaration"""
  141|         try: return self._children_cache[decl]
  142|         except KeyError: pass
  143|         config.sorter.set_scope(decl)
  144|         config.sorter.sort_sections()
  145|         children = config.sorter.children()
  146|         children = filter(self._child_filter, children)
  147|         self._children_cache[decl] = children
  148|         return children
  149|     def indexModule(self, ns, rel_scope):
  150|         "Write a link for this module and recursively visit child modules."
  151|         my_scope = ns.name()
  152|         # Find children, and sort so that compound children (packages) go first
  153|         children = self._get_children(ns)
  154|         children.sort(lambda a,b,g=self._get_children:
  155|             cmp(len(g(b)),len(g(a))))
  156|         # Print link to this module
  157|         name = Util.ccolonName(my_scope, rel_scope) or "Global Namespace"
  158|         link = self._link_href(ns)
  159|         text = href(link, name, target=self._link_target)
  160|         if not len(children):
  161|             self.tree.writeLeaf(text)
  162|         else:
  163|             self.tree.writeNodeStart(text)
  164|             # Add children
  165|             for child in children:
  166|                self.indexModule(child, my_scope)
  167|             self.tree.writeNodeEnd()
  168| 
  169| htmlPageClass = ModuleListing
  170|