Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/FileIndexer.py
    1| # $Id: FileIndexer.py,v 1.2 2003/01/20 06:43:02 chalky Exp $
    2| #
    3| # This file is a part of Synopsis.
    4| # Copyright (C) 2000-2003 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: FileIndexer.py,v $
   23| # Revision 1.2  2003/01/20 06:43:02  chalky
   24| # Refactored comment processing. Added AST.CommentTag. Linker now determines
   25| # comment summary and extracts tags. Increased AST version number.
   26| #
   27| # Revision 1.1  2003/01/16 12:46:46  chalky
   28| # Renamed FilePages to FileSource, FileTree to FileListing. Added FileIndexer
   29| # (used to be part of FileTree) and FileDetails.
   30| #
   31| # Revision 1.18  2003/01/02 07:00:58  chalky
   32| # Only use Core.FileTree, refactored FileTree to be quicker and better.
   33| #
   34| # Revision 1.17  2002/12/12 17:25:33  chalky
   35| # Implemented Include support for C++ parser. A few other minor fixes.
   36| #
   37| # Revision 1.16  2002/11/02 06:37:37  chalky
   38| # Allow non-frames output, some refactoring of page layout, new modules.
   39| #
   40| # Revision 1.15  2002/11/01 07:21:15  chalky
   41| # More HTML formatting fixes eg: ampersands and stuff
   42| #
   43| # Revision 1.14  2002/10/29 12:43:56  chalky
   44| # Added flexible TOC support to link to things other than ScopePages
   45| #
   46| 
   47| # System modules
   48| import os
   49| 
   50| # Synopsis modules
   51| from Synopsis.Core import AST, Util
   52| 
   53| # HTML modules
   54| import Page
   55| import core
   56| from core import config
   57| from Tags import *
   58| 
   59| class FileIndexer (Page.Page):
   60|     """A page that creates an index of files, and an index for each file.
   61|     First the index of files is created, intended for the top-left frame.
   62|     Second a page is created for each file, listing the major declarations for
   63|     that file, eg: classes, global functions, namespaces, etc."""
   64|     def __init__(self, manager):
   65|         Page.Page.__init__(self, manager)
   66|         self.__filename = ''
   67|         self.__title = ''
   68|         self.__link_source = ('FileSource' in config.pages)
   69|         self.__link_details = ('FileDetails' in config.pages)
   70| 
   71|     def filename(self):
   72|         """since FileTree generates a whole file hierarchy, this method returns the current filename,
   73|         which may change over the lifetime of this object"""
   74|         return self.__filename
   75|     def title(self):
   76|         """since FileTree generates a while file hierarchy, this method returns the current title,
   77|         which may change over the lifetime of this object"""
   78|         return self.__title
   79| 
   80|     def register_filenames(self, start):
   81|         """Registers a page for each file indexed"""
   82|         for filename, file in config.ast.files().items():
   83|             if file.is_main():
   84|                 filename = config.files.nameOfFileIndex(filename)
   85|                self.manager.register_filename(filename, self, file)
   86|     
   87|     def process(self, start):
   88|         """Creates a page for each file using process_scope"""
   89|         for filename, file in config.ast.files().items():
   90|             if file.is_main():
   91|                self.process_scope(filename, file)
   92| 
   93|     def process_scope(self, filename, file):
   94|         """Creates a page for the given file. The page is just an index,
   95|         containing a list of declarations."""
   96|         toc = config.toc
   97| 
   98|         # set up filename and title for the current page
   99|         self.__filename = config.files.nameOfFileIndex(filename)
  100|         # (get rid of ../'s in the filename)
  101|         name = string.split(filename, os.sep)
  102|         while len(name) and name[0] == '..': del name[0]
  103|         self.__title = string.join(name, os.sep)
  104| 
  105|         self.start_file()
  106|         self.write(entity('b', string.join(name, os.sep))+'<br>')
  107|         if self.__link_source:
  108|             link = rel(self.filename(),
  109|                config.files.nameOfFileSource(filename))
  110|             self.write(href(link, '[File Source]', target="main")+'<br>')
  111|         if self.__link_details:
  112|             link = rel(self.filename(),
  113|                config.files.nameOfFileDetails(filename))
  114|             self.write(href(link, '[File Details]', target="main")+'<br>')
  115|         comments = config.comments
  116| 
  117|         self.write('<b>Declarations:</b><br>')
  118|         # Sort items (by name)
  119|         items = map(lambda decl: (decl.name(), decl), file.declarations())
  120|         items.sort()
  121|         scope, last = [], []
  122|         for name, decl in items:
  123|             # TODO make this nicer :)
  124|             entry = config.toc[name]
  125|             if not entry: continue
  126|             summary = string.strip("(%s) %s"%(decl.type(),
  127|                anglebrackets(comments.format_summary(self, decl))))
  128|             # Print link to declaration's page
  129|             link = rel(self.filename(), entry.link)
  130|             if isinstance(decl, AST.Function): print_name = decl.realname()
  131|             else: print_name = name
  132|             # Increase scope
  133|          i = 0
  134|             while i < len(print_name)-1 and i < len(scope) and print_name[i] == scope[i]:
  135|                i = i + 1
  136|             # Remove unneeded indentation
  137|          j = i
  138|             while j < len(scope):
  139|                self.write("</div>")
  140|                j = j + 1
  141|             # Add new indentation
  142|             scope[i:j] = []
  143|             while i < len(print_name)-1:
  144|                scope.append(print_name[i])
  145|                if len(last) >= len(scope) and last[:len(scope)] == scope: div_bit = ""
  146|                else: div_bit = print_name[i]+"<br>"
  147|                self.write('%s<div class="filepage-scope">'%div_bit)
  148|                i = i + 1
  149| 
  150|             # Now print the actual item
  151|             label = anglebrackets(Util.ccolonName(print_name, scope))
  152|             label = replace_spaces(label)
  153|             self.write(div('href',href(link, label, target='main', title=summary)))
  154|             # Store this name incase, f.ex, its a class and the next item is
  155|             # in that class scope
  156|             last = list(name)
  157|         # Close open DIVs
  158|         for i in scope:
  159|             self.write("</div>")
  160|         self.end_file()
  161|         
  162| htmlPageClass = FileIndexer