Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/ScopePages.py
    1| # $Id: ScopePages.py,v 1.18 2002/11/01 07:21:15 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: ScopePages.py,v $
   23| # Revision 1.18  2002/11/01 07:21:15  chalky
   24| # More HTML formatting fixes eg: ampersands and stuff
   25| #
   26| # Revision 1.17  2002/10/29 12:43:56  chalky
   27| # Added flexible TOC support to link to things other than ScopePages
   28| #
   29| # Revision 1.16  2002/01/09 10:16:35  chalky
   30| # Centralized navigation, clicking links in (html) docs works.
   31| #
   32| # Revision 1.15  2001/11/09 15:35:04  chalky
   33| # GUI shows HTML pages. just. Source window also scrolls to correct line.
   34| #
   35| # Revision 1.14  2001/07/15 08:28:43  chalky
   36| # Added 'Inheritance' page Part
   37| #
   38| # Revision 1.13  2001/07/15 06:41:57  chalky
   39| # Factored summarizer and detailer into 'Parts', and added a separate one for
   40| # the top of the page (Heading)
   41| #
   42| # Revision 1.12  2001/07/10 14:40:23  chalky
   43| # Cache summarizer and detailer
   44| #
   45| # Revision 1.11  2001/07/05 05:39:58  stefan
   46| # advanced a lot in the refactoring of the HTML module.
   47| # Page now is a truely polymorphic (abstract) class. Some derived classes
   48| # implement the 'filename()' method as a constant, some return a variable
   49| # dependent on what the current scope is...
   50| #
   51| # Revision 1.10  2001/07/04 08:17:48  uid20151
   52| # Comments
   53| #
   54| # Revision 1.9  2001/06/28 07:22:18  stefan
   55| # more refactoring/cleanup in the HTML formatter
   56| #
   57| # Revision 1.8  2001/06/26 04:32:16  stefan
   58| # A whole slew of changes mostly to fix the HTML formatter's output generation,
   59| # i.e. to make the output more robust towards changes in the layout of files.
   60| #
   61| # the rpm script now works, i.e. it generates source and binary packages.
   62| #
   63| # Revision 1.7  2001/06/21 01:17:27  chalky
   64| # Fixed some paths for the new dir structure
   65| #
   66| # Revision 1.6  2001/04/05 09:58:14  chalky
   67| # More comments, and use config object exclusively with basePackage support
   68| #
   69| # Revision 1.5  2001/02/12 04:08:09  chalky
   70| # Added config options to HTML and Linker. Config demo has doxy and synopsis styles.
   71| #
   72| # Revision 1.4  2001/02/06 15:00:42  stefan
   73| # Dot.py now references the template, not the last parameter, when displaying a Parametrized; replaced logo with a simple link
   74| #
   75| # Revision 1.3  2001/02/05 07:58:39  chalky
   76| # Cleaned up image copying for *JS. Added synopsis logo to ScopePages.
   77| #
   78| # Revision 1.2  2001/02/01 15:23:24  chalky
   79| # Copywritten brown paper bag edition.
   80| #
   81| 
   82| # System modules
   83| import time, os
   84| 
   85| # Synopsis modules
   86| from Synopsis.Core import AST
   87| 
   88| # Formatter modules
   89| from Synopsis.Formatter import TOC
   90| 
   91| # HTML modules
   92| import Page
   93| import core
   94| import ASTFormatter
   95| from core import config
   96| from Tags import *
   97| 
   98| 
   99| class ScopePages (Page.Page):
  100|     """A module for creating a page for each Scope with summaries and
  101|     details. This module is highly modular, using the classes from
  102|     ASTFormatter to do the actual formatting. The classes to use may be
  103|     controlled via the config script, resulting in a very configurable output.
  104|     @see ASTFormatter The ASTFormatter module
  105|     @see Config.Formatter.HTML.ScopePages Config for ScopePages
  106|     """
  107|     def __init__(self, manager):
  108|         Page.Page.__init__(self, manager)
  109|         share = config.datadir
  110|         self.syn_logo = 'synopsis200.jpg'
  111|         if config.files:
  112|             config.files.copyFile(os.path.join(share, 'synopsis200.jpg'), os.path.join(config.basename, self.syn_logo))
  113|         self.__parts = []
  114|         self._get_parts()
  115|         self.__namespaces = []
  116|         self.__toc = None
  117| 
  118|     def _get_parts(self):
  119|         "Loads the list of parts from config"
  120|         try:
  121|             parts = config.obj.ScopePages.parts
  122|         except AttributeError:
  123|             parts = ['Heading', 'Summary', 'Detail']
  124|         base = 'Synopsis.Formatter.HTML.ASTFormatter.'
  125|         for part in parts:
  126|             obj = core.import_object(part, basePackage=base)(self)
  127|             self.__parts.append(obj)
  128|     
  129|     def get_toc(self, start):
  130|         """Returns the TOC for the whole AST starting at start"""
  131|         if self.__toc: return self.__toc
  132|         self.__toc = TOC.TableOfContents(config.files)
  133|         start.accept(self.__toc)
  134|         return self.__toc
  135| 
  136|     def filename(self):
  137|         """since ScopePages generates a whole file hierarchy, this method returns the current filename,
  138|         which may change over the lifetime of this object"""
  139|         return self.__filename
  140|     def title(self):
  141|         """since ScopePages generates a while file hierarchy, this method returns the current title,
  142|         which may change over the lifetime of this object"""
  143|         return self.__title
  144|     def scope(self):
  145|         """return the current scope processed by this object"""
  146|         return self.__scope
  147| 
  148|     def process(self, start):
  149|         """Creates a page for every Scope"""
  150|         self.__namespaces = [start]
  151|         while self.__namespaces:
  152|             ns = self.__namespaces.pop(0)
  153|             self.process_scope(ns)
  154|         
  155|             # Queue child namespaces
  156|             for child in config.sorter.children():
  157|                if isinstance(child, AST.Scope):
  158|                    self.__namespaces.append(child)
  159| 
  160|     def register_filenames(self, start):
  161|         """Registers a page for every Scope"""
  162|         self.__namespaces = [start]
  163|         while self.__namespaces:
  164|             ns = self.__namespaces.pop(0)
  165| 
  166|             filename = config.files.nameOfScope(ns.name())
  167|             self.manager.register_filename(filename, self, ns)
  168| 
  169|             config.sorter.set_scope(ns)
  170|         
  171|             # Queue child namespaces
  172|             for child in config.sorter.children():
  173|                if isinstance(child, AST.Scope):
  174|                    self.__namespaces.append(child)
  175|      
  176|     def process_scope(self, ns):
  177|         """Creates a page for the given scope"""
  178|         details = {} # A hash of lists of detailed children by type
  179|         sections = [] # a list of detailed sections
  180|         
  181|         # Open file and setup scopes
  182|         self.__scope = ns.name()
  183|         self.__filename = config.files.nameOfScope(self.__scope)
  184|         self.__title = anglebrackets(string.join(self.__scope))
  185|         self.start_file()
  186|         
  187|         # Write heading
  188|         self.write(self.manager.formatHeader(self.filename()))
  189| 
  190|         # Loop throught all the page Parts
  191|         for part in self.__parts:
  192|             part.process(ns)
  193|         self.end_file()
  194|     
  195|     def end_file(self):
  196|         """Overrides end_file to provide synopsis logo"""
  197|         self.write('<hr>\n')
  198|         now = time.strftime(r'%c', time.localtime(time.time()))
  199|         logo = href('http://synopsis.sourceforge.net', 'synopsis')
  200|         self.write(div('logo', 'Generated on ' + now + ' by \n<br>\n' + logo))
  201|         Page.Page.end_file(self)
  202|  
  203| htmlPageClass = ScopePages