Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Formatter/HTML/TreeFormatter.py
1| # $Id: TreeFormatter.py,v 1.3 2002/12/30 13:48:17 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: TreeFormatter.py,v $
23| # Revision 1.3 2002/12/30 13:48:17 chalky
24| # Use stylesheets for ModuleListing and classes' headings
25| #
26| # Revision 1.2 2002/11/01 03:39:21 chalky
27| # Cleaning up HTML after using 'htmltidy'
28| #
29| # Revision 1.1 2001/06/05 10:43:07 chalky
30| # Initial TreeFormatter and a JS version
31| #
32| #
33|
34| """Tree formatter interface.
35|
36| This module contains the class which defines the interface for all tree views.
37| A tree is a structure of leaves and nodes, where each leave has one node, each
38| node can have many child leaves or nodes, and there is one root node. Trees
39| are used to describe the relationship between modules, and also between files.
40| The user can select between different ways of representing trees, for example
41| as simple nested lists or as complex javascript trees that the user can expand
42| and collapse individual branches of. This module contains the tree interface
43| which is common to all implementations."""
44|
45| class TreeFormatter:
46| """Interface for all tree implementations. This tree class provides
47| default implementations of its methods for example and basic usage. The
48| implementation provided outputs a nested tree using the UL and LI html
49| elements."""
50| def __init__(self, page):
51| """A tree is a strategy, so it must be passed the page instance to
52| display to."""
53| self.page = page
54| self.write = page.write
55| self.os = page.os()
56|
57| def startTree(self):
58| """Writes anything to the file that needs to be written at the start.
59| For example a script section for the global scripts used by a
60| javascript tree."""
61| self.write('<ul class="tree">')
62|
63| def endTree(self):
64| """Writes anything that needs to be written at the end."""
65| self.write('</ul>')
66|
67| def writeLeaf(self, text):
68| """Writes a leaf to the output. A leaf is a node with no children, for
69| example a module (not package) or a file (not directory). The text is
70| output verbatim in the appropriate html tags, which in the default
71| instance is LI"""
72| self.write('<li>%s</li>'%text)
73|
74| def writeNodeStart(self, text):
75| """Starts a node with children. The text is written, and then a block
76| of children is started. This method call must be followed by a
77| corresponding writeNodeEnd() call. Invididual leaves inside the block
78| may be written out using the writeLeaf() method."""
79| self.write('<li>%s<ul class="tree">'%text)
80|
81| def writeNodeEnd(self):
82| """Ends a node with children. This method just closes any tags opened
83| by the corresponding writeNodeStart() method for a node."""
84| self.write('</ul></li>')