[Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML Formatter.py,1.6,1.7 Tags.py,1.11,1.12
Stefan Seefeld stefan at synopsis.fresco.orgSat Nov 15 19:55:33 UTC 2003
- Previous message: [Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML DeclarationStyle.py,NONE,1.1
- Next message: [Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML Formatter.py,1.7,1.8
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Update of /cvs/synopsis/Synopsis/Synopsis/Formatters/HTML
In directory frida:/tmp/cvs-serv5222/Synopsis/Formatters/HTML
Modified Files:
Formatter.py Tags.py
Log Message:
refactoring
Index: Formatter.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Formatters/HTML/Formatter.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -p -d -r1.6 -r1.7
--- Formatter.py 15 Nov 2003 19:01:53 -0000 1.6
+++ Formatter.py 15 Nov 2003 19:55:31 -0000 1.7
@@ -6,6 +6,7 @@
# see the file COPYING for details.
#
+from Synopsis import config
from Synopsis.Processor import Processor, Parameter
from Synopsis import AST
from Synopsis.Formatters.TOC import TOC
@@ -14,6 +15,7 @@ from Synopsis.Formatters.XRef import Cro
from FileLayout import *
from TreeFormatter import *
from CommentFormatter import *
+from DeclarationStyle import *
from Pages.FramesIndex import *
from Pages.DirBrowse import *
from Pages.Scope import *
@@ -27,8 +29,7 @@ from Pages.InheritanceGraph import *
from Pages.FileSource import *
from Pages.NameIndex import *
from Pages.XRef import *
-
-from core import *
+import Tags
class ConfigHTML:
"""This is a verbatim copy of the HTML class in Config.py.
@@ -67,8 +68,7 @@ class Formatter(Processor):
stylesheet = Parameter('style.css', '')
stylesheet_file = Parameter('../html.css', '')
- # this should go away !
- datadir = Parameter('/usr/local/share/synopsis', '')
+ datadir = Parameter('', 'alternative data directory')
file_layout = Parameter(NestedFileLayout(), 'how to lay out the output files')
toc_in = Parameter([], 'list of table of content files to use for symbol lookup')
toc_out = Parameter('', 'name of file into which to store the TOC')
@@ -100,42 +100,29 @@ class Formatter(Processor):
self.set_parameters(kwds)
self.ast = self.merge_input(ast)
- config_obj = ConfigHTML(self.verbose)
-
- config.use_config(config_obj)
-
- config.basename = self.output
-
- config.fillDefaults() # <-- end of _parseArgs...
-
- config.types = ast.types()
- declarations = ast.declarations()
+ # if not set, use default...
+ if not self.datadir: self.datadir = config.datadir
self.file_layout.init(self)
-
- # Create the declaration styler and the comment formatter
- config.decl_style = DeclStyle()
+ self.decl_style = Style()
for f in self.comment_formatters:
f.init(self)
-
self.comments = CommentFormatter(self)
-
# Create the Class Tree (TODO: only if needed...)
self.classTree = ClassTree()
-
# Create the File Tree (TODO: only if needed...)
self.fileTree = FileTree()
self.fileTree.set_ast(ast)
self.xref = CrossReferencer()
+ Tags.using_frames = self.has_page('FramesIndex')
+
+ declarations = ast.declarations()
# Build class tree
for d in declarations:
- d.accept(config.classTree)
-
- # Create the page manager, which loads the pages
- core.manager = self
+ d.accept(self.classTree)
self.__roots = [] #pages with roots, list of Structs
self.__global = None # The global scope
@@ -150,39 +137,36 @@ class Formatter(Processor):
# Create table of contents index
start = self.calculateStart(root)
self.toc = self.get_toc(start)
- if verbose: print "HTML Formatter: Initialising TOC"
+ if self.verbose: print "HTML Formatter: Initialising TOC"
# Add all declarations to the namespace tree
# for d in declarations:
- # d.accept(config.toc)
+ # d.accept(self.toc)
- if verbose: print "TOC size:",self.toc.size()
+ if self.verbose: print "TOC size:",self.toc.size()
if self.toc_out: self.toc.store(self.toc_out)
# load external references from toc files, if any
for t in self.toc_in: self.toc.load(t)
- if verbose: print "HTML Formatter: Writing Pages..."
+ if self.verbose: print "HTML Formatter: Writing Pages..."
# Create the pages
self.__global = root
start = self.calculateStart(root)
- if config.verbose: print "Registering filenames...",
+ if self.verbose: print "Registering filenames...",
for page in self.pages:
page.register_filenames(start)
- if config.verbose: print "Done."
+ if self.verbose: print "Done."
for page in self.pages:
- if config.verbose:
+ if self.verbose:
print "Time for %s:"%page.__class__.__name__,
sys.stdout.flush()
start_time = time.time()
page.process(start)
- if config.verbose:
+ if self.verbose:
print "%f"%(time.time() - start_time)
- #core.manager.process(root)
- #format(['-o', self.output], self.ast, config_obj)
-
return self.ast
def has_page(self, page_name):
@@ -231,16 +215,16 @@ class Formatter(Processor):
scope_names = string.split(namespace or config.namespace, "::")
start = root # The running result
- config.sorter.set_scope(root)
+ self.sorter.set_scope(root)
scope = [] # The running name of the start
for scope_name in scope_names:
if not scope_name: break
scope.append(scope_name)
try:
- child = config.sorter.child(tuple(scope))
+ child = self.sorter.child(tuple(scope))
if isinstance(child, AST.Scope):
start = child
- config.sorter.set_scope(start)
+ self.sorter.set_scope(start)
else:
raise TypeError, 'calculateStart: Not a Scope'
except:
@@ -248,7 +232,7 @@ class Formatter(Processor):
import traceback
traceback.print_exc()
print "Fatal: Couldn't find child scope",scope
- print "Children:",map(lambda x:x.name(), config.sorter.children())
+ print "Children:",map(lambda x:x.name(), self.sorter.children())
sys.exit(3)
return start
@@ -273,7 +257,7 @@ class Formatter(Processor):
above are included."""
# If not using frames, show all headings on all pages!
- if not self.has_page(FramesIndex):
+ if not self.has_page('FramesIndex'):
visibility = 1
#filter out roots that are visible
roots = filter(lambda x,v=visibility: x.visibility >= v, self.__roots)
Index: Tags.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Formatters/HTML/Tags.py,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -p -d -r1.11 -r1.12
--- Tags.py 13 Nov 2002 01:01:49 -0000 1.11
+++ Tags.py 15 Nov 2003 19:55:31 -0000 1.12
@@ -1,129 +1,102 @@
# $Id$
#
-# This file is a part of Synopsis.
-# Copyright (C) 2000, 2001 Stephen Davies
-# Copyright (C) 2000, 2001 Stefan Seefeld
-#
-# Synopsis is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-# 02111-1307, USA.
-#
-# $Log$
-# Revision 1.11 2002/11/13 01:01:49 chalky
-# Improvements to links when using the Nested file layout
-#
-# Revision 1.10 2002/11/02 06:37:37 chalky
-# Allow non-frames output, some refactoring of page layout, new modules.
-#
-# Revision 1.9 2002/11/01 07:20:22 chalky
-# Enhanced anglebrackets()
-#
-# Revision 1.8 2002/11/01 03:39:21 chalky
-# Cleaning up HTML after using 'htmltidy'
-#
-# Revision 1.7 2002/07/11 09:28:40 chalky
-# Missed one
-#
-# Revision 1.6 2002/07/11 02:03:49 chalky
-# Oops, remove print that shouldn't be there.
-#
-# Revision 1.5 2002/07/04 06:43:18 chalky
-# Improved support for absolute references - pages known their full path.
-#
-# Revision 1.4 2001/07/10 05:09:11 chalky
-# More links work
-#
-# Revision 1.3 2001/06/28 07:22:18 stefan
-# more refactoring/cleanup in the HTML formatter
-#
-# Revision 1.2 2001/02/01 15:23:24 chalky
-# Copywritten brown paper bag edition.
-#
+# Copyright (C) 2000 Stephen Davies
+# Copyright (C) 2000 Stefan Seefeld
+# All rights reserved.
+# Licensed to the public under the terms of the GNU LGPL (>= 2),
+# see the file COPYING for details.
#
"""HTML Tag generation utilities.
You will probably find it easiest to import * from this module."""
-# System modules
import string, re
-# HTML modules
-import core
+using_frames = True #overwritten by Formatter...
def k2a(keys):
- "Convert a name/value dict to a string of attributes"
- return string.join(map(lambda item:' %s="%s"'%item, keys.items()), '')
+ "Convert a name/value dict to a string of attributes"
+
+ return string.join(map(lambda item:' %s="%s"'%item, keys.items()), '')
+
def rel(frm, to):
- "Find link to to relative to frm"
- frm = string.split(frm, '/'); to = string.split(to, '/')
- if len(frm) < len(to): check = len(frm)-1
- else: check = len(to)-1
- for l in range(check):
- if to[0] == frm[0]: del to[0]; del frm[0]
- else: break
- # If frm is a directory, and to is in that directory, frm[0] == to[0]
- if len(frm) == 1 and len(to) > 1 and frm[0] == to[0]:
- # Remove directory from to, but respect len(frm)-1 below
- del to[0]
- if frm: to = ['..'] * (len(frm) - 1) + to
- return string.join(to,'/')
+ "Find link to to relative to frm"
+
+ frm = string.split(frm, '/'); to = string.split(to, '/')
+ if len(frm) < len(to): check = len(frm)-1
+ else: check = len(to)-1
+ for l in range(check):
+ if to[0] == frm[0]: del to[0]; del frm[0]
+ else: break
+ # If frm is a directory, and to is in that directory, frm[0] == to[0]
+ if len(frm) == 1 and len(to) > 1 and frm[0] == to[0]:
+ # Remove directory from to, but respect len(frm)-1 below
+ del to[0]
+ if frm: to = ['..'] * (len(frm) - 1) + to
+ return string.join(to,'/')
+
def href(_ref, _label, **keys):
- "Return a href to 'ref' with name 'label' and attributes"
- # Remove target if not using frames
- if keys.has_key('target') and not core.config.using_frames:
- del keys['target']
- return '<a href="%s"%s>%s</a>'%(_ref,k2a(keys),_label)
+ "Return a href to 'ref' with name 'label' and attributes"
+
+ # Remove target if not using frames
+ if keys.has_key('target') and not using_frames:
+ del keys['target']
+ return '<a href="%s"%s>%s</a>'%(_ref,k2a(keys),_label)
+
def name(ref, label):
- "Return a name anchor with given reference and label"
- return '<a class="name" name="%s">%s</a>'%(ref,label)
+ "Return a name anchor with given reference and label"
+
+ return '<a class="name" name="%s">%s</a>'%(ref,label)
+
def span(clas, body):
- "Wrap the body in a span of the given class"
- return '<span class="%s">%s</span>'%(clas,body)
+ "Wrap the body in a span of the given class"
+
+ return '<span class="%s">%s</span>'%(clas,body)
+
def div(clas, body):
- "Wrap the body in a div of the given class"
- return '<div class="%s">%s</div>'%(clas,body)
+ "Wrap the body in a div of the given class"
+
+ return '<div class="%s">%s</div>'%(clas,body)
+
def entity(_type, body, **keys):
- "Wrap the body in a tag of given type and attributes"
- return '<%s%s>%s</%s>'%(_type,k2a(keys),body,_type)
+ "Wrap the body in a tag of given type and attributes"
+
+ return '<%s%s>%s</%s>'%(_type,k2a(keys),body,_type)
+
def solotag(_type, **keys):
- "Create a solo tag (no close tag) of given type and attributes"
- return '<%s%s>'%(_type,k2a(keys))
+ "Create a solo tag (no close tag) of given type and attributes"
+
+ return '<%s%s>'%(_type,k2a(keys))
+
def desc(text):
- "Create a description div for the given text"
- return text and div("desc", text) or ''
+ "Create a description div for the given text"
+
+ return text and div("desc", text) or ''
+
def anglebrackets(text):
- """Replace angle brackets with HTML codes"""
- text = text.replace('&', '&')
- text = text.replace('"', '"')
- text = text.replace('<', '<')
- text = text.replace('>', '>')
- return text
+ """Replace angle brackets with HTML codes"""
+
+ text = text.replace('&', '&')
+ text = text.replace('"', '"')
+ text = text.replace('<', '<')
+ text = text.replace('>', '>')
+ return text
def replace_spaces(text):
- """Replaces spaces in the given string with sequences. Does NOT
- replace spaces inside tags"""
- # original "hello <there stuff> fool <thing me bob>yo<a>hi"
- tags = string.split(text, '<')
- # now ['hello ', 'there stuff> fool ', 'thing me bob>yo', 'a>hi']
- tags = map(lambda x: string.split(x, '>'), tags)
- # now [['hello '], ['there stuff', ' fool '], ['thing me bob', 'yo'], ['a', 'hi']]
- tags = reduce(lambda x,y: x+y, tags)
- # now ['hello ', 'there stuff', ' fool ', 'thing me bob', 'yo', 'a', 'hi']
- for i in range(0,len(tags),2):
- tags[i] = tags[i].replace(' ', ' ')
- for i in range(1,len(tags),2):
- tags[i] = '<' + tags[i] + '>'
- return string.join(tags, '')
+ """Replaces spaces in the given string with sequences. Does NOT
+ replace spaces inside tags"""
+
+ # original "hello <there stuff> fool <thing me bob>yo<a>hi"
+ tags = string.split(text, '<')
+ # now ['hello ', 'there stuff> fool ', 'thing me bob>yo', 'a>hi']
+ tags = map(lambda x: string.split(x, '>'), tags)
+ # now [['hello '], ['there stuff', ' fool '], ['thing me bob', 'yo'], ['a', 'hi']]
+ tags = reduce(lambda x,y: x+y, tags)
+ # now ['hello ', 'there stuff', ' fool ', 'thing me bob', 'yo', 'a', 'hi']
+ for i in range(0,len(tags),2):
+ tags[i] = tags[i].replace(' ', ' ')
+ for i in range(1,len(tags),2):
+ tags[i] = '<' + tags[i] + '>'
+ return string.join(tags, '')
- Previous message: [Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML DeclarationStyle.py,NONE,1.1
- Next message: [Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML Formatter.py,1.7,1.8
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Synopsis-changes mailing list