[Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML Fragment.py,NONE,1.1 Part.py,1.38,1.39

Stefan Seefeld stefan at synopsis.fresco.org
Fri Dec 5 22:30:32 UTC 2003


Update of /cvs/synopsis/Synopsis/Synopsis/Formatters/HTML
In directory frida:/tmp/cvs-serv31713/Synopsis/Formatters/HTML

Modified Files:
	Part.py 
Added Files:
	Fragment.py 
Log Message:
rename and refactor FormatStrategy -> Fragment

--- NEW FILE: Fragment.py ---
# $Id: Fragment.py,v 1.1 2003/12/05 22:30:29 stefan Exp $
#
# 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.
#

from Synopsis import AST, Type
from Tags import *
import string

class Fragment:
   """Generates HTML fragment for a declaration. Multiple strategies are
   combined to generate the output for a single declaration, allowing the
   user to customise the output by choosing a set of strategies. This follows
   the Strategy design pattern.
   
   The key concept of this class is the format* methods. Any
   class derived from Strategy that overrides one of the format methods
   will have that method called by the Summary and Detail formatters when
   they visit that AST type. Summary and Detail maintain a list of
   Strategies, and a list for each AST type.
    
   For example, when Strategy.Summary visits a Function object, it calls
   the formatFunction method on all Strategys registed with
   SummaryFormatter that implemented that method. Each of these format
   methods returns a string, which may contain a TD tag to create a new
   column.

   An important point to note is that only Strategies which override a
   particular format method are called - if that format method is not
   overridden then it is not called for that declaration type.
   """

   def register(self, formatter):
      """Store formatter as self.formatter. The formatter is either a
      SummaryFormatter or DetailFormatter, and is used for things like
      reference() and label() calls. Local references to the formatter's
      reference and label methods are stored in self for more efficient use
      of them."""

      self.processor = formatter.processor
      self.formatter = formatter
      self.label = formatter.label
      self.reference = formatter.reference
      self.format_type = formatter.format_type
      self.page = formatter.page()

   #
   # Utility methods
   #
   def format_modifiers(self, modifiers):
      """Returns a HTML string from the given list of string modifiers. The
      modifiers are enclosed in 'keyword' spans."""

      def keyword(m):
         if m == '&': return span('keyword', '&')
         return span('keyword', m)
      return string.join(map(keyword, modifiers))


   #
   # AST Formatters
   #
   def format_declaration(self, decl): pass
   def format_forward(self, decl): pass
   def format_group(self, decl): pass
   def format_scope(self, decl): pass
   def format_module(self, decl): pass
   def format_meta_module(self, decl): pass
   def format_class(self, decl): pass
   def format_typedef(self, decl): pass
   def format_enum(self, decl): pass
   def format_variable(self, decl): pass
   def format_const(self, decl): pass
   def format_function(self, decl): pass
   def format_operation(self, decl): pass

Index: Part.py
===================================================================
RCS file: /cvs/synopsis/Synopsis/Synopsis/Formatters/HTML/Part.py,v
retrieving revision 1.38
retrieving revision 1.39
diff -u -p -d -r1.38 -r1.39
--- Part.py	16 Nov 2003 21:09:45 -0000	1.38
+++ Part.py	5 Dec 2003 22:30:29 -0000	1.39
@@ -17,7 +17,7 @@ and are defined in the FormatStrategy mo
 
 from Synopsis.Processor import Parametrized, Parameter
 from Synopsis import AST, Type, Util
-import FormatStrategy
+from Fragment import Fragment
 import Tags # need both because otherwise 'Tags.name' would be ambiguous
 from Tags import *
 
@@ -37,13 +37,13 @@ class Part(Parametrized, Type.Visitor, A
    methods, which myst be implemented in a subclass.
    """
 
-   formatters = Parameter([], "list of FormatStrategies (yes, that's an aweful name)")
+   fragments = Parameter([], "list of Fragments")
 
    def register(self, page):
 
       self.processor = page.processor
       self.__page = page
-      self.__formatters = []
+      self.__fragments = []
       self.__id_holder = None
       # Lists of format methods for each AST type
       self.__formatdict = {'format_declaration':[],
@@ -62,12 +62,12 @@ class Part(Parametrized, Type.Visitor, A
 
       # Why not just apply all formatters ? is this an optimization ?
       # ask chalky...
-      for formatter in self.formatters:
-         formatter.register(self)
+      for fragment in self.fragments:
+         fragment.register(self)
          for method in self.__formatdict.keys():
-            no_func = getattr(FormatStrategy.Strategy, method).im_func
-            method_obj = getattr(formatter, method)
-            # If it was overridden in formatter
+            no_func = getattr(Fragment, method).im_func
+            method_obj = getattr(fragment, method)
+            # If it was overridden in fragment
             if method_obj.im_func is not no_func:
                # Add to the dictionary
                self.__formatdict[method].append(method_obj)
@@ -116,7 +116,7 @@ class Part(Parametrized, Type.Visitor, A
 
 
    def format_declaration(self, decl, method):
-      """Format decl using named method of each formatter. Each formatter
+      """Format decl using named method of each fragment. Each fragment
       returns two strings - type and name. All the types are joined and all
       the names are joined separately. The consolidated type and name
       strings are then passed to write_section_item."""





More information about the Synopsis-changes mailing list