Synopsis - Synopsis/Formatters/HTML/Views/Scope.py

File: Synopsis/Formatters/HTML/Views/Scope.py

      1#
      2# Copyright (C) 2000 Stephen Davies
      3# Copyright (C) 2000 Stefan Seefeld
      4# All rights reserved.
      5# Licensed to the public under the terms of the GNU LGPL (>= 2),
      6# see the file COPYING for details.
      7#
      8
      9from Synopsis import config
     10from Synopsis.Processor import Parameter
     11from Synopsis import ASG
     12from Synopsis.Formatters.TOC import TOC
     13from Synopsis.Formatters.HTML.View import View
     14from Synopsis.Formatters.HTML.Tags import *
     15from Synopsis.Formatters.HTML.Parts import *
     16import time
     17
     18class Scope(View):
     19    """A module for creating a view for each Scope with summaries and
     20    details. This module is highly modular, using the classes from
     21    ASGFormatter to do the actual formatting. The classes to use may be
     22    controlled via the config script, resulting in a very configurable output.
     23    @see ASGFormatter The ASGFormatter module
     24    @see Config.Formatters.HTML.ScopeViews Config for ScopeViews
     25    """
     26
     27    parts = Parameter([Heading(),
     28                       Summary(),
     29                       Inheritance(),
     30                       Detail()],
     31                      '')
     32
     33    def register(self, frame):
     34
     35        super(Scope, self).register(frame)
     36        for part in self.parts: part.register(self)
     37
     38        self.scope_queue = []
     39        self.__toc = TOC(self.directory_layout)
     40        for d in self.processor.ir.asg.declarations:
     41            d.accept(self.__toc)
     42
     43    def toc(self):
     44
     45        return self.__toc
     46
     47    def filename(self):
     48
     49        return self.__filename
     50
     51    def title(self):
     52
     53        return self.__title
     54
     55    def root(self):
     56
     57        if self.main:
     58            url = self.directory_layout.index()
     59        else:
     60            url = self.directory_layout.scope(self.processor.root.name)
     61        title = 'Global %s'%(self.processor.root.type.capitalize())
     62        return url, title
     63
     64    def scope(self):
     65        """return the current scope processed by this object"""
     66
     67        return self.__scope
     68
     69    def process(self):
     70        """Creates a view for every Scope."""
     71
     72        module = self.processor.root
     73        self.scopes_queue = [module]
     74        while self.scopes_queue:
     75            scope = self.scopes_queue.pop(0)
     76            self.process_scope(scope)
     77            scopes = [c for c in scope.declarations if isinstance(c, ASG.Scope)]
     78            self.scopes_queue.extend(scopes)
     79            forwards = [c for c in scope.declarations
     80                        if isinstance(c, ASG.Forward) and c.specializations]
     81            # Treat forward-declared class template like a scope if it has
     82            # specializations, since these are only listed in a Scope view.
     83            # Process them directly as they don't have child declarations.
     84            for f in forwards:
     85                self.process_scope(f)
     86
     87    def register_filenames(self):
     88        """Registers a view for every Scope."""
     89
     90        self.scopes_queue = [self.processor.root]
     91        while self.scopes_queue:
     92            scope = self.scopes_queue.pop(0)
     93            if scope.name:
     94                filename = self.directory_layout.scope(scope.name)
     95            else:
     96                filename = self.root()[0]
     97            self.processor.register_filename(filename, self, scope)
     98
     99            scopes = [c for c in scope.declarations if isinstance(c, ASG.Module)]
    100            self.scopes_queue.extend(scopes)
    101
    102    def process_scope(self, scope):
    103        """Creates a view for the given scope"""
    104
    105        # Open file and setup scopes
    106        self.__scope = scope.name
    107        if self.__scope:
    108            self.__filename = self.directory_layout.scope(self.__scope)
    109            self.__title = escape(str(self.__scope))
    110        else:
    111            self.__filename, self.__title = self.root()
    112        self.start_file()
    113        self.write_navigation_bar()
    114        # Loop throught all the view Parts
    115        for part in self.parts:
    116            part.process(scope)
    117        self.end_file()
    118
    119    def end_file(self):
    120        """Overrides end_file to provide synopsis logo"""
    121
    122        self.write('\n')
    123        now = time.strftime(r'%c', time.localtime(time.time()))
    124        logo = img(src=rel(self.filename(), 'synopsis.png'), alt='logo')
    125        logo = href('http://synopsis.fresco.org', logo + ' synopsis', target='_blank')
    126        logo += ' (version %s)'%config.version
    127        self.write(div('logo', 'Generated on ' + now + ' by \n<br/>\n' + logo))
    128        View.end_file(self)
    129

Generated on Thu Apr 16 16:27:15 2009 by
synopsis (version devel)