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

File: Synopsis/Formatters/HTML/Views/ModuleTree.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 ASG
    10from Synopsis.Formatters.HTML.Tags import *
    11from Tree import Tree
    12
    13class ModuleTree(Tree):
    14    """Create a javascript-enabled module tree."""
    15
    16    def register(self, frame):
    17
    18        super(ModuleTree, self).register(frame)
    19        self._children_cache = {}
    20
    21    def filename(self):
    22
    23        if self.main:
    24            return self.directory_layout.index()
    25        else:
    26            return self.directory_layout.special('ModuleTree')
    27
    28    def title(self):
    29
    30        return 'Module Tree'
    31
    32    def root(self):
    33
    34        return self.filename(), self.title()
    35
    36    def process(self):
    37
    38        self.start_file()
    39        self.write_navigation_bar()
    40        module = self.processor.root
    41        self.index_module(module, module.name)
    42        self.end_tree()
    43        self.end_file()
    44
    45    def _link_href(self, module):
    46
    47        return self.directory_layout.module_index(module.name)
    48
    49    def get_children(self, decl):
    50
    51        try: return self._children_cache[decl]
    52        except KeyError: pass
    53        children = [c for c in decl.declarations if isinstance(c, ASG.Module)]
    54        self._children_cache[decl] = children
    55        return children
    56
    57    def index_module(self, module, qname):
    58        """Write a link for this module and recursively visit child modules."""
    59
    60        # Find children, and sort so that compound children (packages) go first
    61        children = self.get_children(module)
    62        children.sort(lambda a,b,g=self.get_children:
    63                      cmp(len(g(b)),len(g(a))))
    64        # Print link to this module
    65        if module.name:
    66            label = str(qname.prune(module.name))
    67        else:
    68            label = 'Global %s'%module.type.capitalize()
    69        link = self._link_href(module)
    70        text = href(link, label, target='detail')
    71        if not len(children):
    72            self.write_leaf(text)
    73        else:
    74            self.write_node_start(text)
    75            # Add children
    76            for child in children:
    77                self.index_module(child, module.name)
    78            self.write_node_end()
    79
    80

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