[Synopsis-changes] Synopsis/Synopsis/Synopsis/Formatters/HTML/Parts Detail.py,NONE,1.1 Heading.py,NONE,1.1 Inheritance.py,NONE,1.1 Summary.py,NONE,1.1 __init__.py,NONE,1.1

Stefan Seefeld stefan at synopsis.fresco.org
Sat Nov 15 19:54:07 UTC 2003


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

Added Files:
	Detail.py Heading.py Inheritance.py Summary.py __init__.py 
Log Message:
refactor parts

--- NEW FILE: Detail.py ---
# $Id: Detail.py,v 1.1 2003/11/15 19:54:05 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.Formatters.HTML.Part import Part

from Synopsis.Formatters.HTML import FormatStrategy
from Synopsis.Formatters.HTML.Tags import *
from Synopsis.Formatters.HTML.DeclarationStyle import *

class Detail(Part):

   def register(self, page):

      Part.register(self, page)
      self._init_formatters('detail_formatters', 'detail')

   def _init_default_formatters(self):

      self.addFormatter( FormatStrategy.DetailAST )
      #self.addFormatter( ClassHierarchySimple )
      self.addFormatter( FormatStrategy.DetailCommenter )

   def writeSectionStart(self, heading):
      """Creates a table with one row. The row has a td of class 'heading'
      containing the heading string"""

      self.write('<table width="100%%" summary="%s">\n'%heading)
      self.write('<tr><td colspan="2" class="heading">' + heading + '</td></tr>\n')
      self.write('</table>')

   def writeSectionItem(self, text):
      """Writes text and follows with a horizontal rule"""

      self.write(text + '\n<hr>\n')

   def process(self, decl):
      "Print out the details for the children of the given decl"

      decl_style = self.processor.decl_style
      SUMMARY = Style.SUMMARY

      sorter = self.processor.sorter
      sorter.set_scope(decl)
      sorter.sort_section_names()

      # Iterate through the sections with details
      self.write_start()
      for section in sorter.sections():
         # Write a heading
         heading = section+' Details:'
         started = 0 # Lazy section start incase no details for this section
         # Iterate through the children in this section
         for child in sorter.children(section):
            # Check if need to add to detail list
            if decl_style[child] == SUMMARY:
               continue
            # Check section heading
            if not started:
               started = 1
               self.writeSectionStart(heading)
            child.accept(self)
         # Finish the section
         if started: self.writeSectionEnd(heading)
      self.write_end()

--- NEW FILE: Heading.py ---
# $Id: Heading.py,v 1.1 2003/11/15 19:54:05 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.Formatters.HTML.Part import Part

from Synopsis.Formatters.HTML import FormatStrategy
from from Synopsis.Formatters.HTML.Tags import *

class Heading(Part):
   """Heading page part. Displays a header for the page -- its strategies are
   only passed the object that the page is for; ie a Class or Module"""

   def register(self, page):

      Part.register(self, page)
      self._init_formatters('heading_formatters', 'heading')

   def _init_default_formatters(self):

      self.addFormatter(FormatStrategy.Heading)
      self.addFormatter(FormatStrategy.ClassHierarchyGraph)
      self.addFormatter(FormatStrategy.DetailCommenter)

   def writeSectionItem(self, text):
      """Writes text and follows with a horizontal rule"""

      self.write(text + '\n<hr>\n')

   def process(self, decl):
      """Process this Part by formatting only the given decl"""

      decl.accept(self)


--- NEW FILE: Inheritance.py ---
# $Id: Inheritance.py,v 1.1 2003/11/15 19:54:05 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.Formatters.HTML.Part import Part

from Synopsis.Formatters.HTML import FormatStrategy
from from Synopsis.Formatters.HTML.Tags import *

class Inheritance(Part):

   def register(self, page):

      Part.register(self, page)
      self._init_formatters('inheritance_formatters', 'inheritance')
      self.__start_list = 0

   def _init_default_formatters(self):

      self.addFormatter(FormatStrategy.Inheritance)

   def process(self, decl):
      "Walk the hierarchy to find inherited members to print."

      if not isinstance(decl, AST.Class): return
      self.write_start()
      names = decl.declarations()
      names = map(self._short_name, names)
      self._process_superclasses(decl, names)
      self.write_end()

   def _process_class(self, clas, names):
      "Prints info for the given class, and calls _process_superclasses after"

      sorter = self.processor.sorter
      sorter.set_scope(clas)
      sorter.sort_section_names()
      child_names = []

      # Iterate through the sections
      for section in sorter.sections():
         # Write a heading
         heading = section+'s Inherited from '+ Util.ccolonName(clas.name(), self.scope())
         started = 0 # Lazy section start incase no details for this section
         # Iterate through the children in this section
         for child in sorter.children(section):
            child_name = self._short_name(child)
            if child_name in names:
               continue
            # FIXME: This doesn't account for the inheritance type
            # (private etc)
            if child.accessibility() == AST.PRIVATE:
               continue
            # Don't include constructors and destructors!
            if isinstance(child, AST.Function) and child.language() == 'C++' and len(child.realname())>1:
               if child.realname()[-1] == child.realname()[-2]: continue
               elif child.realname()[-1] == "~"+child.realname()[-2]: continue
            # FIXME: skip overriden declarations
            child_names.append(child_name)
            # Check section heading
            if not started:
               started = 1
               self.writeSectionStart(heading)
            child.accept(self)
         # Finish the section
         if started: self.writeSectionEnd(heading)
	
      self._process_superclasses(clas, names + child_names)
    
   def _short_name(self, decl):
      if isinstance(decl, AST.Function):
         return decl.realname()[-1]
      return decl.name()[-1]
    
   def _process_superclasses(self, clas, names):
      """Iterates through the superclasses of clas and calls _process_clas for
      each"""

      for inheritance in clas.parents():
         parent = inheritance.parent()
         if isinstance(parent, Type.Declared):
            parent = parent.declaration()
            if isinstance(parent, AST.Class):
               self._process_class(parent, names)
               continue
         #print "Ignoring", parent.__class__.__name__, "parent of", clas.name()
         pass #ignore
     
   def writeSectionStart(self, heading):
      """Creates a table with one row. The row has a td of class 'heading'
      containing the heading string"""

      self.write('<table width="100%%" summary="%s">\n'%heading)
      self.write('<tr><td colspan="2" class="heading">' + heading + '</td></tr>\n')
      self.write('<tr><td class="inherited">')
      self.__start_list = 1

   def writeSectionItem(self, text):
      """Adds a table row"""

      if self.__start_list:
         self.write(text)
         self.__start_list = 0
      else:
         self.write(',\n'+text)

   def writeSectionEnd(self, heading):
      """Closes the table entity and adds a break."""
      self.write('</td></tr></table>\n<br>\n')



--- NEW FILE: Summary.py ---
# $Id: Summary.py,v 1.1 2003/11/15 19:54:05 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.Formatters.HTML.Part import Part

from Synopsis.Formatters.HTML import FormatStrategy
from from Synopsis.Formatters.HTML.Tags import *

class Summary(Part):
   """Formatting summary visitor. This formatter displays a summary for each
   declaration, with links to the details if there is one. All of this is
   controlled by the ASTFormatters."""

   def register(self, page):

      Part.register(self, page)
      self.__link_detail = 0
      self._init_formatters('summary_formatters', 'summary')

   def _init_default_formatters(self):

      self.addFormatter( FormatStrategy.SummaryAST )
      self.addFormatter( FormatStrategy.SummaryCommenter )

   def set_link_detail(self, boolean):
      """Sets link_detail flag to given value.
      @see label()"""

      self.__link_detail = boolean
      config.link_detail = boolean

   def label(self, ref, label=None):
      """Override to check link_detail flag. If it's set, returns a reference
      instead - which will be to the detailed info"""

      if label is None: label = ref
      if self.__link_detail:
         # Insert a reference instead
         return span('name',self.reference(ref, Util.ccolonName(label, self.scope())))
      return Part.label(self, ref, label)
	
   def writeSectionStart(self, heading):
      """Starts a table entity. The heading is placed in a row in a td with
      the class 'heading'."""

      self.write('<table width="100%%" summary="%s">\n'%heading)
      self.write('<col><col width="100%%">')
      self.write('<tr><td class="heading" colspan="2">' + heading + '</td></tr>\n')

   def writeSectionEnd(self, heading):
      """Closes the table entity and adds a break."""

      self.write('</table>\n<br>\n')

   def writeSectionItem(self, text):
      """Adds a table row"""

      if text[:22] == '<td class="summ-start"':
         # text provided its own TD element
         self.write('<tr>' + text + '</td></tr>\n')
      else:
         self.write('<tr><td class="summ-start">' + text + '</td></tr>\n')

   def process(self, decl):
      "Print out the summaries from the given decl"

      decl_style = config.decl_style
      SUMMARY = DeclStyle.SUMMARY
      config.link_detail = 0
	
      config.sorter.set_scope(decl)
      config.sorter.sort_section_names()

      self.write_start()
      for section in config.sorter.sections():
         # Write a header for this section
         if section[-1] == 's': heading = section+'es Summary:'
         else: heading = section+'s Summary:'
         self.writeSectionStart(heading)
         # Iterate through the children in this section
         for child in config.sorter.children(section):
            # Check if need to add to detail list
            if decl_style[child] != SUMMARY:
               # Setup the linking stuff
               self.set_link_detail(1)
               child.accept(self)
               self.set_link_detail(0)
            else:
               # Just do it
               child.accept(self)
         # Finish off this section
         self.writeSectionEnd(heading)
      self.write_end()


--- NEW FILE: __init__.py ---
# this file is intentionally left empty
# -stefan





More information about the Synopsis-changes mailing list