Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/FileDetails.py
    1| # $Id: FileDetails.py,v 1.2 2003/01/16 13:31:33 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: FileDetails.py,v $
   23| # Revision 1.2  2003/01/16 13:31:33  chalky
   24| # Quote the scope name
   25| #
   26| # Revision 1.1  2003/01/16 12:46:46  chalky
   27| # Renamed FilePages to FileSource, FileTree to FileListing. Added FileIndexer
   28| # (used to be part of FileTree) and FileDetails.
   29| #
   30| # Revision 1.18  2003/01/02 07:00:58  chalky
   31| # Only use Core.FileTree, refactored FileTree to be quicker and better.
   32| #
   33| # Revision 1.17  2002/12/12 17:25:33  chalky
   34| # Implemented Include support for C++ parser. A few other minor fixes.
   35| #
   36| # Revision 1.16  2002/11/02 06:37:37  chalky
   37| # Allow non-frames output, some refactoring of page layout, new modules.
   38| #
   39| # Revision 1.15  2002/11/01 07:21:15  chalky
   40| # More HTML formatting fixes eg: ampersands and stuff
   41| #
   42| # Revision 1.14  2002/10/29 12:43:56  chalky
   43| # Added flexible TOC support to link to things other than ScopePages
   44| #
   45| 
   46| # System modules
   47| import os
   48| 
   49| # Synopsis modules
   50| from Synopsis.Core import AST, Util
   51| 
   52| # HTML modules
   53| import Page
   54| import core
   55| from core import config
   56| from Tags import *
   57| 
   58| class FileDetails (Page.Page):
   59|     """A page that creates an index of files, and an index for each file.
   60|     First the index of files is created, intended for the top-left frame.
   61|     Second a page is created for each file, listing the major declarations for
   62|     that file, eg: classes, global functions, namespaces, etc."""
   63|     def __init__(self, manager):
   64|         Page.Page.__init__(self, manager)
   65|         self.__filename = ''
   66|         self.__title = ''
   67|         self.__link_source = ('FileSource' in config.pages)
   68| 
   69|     def filename(self):
   70|         """since FileTree generates a whole file hierarchy, this method returns the current filename,
   71|         which may change over the lifetime of this object"""
   72|         return self.__filename
   73|     def title(self):
   74|         """since FileTree generates a while file hierarchy, this method returns the current title,
   75|         which may change over the lifetime of this object"""
   76|         return self.__title
   77| 
   78|     def register_filenames(self, start):
   79|         """Registers a page for each file indexed"""
   80|         for filename, file in config.ast.files().items():
   81|             if file.is_main():
   82|                 filename = config.files.nameOfFileDetails(filename)
   83|                self.manager.register_filename(filename, self, file)
   84|     
   85|     def process(self, start):
   86|         """Creates a page for each file using process_scope"""
   87|         for filename, file in config.ast.files().items():
   88|             if file.is_main():
   89|                self.process_scope(filename, file)
   90| 
   91|     def process_scope(self, filename, file):
   92|         """Creates a page for the given file. The page is just an index,
   93|         containing a list of declarations."""
   94|         toc = config.toc
   95| 
   96|         # set up filename and title for the current page
   97|         self.__filename = config.files.nameOfFileDetails(filename)
   98|         # (get rid of ../'s in the filename)
   99|         name = string.split(filename, os.sep)
  100|         while len(name) and name[0] == '..': del name[0]
  101|         self.__title = string.join(name, os.sep)+' Details'
  102| 
  103|         self.start_file()
  104|         self.write(self.manager.formatHeader(self.filename()))
  105|         self.write(entity('h1', string.join(name, os.sep))+'<br>')
  106|         if self.__link_source:
  107|             link = rel(self.filename(),
  108|                config.files.nameOfFileSource(filename))
  109|             self.write(href(link, '[File Source]', target="main")+'<br>')
  110| 
  111|         # Print list of includes
  112|         try:
  113|             sourcefile = config.ast.files()[filename]
  114|             includes = sourcefile.includes()
  115|             # Only show files from the project
  116|             includes = filter(lambda x: x.target().is_main(), includes)
  117|             self.write('<h2>Includes from this file:</h2>')
  118|             if not len(includes):
  119|                self.write('No includes.<br>')
  120|             for include in includes:
  121|                target_filename = include.target().filename()
  122|                if include.is_next(): idesc = 'include_next '
  123|                else: idesc = 'include '
  124|                if include.is_macro(): idesc = idesc + 'from macro '
  125|                link = rel(self.filename(), config.files.nameOfFileDetails(target_filename))
  126|                self.write(idesc + href(link, target_filename)+'<br>')
  127|         except:
  128|         pass
  129| 
  130|         self.write('<h2>Declarations in this file:</h2>')
  131|         # Sort items (by name)
  132|         items = map(lambda decl: (decl.type(), decl.name(), decl), file.declarations())
  133|         items.sort()
  134|         curr_scope = None
  135|         curr_type = None
  136|         comma = 0
  137|         for decl_type, name, decl in items:
  138|             # Check scope and type to see if they've changed since the last
  139|             # declaration, thereby forming sections of scope and type
  140|             decl_scope = name[:-1]
  141|             if decl_scope != curr_scope or decl_type != curr_type:
  142|                curr_scope = decl_scope
  143|                curr_type = decl_type
  144|                if curr_scope is not None:
  145|                    self.write('\n</div>')
  146|                if len(curr_type) and curr_type[-1] == 's': plural = 'es'
  147|                else: plural = 's'
  148|                if len(curr_scope):
  149|                    self.write('<h3>%s%s in %s</h3>\n<div>'%(
  150|                       curr_type.capitalize(), plural,
  151|                       anglebrackets(Util.ccolonName(curr_scope))))
  152|         else:
  153|                    self.write('<h3>%s%s</h3>\n<div>'%(curr_type.capitalize(),plural))
  154|                comma = 0
  155|             # Format this declaration
  156|             entry = config.toc[name]
  157|         
  158|             label = anglebrackets(Util.ccolonName(name, curr_scope))
  159|             label = replace_spaces(label)
  160|             if entry:
  161|                link = rel(self.filename(), entry.link)
  162|                text = ' ' + href(link, label)
  163|          else:
  164|                text = ' ' + label
  165|             if comma: self.write(',')
  166|             self.write(text)
  167|             comma = 1
  168|         
  169|         # Close open DIV
  170|         if curr_scope is not None:
  171|             self.write('\n</div>')
  172|         self.end_file()
  173|         
  174| htmlPageClass = FileDetails