Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Formatter/HTML/FileTreeJS.py
    1| # $Id: FileTreeJS.py,v 1.7 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: FileTreeJS.py,v $
   23| # Revision 1.7  2002/11/02 06:37:37  chalky
   24| # Allow non-frames output, some refactoring of page layout, new modules.
   25| #
   26| # Revision 1.6  2001/07/05 05:39:58  stefan
   27| # advanced a lot in the refactoring of the HTML module.
   28| # Page now is a truely polymorphic (abstract) class. Some derived classes
   29| # implement the 'filename()' method as a constant, some return a variable
   30| # dependent on what the current scope is...
   31| #
   32| # Revision 1.5  2001/06/28 07:22:18  stefan
   33| # more refactoring/cleanup in the HTML formatter
   34| #
   35| # Revision 1.4  2001/06/26 04:32:16  stefan
   36| # A whole slew of changes mostly to fix the HTML formatter's output generation,
   37| # i.e. to make the output more robust towards changes in the layout of files.
   38| #
   39| # the rpm script now works, i.e. it generates source and binary packages.
   40| #
   41| # Revision 1.3  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.2  2001/02/16 02:29:55  chalky
   45| # Initial work on SXR and HTML integration
   46| #
   47| # Revision 1.1  2001/02/06 05:12:46  chalky
   48| # Added JSTree class and FileTreeJS and modified ModuleListingJS to use JSTree
   49| #
   50| # Revision 1.3  2001/02/05 05:26:24  chalky
   51| # Graphs are separated. Misc changes
   52| #
   53| # Revision 1.2  2001/02/01 15:23:24  chalky
   54| # Copywritten brown paper bag edition.
   55| #
   56| #
   57| 
   58| # System modules
   59| import os
   60| 
   61| # Synopsis modules
   62| from Synopsis.Core import AST, Util
   63| 
   64| # HTML modules
   65| import JSTree
   66| import core
   67| from core import config
   68| from Tags import *
   69| 
   70| class FileTree(JSTree.JSTree):
   71|     def __init__(self, manager):
   72|         JSTree.JSTree.__init__(self, manager)
   73|         filename = config.files.nameOfSpecial('FileTree')
   74|         self.manager.addRootPage(filename, 'File Tree', 'contents', 2)
   75|         myconfig = config.obj.FileTree
   76|         self._link_pages = myconfig.link_to_pages
   77|    
   78|     def filename(self):
   79|         """since FileTree generates a whole file hierarchy, this method returns the current filename,
   80|         which may change over the lifetime of this object"""
   81|         return self.__filename
   82|     def title(self):
   83|         """since FileTree generates a while file hierarchy, this method returns the current title,
   84|         which may change over the lifetime of this object"""
   85|         return self.__title
   86| 
   87|     def process(self, start):
   88|         # Init tree
   89|         share = config.datadir
   90|         self.js_init(os.path.join(share, 'syn-down.png'),
   91|                      os.path.join(share, 'syn-right.png'),
   92|                      os.path.join(share, 'syn-dot.png'),
   93|                      'tree_%s.png', 0)
   94|         # Start the file
   95|         filename = config.files.nameOfSpecial('FileTree')
   96|         self.start_file(filename, 'File Tree')
   97|         self.write(self.manager.formatHeader(filename, 2))
   98|         # recursively visit all nodes
   99|         self.processFileTreeNode(config.fileTree.root())
  100|         self.end_file()
  101|         # recursively create all node pages
  102|         self.processFileTreeNodePage(config.fileTree.root())
  103| 
  104|     def _node_sorter(self, a, b):
  105|         a_leaf = hasattr(a, 'decls')
  106|         b_leaf = hasattr(b, 'decls')
  107|         if a_leaf != b_leaf:
  108|             return cmp(b_leaf, a_leaf)
  109|         return cmp(string.upper(a.path[-1]), string.upper(b.path[-1]))
  110| 
  111|     def processFileTreeNode(self, node):
  112|         if hasattr(node, 'decls'):
  113|             # Leaf node
  114|             text = href(config.files.nameOfFileIndex(string.join(node.path, os.sep)), node.path[-1], target='index')
  115|             self.writeLeaf(text)
  116|           return
  117|         # Non-leaf node
  118|         children = node.children.values()
  119|         children.sort(self._node_sorter)
  120|         if len(node.path):
  121|             self.writeNodeStart(node.path[-1]+os.sep)
  122|         if len(children):
  123|             for child in children:
  124|                #self.write('<div class="files">')
  125|                self.processFileTreeNode(child)
  126|                #self.write('</div>')
  127|         if len(node.path):
  128|             self.writeNodeEnd()
  129|         
  130|     def processFileTreeNodePage(self, node):
  131|         for child in node.children.values():
  132|             self.processFileTreeNodePage(child)
  133|         if not hasattr(node, 'decls'): return
  134| 
  135|         toc = config.toc
  136|         # set up filename and title for the current page
  137|         self.__filename = config.files.nameOfFileIndex(string.join(node.path, os.sep))
  138|         name = list(node.path)
  139|         while len(name) and name[0] == '..': del name[0]
  140|         self.__title = string.join(name, os.sep)
  141| 
  142|         self.start_file()
  143|         self.write(entity('b', string.join(name, os.sep))+'<br>')
  144|         if self._link_pages:
  145|             link = config.files.nameOfScopedSpecial('page', name)
  146|             self.write(href(link, '[Source]', target="main")+'<br>')
  147|         for name, decl in node.decls.items():
  148|             # TODO make this nicer :)
  149|             entry = config.toc[name]
  150|             if not entry: print "no entry for",name
  151|          else:
  152|                # Print link to declaration's page
  153|                if isinstance(decl, AST.Function):
  154|                    self.write(div('href',href(entry.link,anglebrackets(Util.ccolonName(decl.realname())),target='main')))
  155|         else:
  156|                    self.write(div('href',href(entry.link,Util.ccolonName(name),target='main')))
  157|                # Print comment
  158|                #self.write(self.summarizer.getSummary(node.decls[name]))
  159|         self.end_file()
  160|         
  161| htmlPageClass = FileTree