Modules |
Files |
Inheritance Tree |
Inheritance Graph |
Name Index |
Config
File: Synopsis/Formatter/HTML/ModuleIndexer.py
1| # $Id: ModuleIndexer.py,v 1.13 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: ModuleIndexer.py,v $
23| # Revision 1.13 2002/11/02 06:37:37 chalky
24| # Allow non-frames output, some refactoring of page layout, new modules.
25| #
26| # Revision 1.12 2002/11/01 07:21:15 chalky
27| # More HTML formatting fixes eg: ampersands and stuff
28| #
29| # Revision 1.11 2002/11/01 03:39:21 chalky
30| # Cleaning up HTML after using 'htmltidy'
31| #
32| # Revision 1.10 2002/10/29 12:43:56 chalky
33| # Added flexible TOC support to link to things other than ScopePages
34| #
35| # Revision 1.9 2002/07/04 06:43:18 chalky
36| # Improved support for absolute references - pages known their full path.
37| #
38| # Revision 1.8 2002/03/14 00:19:47 chalky
39| # Added demo of template specializations, and fixed HTML formatter to deal with
40| # angle brackets in class names :)
41| #
42| # Revision 1.7 2001/07/10 02:55:51 chalky
43| # Better comments in some files, and more links work with the nested layout
44| #
45| # Revision 1.6 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.5 2001/06/28 07:22:18 stefan
52| # more refactoring/cleanup in the HTML formatter
53| #
54| # Revision 1.4 2001/06/26 04:32:16 stefan
55| # A whole slew of changes mostly to fix the HTML formatter's output generation,
56| # i.e. to make the output more robust towards changes in the layout of files.
57| #
58| # the rpm script now works, i.e. it generates source and binary packages.
59| #
60| # Revision 1.3 2001/02/01 18:36:55 chalky
61| # Moved TOC out to Formatter/TOC.py
62| #
63| # Revision 1.2 2001/02/01 15:23:24 chalky
64| # Copywritten brown paper bag edition.
65| #
66| #
67|
68| import os
69| from Synopsis.Core import AST, Util
70|
71| import core, Page
72| from core import config
73| from Tags import *
74|
75| class ModuleIndexer(Page.Page):
76| """A module for indexing AST.Modules. Each module gets its own page with a
77| list of nested scope declarations with comments. It is intended to go in
78| the left frame..."""
79| def __init__(self, manager):
80| Page.Page.__init__(self, manager)
81|
82| def filename(self): return self.__filename
83| def title(self): return self.__title
84|
85| def register(self):
86| """Register first page as index page"""
87| config.set_using_module_index()
88| self.__filename = config.files.nameOfModuleIndex(())
89| config.set_index_page(self.__filename)
90|
91| def process(self, start):
92| """Creates indexes for all modules"""
93| start_file = config.files.nameOfModuleIndex(start.name())
94| config.set_index_page(start_file)
95| self.__namespaces = [start]
96| while self.__namespaces:
97| ns = self.__namespaces.pop(0)
98| self.processNamespaceIndex(ns)
99|
100| def _makePageHeading(self, ns):
101| """Creates a HTML fragment which becomes the name at the top of the
102| index page. This may be overridden, but the default is (now) to make a
103| linked fully scoped name, where each scope has a link to the relevant
104| index."""
105| name = ns.name()
106| if not name: return 'Global Index'
107| links = []
108| for depth in range(0, len(name)):
109| url = config.files.nameOfModuleIndex(name[:depth+1])
110| label = anglebrackets(name[depth])
111| links.append(href(rel(self.__filename, url), label))
112| return entity('b', string.join(links, '\n::') + ' Index')
113|
114| def processNamespaceIndex(self, ns):
115| "Index one module"
116| config.sorter.set_scope(ns)
117| config.sorter.sort_section_names()
118| config.sorter.sort_sections()
119|
120| self.__filename = config.files.nameOfModuleIndex(ns.name())
121| self.__title = Util.ccolonName(ns.name()) or 'Global Namespace'
122| self.__title = self.__title + ' Index'
123| # Create file
124| self.start_file()
125| #target = rel(self.__filename, config.files.nameOfScope(ns.name()))
126| #link = href(target, self.__title, target='main')
127| self.write(self._makePageHeading(ns))
128|
129| # Make script to switch main frame upon load
130| load_script = '<!--\n'
131| if config.toc[ns.name()]:
132| target = rel(self.__filename, config.toc[ns.name()].link)
133| load_script = load_script + 'window.parent.frames["main"].location="%s";\n'%target
134| load_script = load_script + 'function go(index,main) {\n'\
135| 'window.parent.frames["index"].location=index;\n'\
136| 'window.parent.frames["main"].location=main;\n'\
137| 'return false;}\n-->'
138| self.write(entity('script', load_script, type='text/javascript'))
139|
140| # Loop throught all the types of children
141| for section in config.sorter.sections():
142| if section[-1] == 's': heading = section+'es'
143| else: heading = section+'s'
144| heading = '<br>'+entity('i', heading)+'<br>'
145| # Get a list of children of this type
146| for child in config.sorter.children(section):
147| # Print out summary for the child
148| if not isinstance(child, AST.Scope):
149| continue
150| if heading:
151| self.write(heading)
152| heading = None
153| label = Util.ccolonName(child.name(), ns.name())
154| label = anglebrackets(label)
155| label = replace_spaces(label)
156| if isinstance(child, AST.Module):
157| index_url = rel(self.__filename, config.files.nameOfModuleIndex(child.name()))
158| self.write(href(index_url, label, target='index'))
159| else:
160| entry = config.toc[child.name()]
161| if entry:
162| url = rel(self.__filename, entry.link)
163| self.write(href(url, label, target='main'))
164| else:
165| self.write(label)
166| self.write('<br>')
167| self.end_file()
168|
169| # Queue child namespaces
170| for child in config.sorter.children():
171| if isinstance(child, AST.Module):
172| self.__namespaces.append(child)
173|
174| htmlPageClass = ModuleIndexer