Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/ModuleListingJS.py
    1| # $Id: ModuleListingJS.py,v 1.9 2001/07/05 05:39:58 stefan 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: ModuleListingJS.py,v $
   23| # Revision 1.9  2001/07/05 05:39:58  stefan
   24| # advanced a lot in the refactoring of the HTML module.
   25| # Page now is a truely polymorphic (abstract) class. Some derived classes
   26| # implement the 'filename()' method as a constant, some return a variable
   27| # dependent on what the current scope is...
   28| #
   29| # Revision 1.8  2001/06/28 07:22:18  stefan
   30| # more refactoring/cleanup in the HTML formatter
   31| #
   32| # Revision 1.7  2001/06/26 04:32:16  stefan
   33| # A whole slew of changes mostly to fix the HTML formatter's output generation,
   34| # i.e. to make the output more robust towards changes in the layout of files.
   35| #
   36| # the rpm script now works, i.e. it generates source and binary packages.
   37| #
   38| # Revision 1.6  2001/04/18 04:08:03  chalky
   39| # Sort modules so that packages come first
   40| #
   41| # Revision 1.5  2001/04/17 13:36:10  chalky
   42| # Slight enhancement to JSTree and derivatives, to use a dot graphic for leaves
   43| #
   44| # Revision 1.4  2001/03/29 14:11:33  chalky
   45| # Refactoring for use by RefManual's own derived module
   46| #
   47| # Revision 1.3  2001/02/06 05:12:46  chalky
   48| # Added JSTree class and FileTreeJS and modified ModuleListingJS to use JSTree
   49| #
   50| # Revision 1.2  2001/02/05 07:58:39  chalky
   51| # Cleaned up image copying for *JS. Added synopsis logo to ScopePages.
   52| #
   53| # Revision 1.1  2001/02/05 05:31:52  chalky
   54| # Initial commit. Image finding is a hack
   55| #
   56| # Revision 1.2  2001/02/01 15:23:24  chalky
   57| # Copywritten brown paper bag edition.
   58| #
   59| #
   60| 
   61| # System modules
   62| import os
   63| 
   64| # Synopsis modules
   65| from Synopsis.Core import AST, Util
   66| 
   67| # HTML modules
   68| import core
   69| import JSTree
   70| from core import config
   71| from Tags import *
   72| 
   73| 
   74| class ModuleListingJS(JSTree.JSTree): 
   75|     """Create an index of all modules with JS. The JS allows the user to
   76|     expand/collapse sections of the tree!"""
   77|     def __init__(self, manager):
   78|         JSTree.JSTree.__init__(self, manager)
   79|         self._children_cache = {}
   80|         self._init_page()
   81| 
   82|     def _init_page(self):
   83|         "Sets _filename and registers the page with the manager"
   84|         filename = config.files.nameOfSpecial('ModuleTree')
   85|         config.set_contents_page(filename)
   86|         self.manager.addRootPage(filename, 'Modules', 'contents', 2)
   87|         self._link_target = 'index'
   88| 
   89|     def filename(self): return config.files.nameOfSpecial('ModuleTree')
   90|     def title(self): return 'Module Tree'
   91| 
   92|     def process(self, start):
   93|         """Create a page with an index of all modules"""
   94|         # Init tree
   95|         share = config.datadir
   96|         self.js_init(os.path.join(share, 'syn-down.png'),
   97|                      os.path.join(share, 'syn-right.png'),
   98|                     os.path.join(share, 'syn-dot.png'),
   99|                      'tree_%s.png', 0)
  100|         self.__share = share
  101|         # Creare the file
  102|         self.start_file()
  103|         self.write(self.manager.formatHeader(filename, 2))
  104|         self.indexModule(start, start.name())
  105|         self.end_file()
  106| 
  107|     def _child_filter(self, child):
  108|         return isinstance(child, AST.Module)
  109|     def _link_href(self, ns):
  110|         return config.files.nameOfModuleIndex(ns.name())
  111|     def get_children(self, decl):
  112|         try: return self._children_cache[decl]
  113|         except KeyError: pass
  114|         config.sorter.set_scope(decl)
  115|         config.sorter.sort_sections()
  116|         children = config.sorter.children()
  117|         children = filter(self._child_filter, children)
  118|         self._children_cache[decl] = children
  119|         return children
  120|     def indexModule(self, ns, rel_scope):
  121|         "Write a link for this module and recursively visit child modules."
  122|         my_scope = ns.name()
  123|         # Find children, and sort so that compound children (packages) go first
  124|         children = self.get_children(ns)
  125|         children.sort(lambda a,b,g=self.get_children:
  126|             cmp(len(g(b)),len(g(a))))
  127|         # Print link to this module
  128|         name = Util.ccolonName(my_scope, rel_scope) or "Global Namespace"
  129|         link = self._link_href(ns)
  130|         text = href(link, name, target=self._link_target)
  131|         if not len(children):
  132|             self.writeLeaf(text)
  133|         else:
  134|             self.writeNodeStart(text)
  135|             # Add children
  136|             for child in children:
  137|                self.indexModule(child, my_scope)
  138|             self.writeNodeEnd()
  139| 
  140| htmlPageClass = ModuleListingJS
  141|