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                       Body(),
 29                       Inheritance()],
 30                      '')
 31
 32    def register(self, frame):
 33
 34        super(Scope, self).register(frame)
 35        for part in self.parts: part.register(self)
 36
 37        self.scope_queue = []
 38        self.__toc = TOC(self.directory_layout)
 39        for d in self.processor.ir.asg.declarations:
 40            d.accept(self.__toc)
 41
 42    def toc(self):
 43
 44        return self.__toc
 45
 46    def filename(self):
 47
 48        return self.__filename
 49
 50    def title(self):
 51
 52        return self.__title
 53
 54    def root(self):
 55
 56        if self.main:
 57            url = self.directory_layout.index()
 58        else:
 59            url = self.directory_layout.scope(self.processor.root.name)
 60        title = 'Global %s'%(self.processor.root.type.capitalize())
 61        return url, title
 62
 63    def scope(self):
 64        """return the current scope processed by this object"""
 65
 66        return self.__scope
 67
 68    def process(self):
 69        """Creates a view for every Scope."""
 70
 71        module = self.processor.root
 72        self.scopes_queue = [module]
 73        while self.scopes_queue:
 74            scope = self.scopes_queue.pop(0)
 75            self.process_scope(scope)
 76            scopes = [c for c in scope.declarations if isinstance(c, ASG.Scope)]
 77            self.scopes_queue.extend(scopes)
 78            forwards = [c for c in scope.declarations
 79                        if isinstance(c, ASG.Forward) and c.specializations]
 80            # Treat forward-declared class template like a scope if it has
 81            # specializations, since these are only listed in a Scope view.
 82            # Process them directly as they don't have child declarations.
 83            for f in forwards:
 84                self.process_scope(f)
 85
 86    def register_filenames(self):
 87        """Registers a view for every Scope."""
 88
 89        self.scopes_queue = [self.processor.root]
 90        while self.scopes_queue:
 91            scope = self.scopes_queue.pop(0)
 92            if scope.name:
 93                filename = self.directory_layout.scope(scope.name)
 94            else:
 95                filename = self.root()[0]
 96            self.processor.register_filename(filename, self, scope)
 97
 98            scopes = [c for c in scope.declarations if isinstance(c, ASG.Module)]
 99            self.scopes_queue.extend(scopes)
100
101    def process_scope(self, scope):
102        """Creates a view for the given scope"""
103
104        # Open file and setup scopes
105        self.__scope = scope.name
106        if self.__scope:
107            self.__filename = self.directory_layout.scope(self.__scope)
108            self.__title = escape(str(self.__scope))
109        else:
110            self.__filename, self.__title = self.root()
111        self.start_file()
112        self.write_navigation_bar()
113        # Loop throught all the view Parts
114        for part in self.parts:
115            part.process(scope)
116        self.end_file()
117
118    def end_file(self):
119        """Overrides end_file to provide synopsis logo"""
120
121        self.write('\n')
122        now = time.strftime(r'%c', time.localtime(time.time()))
123        logo = img(src=rel(self.filename(), 'synopsis.png'), alt='logo')
124        logo = href('http://synopsis.fresco.org', logo + ' synopsis', target='_blank')
125        logo += ' (version %s)'%config.version
126        self.write(div('Generated on ' + now + ' by \n<br/>\n' + logo, class_='logo'))
127        View.end_file(self)
128